Merge branch 'release/1.3.2' into production

This commit is contained in:
Raymond Feng 2014-02-13 08:53:05 -08:00
commit 1773372933
3 changed files with 50 additions and 3 deletions

View File

@ -870,12 +870,14 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb
} else { } else {
inst.trigger('save', function (saveDone) { inst.trigger('save', function (saveDone) {
inst.trigger('update', function (done) { inst.trigger('update', function (done) {
var typedData = {};
for (var key in data) { for (var key in data) {
inst[key] = data[key]; inst[key] = data[key];
typedData[key] = inst.__data[key];
} }
inst._adapter().updateAttributes(model, getIdValue(inst.constructor, inst), inst.constructor._forDB(data), function (err) { inst._adapter().updateAttributes(model, getIdValue(inst.constructor, inst), inst.constructor._forDB(typedData), function (err) {
if (!err) { if (!err) {
// update $was attrs // update $was attrs
for (var key in data) { for (var key in data) {

View File

@ -1,6 +1,6 @@
{ {
"name": "loopback-datasource-juggler", "name": "loopback-datasource-juggler",
"version": "1.3.1", "version": "1.3.2",
"description": "LoopBack DataSoure Juggler", "description": "LoopBack DataSoure Juggler",
"keywords": [ "keywords": [
"StrongLoop", "StrongLoop",

View File

@ -12,7 +12,7 @@ describe('datatypes', function () {
date: Date, date: Date,
num: Number, num: Number,
bool: Boolean, bool: Boolean,
list: {type: []}, list: {type: [String]},
}); });
db.automigrate(function () { db.automigrate(function () {
Model.destroyAll(done); Model.destroyAll(done);
@ -63,4 +63,49 @@ describe('datatypes', function () {
}); });
it('should respect data types when updating attributes', function (done) {
var d = new Date, id;
Model.create({
str: 'hello', date: d, num: '3', bool: 1}, function(err, m) {
should.not.exist(err);
should.exist(m && m.id);
// sanity check initial types
m.str.should.be.a('string');
m.num.should.be.a('number');
m.bool.should.be.a('boolean');
id = m.id;
testDataInDB(function () {
testUpdate(function() {
testDataInDB(done);
});
});
});
function testUpdate(done) {
Model.findById(id, function(err, m) {
should.not.exist(err);
// update using updateAttributes
m.updateAttributes({
id: id, num: '10'
}, function (err, m) {
should.not.exist(err);
m.num.should.be.a('number');
done();
});
});
}
function testDataInDB(done) {
// verify that the value stored in the db is still an object
db.connector.find(Model.modelName, id, function (err, data) {
should.exist(data);
data.num.should.be.a('number');
done();
});
}
});
}); });