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

Commit b836799f by sdepold

Merge branch 'master' of https://github.com/grayt0r/sequelize into grayt0r-master

2 parents f7bcdcc5 b1e5e328
Showing with 54 additions and 0 deletions
...@@ -223,6 +223,10 @@ module.exports = (function() { ...@@ -223,6 +223,10 @@ module.exports = (function() {
DAO.prototype.setValidators = function(attribute, validators) { DAO.prototype.setValidators = function(attribute, validators) {
this.validators[attribute] = validators this.validators[attribute] = validators
} }
DAO.prototype.toJSON = function() {
return this.values;
}
// private // private
......
...@@ -496,6 +496,56 @@ describe('DAO', function() { ...@@ -496,6 +496,56 @@ describe('DAO', function() {
}) })
}) })
}) })
describe('toJSON', function() {
it('returns an object containing all values', function() {
var User = sequelize.define('User', {
username: Sequelize.STRING, age: Sequelize.INTEGER, dob: Sequelize.DATE, isAdmin: Sequelize.BOOLEAN
}, { timestamps: false, logging: false })
Helpers.async(function(done) {
User.sync({ force: true }).success(done)
})
Helpers.async(function(done) {
var user = User.build({ username: 'test.user', age: 99, dob: new Date(1973,4,6), isAdmin: true })
expect(user.toJSON()).toEqual({ username: 'test.user', age: 99, dob: new Date(1973,4,6), isAdmin: true, id: null })
done()
})
})
it('returns a response that can be stringified', function() {
var User = sequelize.define('User', {
username: Sequelize.STRING, age: Sequelize.INTEGER, dob: Sequelize.DATE, isAdmin: Sequelize.BOOLEAN
}, { timestamps: false, logging: false })
Helpers.async(function(done) {
User.sync({ force: true }).success(done)
})
Helpers.async(function(done) {
var user = User.build({ username: 'test.user', age: 99, dob: new Date(1973,4,6), isAdmin: true })
expect(JSON.stringify(user)).toEqual('{"username":"test.user","age":99,"dob":"1973-05-05T23:00:00.000Z","isAdmin":true,"id":null}')
done()
})
})
it('returns a response that can be stringified and then parsed', function() {
var User = sequelize.define('User', {
username: Sequelize.STRING, age: Sequelize.INTEGER, dob: Sequelize.DATE, isAdmin: Sequelize.BOOLEAN
}, { timestamps: false, logging: false })
Helpers.async(function(done) {
User.sync({ force: true }).success(done)
})
Helpers.async(function(done) {
var user = User.build({ username: 'test.user', age: 99, dob: new Date(1973,4,6), isAdmin: true })
expect(JSON.parse(JSON.stringify(user))).toEqual({ username: 'test.user', age: 99, dob: "1973-05-05T23:00:00.000Z", isAdmin: true, id: null })
done()
})
})
})
}) })
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!