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

Commit 5b45e492 by Michael Storgaard

Changed booleans to no longer return false, if they are in fact null

1 parent d4d2f7be
Showing with 20 additions and 1 deletions
...@@ -409,7 +409,7 @@ module.exports = (function() { ...@@ -409,7 +409,7 @@ module.exports = (function() {
} }
DAO.prototype.addAttribute = function(attribute, value) { DAO.prototype.addAttribute = function(attribute, value) {
if (this.booleanValues.length && this.booleanValues.indexOf(attribute) !== -1 && value !== undefined) { // transform integer 0,1 into boolean if (this.booleanValues.length && this.booleanValues.indexOf(attribute) !== -1 && value != null) { // transform integer 0,1 into boolean
value = !!value value = !!value
} }
......
...@@ -1114,6 +1114,25 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1114,6 +1114,25 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
}) })
}) })
it("returns null for null, undefined, and unset boolean values", function(done) {
var Setting = this.sequelize.define('SettingHelper', {
setting_key: DataTypes.STRING,
bool_value: { type: DataTypes.BOOLEAN, allowNull: true },
bool_value2: { type: DataTypes.BOOLEAN, allowNull: true },
bool_value3: { type: DataTypes.BOOLEAN, allowNull: true }
}, { timestamps: false, logging: false })
Setting.sync({ force: true }).success(function() {
Setting.create({ setting_key: 'test', bool_value: null, bool_value2: undefined }).success(function() {
Setting.find({ where: { setting_key: 'test' } }).success(function(setting) {
expect(setting.bool_value).to.equal(null)
expect(setting.bool_value2).to.equal(null)
expect(setting.bool_value3).to.equal(null)
done()
})
})
})
})
}) })
describe('equals', function() { describe('equals', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!