Skip to content

Commit

Permalink
Allow adapters to load new data for clean records
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhuda committed Feb 26, 2012
1 parent 8b315fc commit bbf044b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ember-data/lib/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ var states = {
manager.goToState('updated');
},

didChangeData: didChangeData,

deleteRecord: function(manager) {
manager.goToState('deleted');
},
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-data/tests/unit/store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ test("DS.Store loads individual models without explicit IDs", function() {
equal(get(tom, 'name'), "Tom Dale", "the person was successfully loaded for the given ID");
});

test("can load data for the same record if it is not dirty", function() {
var store = DS.Store.create();
var Person = DS.Model.extend({
name: DS.attr('string')
});

store.load(Person, { id: 1, name: "Tom Dale" });
var tom = store.find(Person, 1);

equal(get(tom, 'isDirty'), false, "precond - record is not dirty");
equal(get(tom, 'name'), "Tom Dale", "returns the correct name");

store.load(Person, { id: 1, name: "Captain Underpants" });
equal(get(tom, 'name'), "Captain Underpants", "updated record with new date");
});

test("DS.Store loads individual models without explicit IDs with a custom primaryKey", function() {
var store = DS.Store.create();
var Person = DS.Model.extend({ name: DS.attr('string'), primaryKey: 'key' });
Expand Down

0 comments on commit bbf044b

Please sign in to comment.