Skip to content

Commit

Permalink
Fix bug in deepExtend that modifies extended machine.
Browse files Browse the repository at this point in the history
  • Loading branch information
fwg committed Feb 4, 2013
1 parent 8b4eb48 commit 3acda81
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/node/machina.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = require( 'underscore' );
obj[sourcePropKey] = sourcePropVal;
},
"object" : function ( obj, sourcePropKey, sourcePropVal ) {
obj[sourcePropKey] = deepExtend( obj[sourcePropKey] || {}, sourcePropVal );
obj[sourcePropKey] = deepExtend( {}, sourcePropVal );
},
"array" : function ( obj, sourcePropKey, sourcePropVal ) {
obj[sourcePropKey] = [];
Expand Down Expand Up @@ -330,4 +330,4 @@ var _ = require( 'underscore' );

machina.emit = machina.trigger;

module.exports = machina;
module.exports = machina;
46 changes: 45 additions & 1 deletion spec/machina.fsm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,50 @@ describe( "machina.Fsm", function () {
} );
} );

describe( "When extending an FSM contructor twice with overriden state & handlers", function () {
var Base = machina.Fsm.extend({
initialState: 'S',
states: {
S: {
action1: function () {
},
action2: function () {
}
}
}
});

var Extend1 = Base.extend({
states: {
S: {
action1: function () {
}
}
}
});

var Extend2 = Base.extend({
states: {
S: {
action2: function () {
}
}
}
});

var b1 = new Base();
var e1 = new Extend1();
var e2 = new Extend2();

it( "should produce instances that have distinct action handlers", function () {
expect( b1.states.S.action1 !== e1.states.S.action1 );
expect( b1.states.S.action2 !== e2.states.S.action2 );

expect( e1.states.S.action1 !== e2.states.S.action1 );
expect( e1.states.S.action2 !== e2.states.S.action2 );
});
});

describe( "When providing a global catch-all handler", function () {
var catchAllHandled = [],
stateSpecificCatchAllHandled = [];
Expand Down Expand Up @@ -802,4 +846,4 @@ describe( "machina.Fsm", function () {
} );
} );
} );
} );
} );

0 comments on commit 3acda81

Please sign in to comment.