@@ -3,8 +3,9 @@ var helper = require('../support/spec_helper');
33var ORM = require ( '../../' ) ;
44
55describe ( "Model.get()" , function ( ) {
6- var db = null ;
6+ var db = null ;
77 var Person = null ;
8+ var John ;
89
910 var setup = function ( cache ) {
1011 return function ( done ) {
@@ -14,7 +15,7 @@ describe("Model.get()", function() {
1415 cache : cache ,
1516 methods : {
1617 UID : function ( ) {
17- return this . id ;
18+ return this [ Person . id ] ;
1819 }
1920 }
2021 } ) ;
@@ -26,7 +27,11 @@ describe("Model.get()", function() {
2627 name : "John Doe"
2728 } , {
2829 name : "Jane Doe"
29- } ] , done ) ;
30+ } ] , function ( err , people ) {
31+ John = people [ 0 ] ;
32+
33+ return done ( ) ;
34+ } ) ;
3035 } ) ;
3136 } ;
3237 } ;
@@ -47,39 +52,39 @@ describe("Model.get()", function() {
4752 before ( setup ( true ) ) ;
4853
4954 it ( "should return item with id 1" , function ( done ) {
50- Person . get ( 1 , function ( err , John ) {
55+ Person . get ( John [ Person . id ] , function ( err , John ) {
5156 should . equal ( err , null ) ;
5257
5358 John . should . be . a ( "object" ) ;
54- John . should . have . property ( "id" , 1 ) ;
59+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
5560 John . should . have . property ( "name" , "John Doe" ) ;
5661
5762 return done ( ) ;
5863 } ) ;
5964 } ) ;
6065
6166 it ( "should have an UID method" , function ( done ) {
62- Person . get ( 1 , function ( err , John ) {
67+ Person . get ( John [ Person . id ] , function ( err , John ) {
6368 should . equal ( err , null ) ;
6469
6570 John . UID . should . be . a ( "function" ) ;
66- John . UID ( ) . should . equal ( John . id ) ;
71+ John . UID ( ) . should . equal ( John [ Person . id ] ) ;
6772
6873 return done ( ) ;
6974 } ) ;
7075 } ) ;
7176
7277 describe ( "changing name and getting id 1 again" , function ( ) {
7378 it ( "should return the original object with unchanged name" , function ( done ) {
74- Person . get ( 1 , function ( err , John1 ) {
79+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
7580 should . equal ( err , null ) ;
7681
7782 John1 . name = "James" ;
7883
79- Person . get ( 1 , function ( err , John2 ) {
84+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
8085 should . equal ( err , null ) ;
8186
82- John1 . id . should . equal ( John2 . id ) ;
87+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
8388 John2 . name . should . equal ( "John Doe" ) ;
8489
8590 return done ( ) ;
@@ -93,15 +98,15 @@ describe("Model.get()", function() {
9398 Person . settings . set ( "instance.cacheSaveCheck" , false ) ;
9499
95100 it ( "should return the same object with the changed name" , function ( done ) {
96- Person . get ( 1 , function ( err , John1 ) {
101+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
97102 should . equal ( err , null ) ;
98103
99104 John1 . name = "James" ;
100105
101- Person . get ( 1 , function ( err , John2 ) {
106+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
102107 should . equal ( err , null ) ;
103108
104- John1 . id . should . equal ( John2 . id ) ;
109+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
105110 John2 . name . should . equal ( "James" ) ;
106111
107112 return done ( ) ;
@@ -117,12 +122,12 @@ describe("Model.get()", function() {
117122
118123 describe ( "fetching several times" , function ( ) {
119124 it ( "should return different objects" , function ( done ) {
120- Person . get ( 1 , function ( err , John1 ) {
125+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
121126 should . equal ( err , null ) ;
122- Person . get ( 1 , function ( err , John2 ) {
127+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
123128 should . equal ( err , null ) ;
124129
125- John1 . id . should . equal ( John2 . id ) ;
130+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
126131 John1 . should . not . equal ( John2 ) ;
127132
128133 return done ( ) ;
@@ -137,14 +142,14 @@ describe("Model.get()", function() {
137142
138143 describe ( "fetching again after 0.2 secs" , function ( ) {
139144 it ( "should return same objects" , function ( done ) {
140- Person . get ( 1 , function ( err , John1 ) {
145+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
141146 should . equal ( err , null ) ;
142147
143148 setTimeout ( function ( ) {
144- Person . get ( 1 , function ( err , John2 ) {
149+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
145150 should . equal ( err , null ) ;
146151
147- John1 . id . should . equal ( John2 . id ) ;
152+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
148153 John1 . should . equal ( John2 ) ;
149154
150155 return done ( ) ;
@@ -156,11 +161,11 @@ describe("Model.get()", function() {
156161
157162 describe ( "fetching again after 0.7 secs" , function ( ) {
158163 it ( "should return different objects" , function ( done ) {
159- Person . get ( 1 , function ( err , John1 ) {
164+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
160165 should . equal ( err , null ) ;
161166
162167 setTimeout ( function ( ) {
163- Person . get ( 1 , function ( err , John2 ) {
168+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
164169 should . equal ( err , null ) ;
165170
166171 John1 . should . not . equal ( John2 ) ;
@@ -177,11 +182,11 @@ describe("Model.get()", function() {
177182 before ( setup ( ) ) ;
178183
179184 it ( "should return item with id 1 like previously" , function ( done ) {
180- Person . get ( 1 , { } , function ( err , John ) {
185+ Person . get ( John [ Person . id ] , { } , function ( err , John ) {
181186 should . equal ( err , null ) ;
182187
183188 John . should . be . a ( "object" ) ;
184- John . should . have . property ( "id" , 1 ) ;
189+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
185190 John . should . have . property ( "name" , "John Doe" ) ;
186191
187192 return done ( ) ;
@@ -194,7 +199,7 @@ describe("Model.get()", function() {
194199
195200 it ( "should throw" , function ( done ) {
196201 ( function ( ) {
197- Person . get ( 1 ) ;
202+ Person . get ( John [ Person . id ] ) ;
198203 } ) . should . throw ( ) ;
199204
200205 return done ( ) ;
@@ -218,11 +223,11 @@ describe("Model.get()", function() {
218223 before ( setup ( true ) ) ;
219224
220225 it ( "should accept and try to fetch" , function ( done ) {
221- Person . get ( [ 1 ] , function ( err , John ) {
226+ Person . get ( [ John [ Person . id ] ] , function ( err , John ) {
222227 should . equal ( err , null ) ;
223228
224229 John . should . be . a ( "object" ) ;
225- John . should . have . property ( "id" , 1 ) ;
230+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
226231 John . should . have . property ( "name" , "John Doe" ) ;
227232
228233 return done ( ) ;
@@ -269,7 +274,6 @@ describe("Model.get()", function() {
269274 OtherPerson . get ( "Jane Doe" , function ( err , person ) {
270275 should . equal ( err , null ) ;
271276
272- person . id . should . be . a ( "number" ) ;
273277 person . name . should . equal ( "Jane Doe" ) ;
274278
275279 return done ( ) ;
0 commit comments