@@ -160,14 +160,31 @@ describe('DS.defineResource(definition)', function () {
160160 }
161161 } ) ;
162162
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+
163173 DS . inject ( 'person' , {
164174 first : 'John' ,
165175 last : 'Anderson' ,
166176 email : 'john.anderson@test.com' ,
167177 id : 1
168178 } ) ;
169179
180+ DS . inject ( 'dog' , {
181+ first : 'doggy' ,
182+ last : 'dog' ,
183+ id : 1
184+ } ) ;
185+
170186 var person = DS . get ( 'person' , 1 ) ;
187+ var dog = DS . get ( 'dog' , 1 ) ;
171188
172189 assert . deepEqual ( JSON . stringify ( person ) , JSON . stringify ( {
173190 first : 'John' ,
@@ -177,14 +194,16 @@ describe('DS.defineResource(definition)', function () {
177194 fullName : 'John Anderson'
178195 } ) ) ;
179196 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' ) ;
182200
183201 person . first = 'Johnny' ;
184202
185203 // digest loop hasn't happened yet
186204 assert . equal ( DS . get ( 'person' , 1 ) . first , 'Johnny' ) ;
187205 assert . equal ( DS . get ( 'person' , 1 ) . fullName , 'John Anderson' ) ;
206+ assert . equal ( DS . get ( 'dog' , 1 ) . fullName , 'doggy dog' ) ;
188207
189208 DS . digest ( ) ;
190209
@@ -199,6 +218,7 @@ describe('DS.defineResource(definition)', function () {
199218 assert . equal ( person . fullName , 'Johnny Anderson' ) ;
200219
201220 person . first = 'Jack' ;
221+ dog . first = 'spot' ;
202222
203223 DS . digest ( ) ;
204224
@@ -211,6 +231,7 @@ describe('DS.defineResource(definition)', function () {
211231 fullName : 'Jack Anderson'
212232 } ) ;
213233 assert . equal ( person . fullName , 'Jack Anderson' ) ;
234+ assert . equal ( dog . fullName , 'spot dog' ) ;
214235
215236 // computed property function should not be called
216237 // when a property changes that isn't a dependency
@@ -219,7 +240,7 @@ describe('DS.defineResource(definition)', function () {
219240
220241 DS . digest ( ) ;
221242
222- assert . equal ( callCount , 3 , 'fullName() should have been called 3 times' ) ;
243+ assert . equal ( callCount , 5 , 'fullName() should have been called 3 times' ) ;
223244
224245 done ( ) ;
225246 } , 50 ) ;
0 commit comments