@@ -78,6 +78,7 @@ _beforeEach.withArgs = function() {
78
78
79
79
_beforeEach . givenModel = function ( modelName , attrs , optionalHandler ) {
80
80
var modelKey = modelName ;
81
+ var modelInstance ;
81
82
82
83
if ( typeof attrs === 'function' ) {
83
84
optionalHandler = attrs ;
@@ -113,6 +114,7 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
113
114
done ( err ) ;
114
115
} else {
115
116
test [ modelKey ] = result ;
117
+ modelInstance = result ;
116
118
done ( ) ;
117
119
}
118
120
} ) ;
@@ -123,7 +125,7 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
123
125
}
124
126
125
127
afterEach ( function ( done ) {
126
- this [ modelKey ] . destroy ( done ) ;
128
+ modelInstance . destroy ( done ) ;
127
129
} ) ;
128
130
}
129
131
@@ -139,6 +141,8 @@ _beforeEach.givenUser = function(attrs, optionalHandler) {
139
141
}
140
142
141
143
_beforeEach . givenUserWithRole = function ( attrs , role , optionalHandler ) {
144
+ var roleInstance , roleMappingInstance ;
145
+
142
146
if ( typeof role === 'string' ) {
143
147
role = {
144
148
name : role
@@ -154,6 +158,8 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) {
154
158
}
155
159
156
160
test . userRole = result ;
161
+ roleInstance = result ;
162
+
157
163
test . app . models . RoleMapping . create (
158
164
{ principalId : test . __USERMODEL__ . id ,
159
165
principalType : test . app . models . RoleMapping . USER ,
@@ -166,6 +172,8 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) {
166
172
}
167
173
168
174
test . userRoleMapping = result ;
175
+ roleMappingInstance = result ;
176
+
169
177
done ( ) ;
170
178
}
171
179
) ;
@@ -177,14 +185,13 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) {
177
185
}
178
186
179
187
afterEach ( function ( done ) {
180
- var test = this ;
181
- this . userRole . destroy ( function ( err ) {
188
+ roleInstance . destroy ( function ( err ) {
182
189
if ( err ) return done ( err ) ;
183
- test . userRole = undefined ;
190
+ roleInstance = undefined ;
184
191
185
- test . userRoleMapping . destroy ( function ( err ) {
192
+ roleMappingInstance . destroy ( function ( err ) {
186
193
if ( err ) return done ( err ) ;
187
- test . userRoleMapping = undefined ;
194
+ roleMappingInstance = undefined ;
188
195
done ( ) ;
189
196
} ) ;
190
197
} ) ;
0 commit comments