Skip to content

Commit

Permalink
Editing an object after it has been used as the starting attributes o…
Browse files Browse the repository at this point in the history
…f a model shouldn't affect the model's attributes.
  • Loading branch information
benpickles committed Oct 15, 2010
1 parent 1253d10 commit 59f6a1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/model.js
Expand Up @@ -4,7 +4,7 @@ var Model = function(name, class_methods, instance_methods) {

// The model constructor.
var model = function(attributes) {
this.attributes = attributes || {};
this.attributes = jQuery.extend({}, attributes)
this.changes = {};
this.errors = new Model.Errors(this);
this.uid = [name, Model.UID.generate()].join("-")
Expand Down
16 changes: 13 additions & 3 deletions test/tests/model.js
@@ -1,10 +1,20 @@
module("Model");

test("attr, attributes, changes, reset, save, destroy", function() {
var Post = Model("post");
test("defining attributes when instanciating a model", function() {
var Post = Model("post")
var post

post = new Post(undefined)
same({}, post.attributes)

same(new Post().attributes, {});
var attributes = { a: "a", b: "b" }
post = new Post(attributes)
attributes.a = "b"
same("a", post.attributes.a)
})

test("attr, attributes, changes, reset, save, destroy", function() {
var Post = Model("post");
var post = new Post({ title: "Foo", body: "..." });

same(post.attributes, { title: "Foo", body: "..." });
Expand Down

0 comments on commit 59f6a1c

Please sign in to comment.