File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ module.exports = function(AV) {
5050 attributes = attributes || { } ;
5151 if ( options && options . parse ) {
5252 attributes = this . parse ( attributes ) ;
53+ attributes = this . _mergeMagicFields ( attributes ) ;
5354 }
5455 var defaults = AV . _getValue ( this , 'defaults' ) ;
5556 if ( defaults ) {
@@ -375,6 +376,7 @@ module.exports = function(AV) {
375376 delete attrs [ attr ] ;
376377 }
377378 } ) ;
379+ return attrs ;
378380 } ,
379381
380382 /**
@@ -652,8 +654,6 @@ module.exports = function(AV) {
652654 // Run validation.
653655 this . _validate ( attrs , options ) ;
654656
655- this . _mergeMagicFields ( attrs ) ;
656-
657657 options . changes = { } ;
658658 var escaped = this . _escapedAttributes ;
659659 var prev = this . _previousAttributes || { } ;
Original file line number Diff line number Diff line change @@ -89,6 +89,17 @@ describe('Objects', function(){
8989 } ) ;
9090 } ) ;
9191
92+ it ( 'toJSON and parse' , ( ) => {
93+ const json = gameScore . toJSON ( ) ;
94+ json . objectId . should . eql ( gameScore . id ) ;
95+ json . id . should . eql ( gameScore . get ( 'id' ) ) ;
96+ json . score . should . eql ( gameScore . get ( 'score' ) ) ;
97+ const parsedGameScore = new GameScore ( json , { parse : true } ) ;
98+ parsedGameScore . id . should . eql ( gameScore . id ) ;
99+ parsedGameScore . get ( 'id' ) . should . eql ( gameScore . get ( 'id' ) ) ;
100+ parsedGameScore . get ( 'score' ) . should . eql ( gameScore . get ( 'score' ) ) ;
101+ } ) ;
102+
92103 it ( 'should create a User' , function ( ) {
93104 var User = AV . Object . extend ( "User" ) ;
94105 var u = new User ( ) ;
You can’t perform that action at this time.
0 commit comments