Commit 6910216b5d835929fd8870d29db6e9b5162b3f8c

Authored by Arek W
1 parent c50f43bc

Add failing test case

test/integration/model-create.js
... ... @@ -13,7 +13,8 @@ describe("Model.create()", function() {
13 13 name : String
14 14 });
15 15 Pet = db.define("pet", {
16   - name : { type: "text", defaultValue: "Mutt" }
  16 + name : { type: "text", defaultValue: "Mutt" },
  17 + age : { type: 'number' }
17 18 });
18 19 Person.hasMany("pets", Pet);
19 20  
... ... @@ -123,5 +124,29 @@ describe("Model.create()", function() {
123 124 return done();
124 125 });
125 126 });
  127 +
  128 + it("should not use defaultValue when updating", function (done) {
  129 + Pet.create({name: "Ruffy"}, function (err, pet) {
  130 + should.equal(err, null);
  131 + should.equal(pet.name, "Ruffy");
  132 +
  133 + // simulated data from a user
  134 + var params = { age: 4 };
  135 +
  136 + pet.age = params.age;
  137 + pet.name = params.name; // we expected a name, but it's undefined
  138 +
  139 + pet.save(function (err) {
  140 + should.not.exist(err);
  141 +
  142 + Pet.get(pet.id, function (err, pet) {
  143 + should.not.exist(err);
  144 + should.strictEqual(pet.name, null);
  145 +
  146 + done();
  147 + })
  148 + });
  149 + })
  150 + });
126 151 });
127 152 });
... ...