Skip to content

Commit

Permalink
fix(collection): $push should work with arrays when inserting new rec…
Browse files Browse the repository at this point in the history
…ords
  • Loading branch information
andreialecu authored and ericfong committed Jan 30, 2015
1 parent 061f16d commit 077c2b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/resources/collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ Collection.prototype.save = function (ctx, fn) {
}

function post() {
collection.execCommands('update', item, commands);
var errs = collection.validate(item, true);

if(errs) return done({errors: errs});
Expand Down
11 changes: 11 additions & 0 deletions test/collection.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ describe('collection', function(){
});
});
});

it('should not fail validation on $push with required array', function (done) {
var c = new Collection('persons', { db: db.create(TEST_DB), config: { properties: { names: { type: 'array', required: true } } } });

c.save({ body: { names: { $pushAll: ['jim','sam', 'joe'] } } }, function (err, item) {
expect(item.id).to.exist;
expect(err).to.not.exist;
expect(item.names).to.eql(['jim', 'sam', 'joe']);
done(err);
});
});

it('should not add duplicate elements and add unique elements on $addUnique', function(done) {
var c = new Collection('persons', {db: db.create(TEST_DB), config: { properties: {names: {type: 'array'}}}});
Expand Down

0 comments on commit 077c2b9

Please sign in to comment.