@@ -160,14 +160,31 @@ describe('DS.defineResource(definition)', function () {
160
160
}
161
161
} ) ;
162
162
163
+ DS . defineResource ( {
164
+ name : 'dog' ,
165
+ computed : {
166
+ fullName : [ 'first' , 'last' , function ( f , l ) {
167
+ callCount ++ ;
168
+ return f + ' ' + l ;
169
+ } ]
170
+ }
171
+ } ) ;
172
+
163
173
DS . inject ( 'person' , {
164
174
first : 'John' ,
165
175
last : 'Anderson' ,
166
176
167
177
id : 1
168
178
} ) ;
169
179
180
+ DS . inject ( 'dog' , {
181
+ first : 'doggy' ,
182
+ last : 'dog' ,
183
+ id : 1
184
+ } ) ;
185
+
170
186
var person = DS . get ( 'person' , 1 ) ;
187
+ var dog = DS . get ( 'dog' , 1 ) ;
171
188
172
189
assert . deepEqual ( JSON . stringify ( person ) , JSON . stringify ( {
173
190
first : 'John' ,
@@ -177,14 +194,16 @@ describe('DS.defineResource(definition)', function () {
177
194
fullName : 'John Anderson'
178
195
} ) ) ;
179
196
assert . equal ( person . fullName , 'John Anderson' ) ;
180
- assert . equal ( lifecycle . beforeInject . callCount , 1 , 'beforeInject should have been called' ) ;
181
- assert . equal ( lifecycle . afterInject . callCount , 1 , 'afterInject should have been called' ) ;
197
+ assert . equal ( dog . fullName , 'doggy dog' ) ;
198
+ assert . equal ( lifecycle . beforeInject . callCount , 2 , 'beforeInject should have been called twice' ) ;
199
+ assert . equal ( lifecycle . afterInject . callCount , 2 , 'afterInject should have been called twice' ) ;
182
200
183
201
person . first = 'Johnny' ;
184
202
185
203
// digest loop hasn't happened yet
186
204
assert . equal ( DS . get ( 'person' , 1 ) . first , 'Johnny' ) ;
187
205
assert . equal ( DS . get ( 'person' , 1 ) . fullName , 'John Anderson' ) ;
206
+ assert . equal ( DS . get ( 'dog' , 1 ) . fullName , 'doggy dog' ) ;
188
207
189
208
DS . digest ( ) ;
190
209
@@ -199,6 +218,7 @@ describe('DS.defineResource(definition)', function () {
199
218
assert . equal ( person . fullName , 'Johnny Anderson' ) ;
200
219
201
220
person . first = 'Jack' ;
221
+ dog . first = 'spot' ;
202
222
203
223
DS . digest ( ) ;
204
224
@@ -211,6 +231,7 @@ describe('DS.defineResource(definition)', function () {
211
231
fullName : 'Jack Anderson'
212
232
} ) ;
213
233
assert . equal ( person . fullName , 'Jack Anderson' ) ;
234
+ assert . equal ( dog . fullName , 'spot dog' ) ;
214
235
215
236
// computed property function should not be called
216
237
// when a property changes that isn't a dependency
@@ -219,7 +240,7 @@ describe('DS.defineResource(definition)', function () {
219
240
220
241
DS . digest ( ) ;
221
242
222
- assert . equal ( callCount , 3 , 'fullName() should have been called 3 times' ) ;
243
+ assert . equal ( callCount , 5 , 'fullName() should have been called 3 times' ) ;
223
244
224
245
done ( ) ;
225
246
} , 50 ) ;
0 commit comments