Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dirty tracking for Number attr #347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions packages/ember-model/tests/dirty_tracking_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,71 @@ test("manipulating the content of objects in a hasMany should dirty the parent",
ok(post.get('comments.isDirty') === true, "post.comments should be dirty after changing comment1's content");
ok(post.get('isDirty') === true, "Post should be dirty after changing comment1's content");
});

test("dirty tracking for Number attr", function() {
expect(7);
var Model = Ember.Model.extend({
num: attr(Number)
});
Model.adapter = Ember.FixtureAdapter.create();

Model.load({ id: '123', num: 1 });
var model = Ember.run(Model, Model.find, '123');
equal(model.get('isDirty'), false, "Model should be initially clean");

model.set('num', 2);
equal(model.get('isDirty'), true, "Model should be dirty after being modified");

model.set('num', 1);
equal(model.get('isDirty'), false, "Model should be clean again");

model.set('num', 2);
stop();
Ember.run(function() {
model.save().then(function() {
start();
equal(model.get('isDirty'), false, "The model is clean after being saved");

model.set('num', 3);
equal(model.get('isDirty'), true, "Model should be dirty after being modified");

model.set('num', 1);
equal(model.get('isDirty'), true, "Model should be dirty after being modified (original value)");

model.set('num', 2);
equal(model.get('isDirty'), false, "Model should be clean again");
});
});
});

test("dirty tracking for Number attr, mixing strings and numbers", function() {
expect(6);
var Model = Ember.Model.extend({
num: attr(Number)
});
Model.adapter = Ember.FixtureAdapter.create();

Model.load({ id: '123', num: 1 });
var model = Ember.run(Model, Model.find, '123');
equal(model.get('isDirty'), false, "Model should be initially clean");

model.set('num', '1');
equal(model.get('isDirty'), false, "Model should still be clean");

model.set('num', '2');
equal(model.get('isDirty'), true, "Model should be dirty");

stop();
Ember.run(function() {
model.save().then(function() {
start();
equal(model.get('isDirty'), false, "The model is clean after being saved");

model.set('num', '2');
equal(model.get('isDirty'), false, "Model should still be clean");

model.set('num', 2);
equal(model.get('isDirty'), false, "Model should be clean since 2 == '2'");
});
});
});