@@ -77,22 +77,18 @@ _beforeEach.withArgs = function() {
77
77
}
78
78
79
79
_beforeEach . givenModel = function ( modelName , attrs , optionalHandler ) {
80
- var modelKey = modelName ;
80
+ var modelInstance ;
81
81
82
82
if ( typeof attrs === 'function' ) {
83
83
optionalHandler = attrs ;
84
84
attrs = undefined ;
85
85
}
86
86
87
- if ( typeof optionalHandler === 'string' ) {
88
- modelKey = optionalHandler ;
89
- }
90
-
91
87
attrs = attrs || { } ;
92
88
93
89
beforeEach ( function ( done ) {
94
90
if ( modelName === '__USERMODEL__' ) {
95
- modelName = this . userModel ? this . userModel : 'user ' ;
91
+ modelName = this . userModel ? this . userModel : 'User ' ;
96
92
}
97
93
98
94
var test = this ;
@@ -112,7 +108,15 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
112
108
if ( err . details ) console . error ( err . details ) ;
113
109
done ( err ) ;
114
110
} else {
111
+ var modelKey = modelName ;
112
+ if ( typeof optionalHandler === 'string' ) {
113
+ modelKey = optionalHandler ;
114
+ }
115
+
116
+ test [ '__USERMODEL__' ] = result ;
115
117
test [ modelKey ] = result ;
118
+ modelInstance = result ;
119
+
116
120
done ( ) ;
117
121
}
118
122
} ) ;
@@ -123,7 +127,7 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
123
127
}
124
128
125
129
afterEach ( function ( done ) {
126
- this [ modelKey ] . destroy ( done ) ;
130
+ modelInstance . destroy ( done ) ;
127
131
} ) ;
128
132
}
129
133
@@ -139,21 +143,25 @@ _beforeEach.givenUser = function(attrs, optionalHandler) {
139
143
}
140
144
141
145
_beforeEach . givenUserWithRole = function ( attrs , role , optionalHandler ) {
146
+ var roleInstance , roleMappingInstance ;
147
+
142
148
if ( typeof role === 'string' ) {
143
149
role = {
144
150
name : role
145
151
}
146
152
}
147
153
_beforeEach . givenUser ( attrs , function ( done ) {
148
154
var test = this ;
149
- test . app . models . Role . findOrCreate ( { name : role . name } , function ( err , result ) {
155
+ test . app . models . Role . findOrCreate ( role , function ( err , result ) {
150
156
if ( err ) {
151
157
console . error ( err . message ) ;
152
158
if ( err . details ) console . error ( err . details ) ;
153
159
return done ( err ) ;
154
160
}
155
161
156
162
test . userRole = result ;
163
+ roleInstance = result ;
164
+
157
165
test . app . models . RoleMapping . create (
158
166
{ principalId : test . __USERMODEL__ . id ,
159
167
principalType : test . app . models . RoleMapping . USER ,
@@ -166,6 +174,8 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) {
166
174
}
167
175
168
176
test . userRoleMapping = result ;
177
+ roleMappingInstance = result ;
178
+
169
179
done ( ) ;
170
180
}
171
181
) ;
@@ -177,14 +187,13 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) {
177
187
}
178
188
179
189
afterEach ( function ( done ) {
180
- var test = this ;
181
- this . userRole . destroy ( function ( err ) {
190
+ roleInstance . destroy ( function ( err ) {
182
191
if ( err ) return done ( err ) ;
183
- test . userRole = undefined ;
192
+ roleInstance = undefined ;
184
193
185
- test . userRoleMapping . destroy ( function ( err ) {
194
+ roleMappingInstance . destroy ( function ( err ) {
186
195
if ( err ) return done ( err ) ;
187
- test . userRoleMapping = undefined ;
196
+ roleMappingInstance = undefined ;
188
197
done ( ) ;
189
198
} ) ;
190
199
} ) ;
0 commit comments