fixing #38 shouldn't mutate insert array

This commit is contained in:
Tim Griesser 2013-08-13 17:44:53 -04:00
parent e290513713
commit a14ebd23f7
2 changed files with 17 additions and 1 deletions

View File

@ -785,7 +785,7 @@
// Sets the values for an `insert` query.
insert: function(values, returning) {
if (returning) this.returning(returning);
this.values = this._prepValues(values);
this.values = this._prepValues(_.clone(values));
return this._setType('insert');
},

View File

@ -1,5 +1,6 @@
var uuid = require('node-uuid');
var deepEqual = require('assert').deepEqual;
module.exports = function(Knex, dbName, resolver) {
@ -156,6 +157,21 @@ module.exports = function(Knex, dbName, resolver) {
});
it('should not mutate the array passed in', function(ok) {
var a = {enum_value: 'a', uuid: uuid.v4()};
var b = {enum_value: 'c', uuid: uuid.v4()};
var x = [a, b];
Knex('datatype_test')
.insert(x)
.then(function() {
deepEqual(x, [a, b]);
ok();
})
.then(null, ok);
});
});
};