不要怂,就是干,撸起袖子干!

Commit 97ff7a47 by Nick Kleinschmidt

Add test case for updating a JSON field using postgres with a custom field name

1 parent 7895f286
Showing with 35 additions and 0 deletions
...@@ -72,6 +72,41 @@ if (dialect.match(/^postgres/)) { ...@@ -72,6 +72,41 @@ if (dialect.match(/^postgres/)) {
}); });
}); });
it('should insert json using a custom field name', function(done) {
var self = this;
this.UserFields = this.sequelize.define('UserFields', {
emergency_contact: { type: DataTypes.JSON, field: 'something_else' }
});
this.UserFields.sync({ force: true }).then(function() {
self.UserFields.create({
emergency_contact: { name: 'joe', phones: [1337, 42] }
}).then(function(user) {
expect(user.emergency_contact.name).to.equal('joe');
done();
});
});
});
it('should update json using a custom field name', function(done) {
var self = this;
this.UserFields = this.sequelize.define('UserFields', {
emergency_contact: { type: DataTypes.JSON, field: 'something_else' }
});
this.UserFields.sync({ force: true }).then(function() {
self.UserFields.create({
emergency_contact: { name: 'joe', phones: [1337, 42] }
}).then(function(user) {
user.emergency_contact = { name: 'larry' };
return user.save();
}).then(function(user) {
expect(user.emergency_contact.name).to.equal('larry');
done();
});
});
});
it('should be able retrieve json value as object', function() { it('should be able retrieve json value as object', function() {
var self = this; var self = this;
var emergencyContact = { name: 'kate', phone: 1337 }; var emergencyContact = { name: 'kate', phone: 1337 };
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!