Permalink
Browse files

Merge branch 'model-sync-options' into dev-master

  • Loading branch information...
2 parents 902538c + dcd5614 commit 686c2a79905389dbf73f961cde63b73829c21b40 @ericf ericf committed Apr 11, 2013
Showing with 29 additions and 2 deletions.
  1. +11 −0 src/app/HISTORY.md
  2. +6 −2 src/app/js/model.js
  3. +12 −0 src/app/tests/unit/assets/model-test.js
View
@@ -1,6 +1,17 @@
App Framework Change History
============================
+@VERSION@
+-----
+
+### Model
+
+* Fixed: The `options` object passed to Model's `setAttrs()` method was being
+ modified. Now a shallow copy of this object is now created so that the
+ `_transaction` property is added to the copy and not the passed-in object.
+ [#598]
+
+
3.9.1
-----
View
@@ -594,7 +594,9 @@ Y.Model = Y.extend(Model, Y.Base, {
var idAttribute = this.idAttribute,
changed, e, key, lastChange, transaction;
- options || (options = {});
+ // Makes a shallow copy of the `options` object before adding the
+ // `_transaction` object to it so we don't modify someone else's object.
+ options = Y.merge(options);
transaction = options._transaction = {};
// When a custom id attribute is in use, always keep the default `id`
@@ -642,7 +644,9 @@ Y.Model = Y.extend(Model, Y.Base, {
});
}
- this.fire(EVT_CHANGE, Y.merge(options, {changed: lastChange}));
+ options.changed = lastChange;
+
+ this.fire(EVT_CHANGE, options);
}
}
@@ -726,6 +726,18 @@ modelSuite.add(new Y.Test.Case({
Assert.areSame('bar', model.get('bar'));
},
+ 'setAttrs() should not modify the passed-in `options` object': function () {
+ var model = new this.TestModel(),
+ options = {foo: 'foo'};
+
+ ArrayAssert.itemsAreSame(['foo'], Y.Object.keys(options));
+
+ model.setAttrs({bar: 'bar'}, options);
+
+ Assert.areSame('bar', model.get('bar'));
+ ArrayAssert.itemsAreSame(['foo'], Y.Object.keys(options));
+ },
+
'sync() should just call the supplied callback by default': function () {
var calls = 0,
model = new this.TestModel();

0 comments on commit 686c2a7

Please sign in to comment.