@@ -6,6 +6,7 @@ var constructor = require("can-connect/constructor/");
6
6
var canMap = require ( "can-connect/can/map/" ) ;
7
7
var canRef = require ( "can-connect/can/ref/" ) ;
8
8
var connect = require ( "can-connect" ) ;
9
+ var canSymbol = require ( "can-symbol" ) ;
9
10
10
11
// connects the "raw" data to a a constructor function
11
12
// creates ways to CRUD the instances
@@ -249,4 +250,71 @@ QUnit.asyncTest("populate Ref that was already created without a value", functio
249
250
QUnit . ok ( false , "error" ) ;
250
251
QUnit . start ( ) ;
251
252
} ) ;
252
- } ) ;
253
+ } ) ;
254
+
255
+ QUnit . test ( 'should serialize object ref' , function ( ) {
256
+ var Team = DefineMap . extend ( {
257
+ id : 'object'
258
+ } ) ;
259
+
260
+ connect ( [ constructor , constructorStore , canMap , canRef ] ,
261
+ {
262
+ Map : Team
263
+ } ) ;
264
+
265
+ var Game = DefineMap . extend ( {
266
+ id : 'string' ,
267
+ teamRef : Team . Ref ,
268
+ score : "number"
269
+ } ) ;
270
+
271
+ connect ( [ constructor , constructorStore , canMap , canRef ] ,
272
+ {
273
+ Map : Game
274
+ } ) ;
275
+
276
+ var team = new Team ( { id : { _id : 5 } } ) ;
277
+
278
+ var game = new Game ( {
279
+ id : 6 ,
280
+ teamRef : team ,
281
+ score : 22
282
+ } ) ;
283
+
284
+ QUnit . equal ( typeof game . teamRef . serialize , 'function' ) ;
285
+ QUnit . equal ( typeof game . teamRef [ canSymbol . for ( "can.serialize" ) ] , 'function' ) ;
286
+ QUnit . deepEqual ( game . teamRef . serialize ( ) , { _id : 5 } ) ;
287
+ } ) ;
288
+
289
+
290
+ QUnit . test ( 'should serialize string ref' , function ( ) {
291
+ var Team = DefineMap . extend ( {
292
+ id : 'string'
293
+ } ) ;
294
+
295
+ connect ( [ constructor , constructorStore , canMap , canRef ] ,
296
+ {
297
+ Map : Team
298
+ } ) ;
299
+
300
+ var Game = DefineMap . extend ( {
301
+ id : 'string' ,
302
+ teamRef : Team . Ref ,
303
+ score : "number"
304
+ } ) ;
305
+
306
+ connect ( [ constructor , constructorStore , canMap , canRef ] ,
307
+ {
308
+ Map : Game
309
+ } ) ;
310
+
311
+ var team = new Team ( { id : 5 } ) ;
312
+
313
+ var game = new Game ( {
314
+ id : 6 ,
315
+ teamRef : team ,
316
+ score : 22
317
+ } ) ;
318
+
319
+ QUnit . equal ( game . teamRef . serialize ( ) , '5' ) ;
320
+ } ) ;
0 commit comments