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

Commit 27b83d3a by Sushant Committed by Jan Aagaard Meier

Fixed #4893, DECIMAL precision for Postgres (#5860)

* test for DECIMAL parser and string default

* fixed test cases using Int value for decimal
1 parent a81128bf
# Future
- [FIXED] Postgres DECIMAL precision. (PostgreSQL) [#4893](https://github.com/sequelize/sequelize/issues/4893)
# 3.23.0 # 3.23.0
- [FIXED] Invalid query generated when using LIKE + ANY [#5736](https://github.com/sequelize/sequelize/issues/5736) - [FIXED] Invalid query generated when using LIKE + ANY [#5736](https://github.com/sequelize/sequelize/issues/5736)
- [FIXED] Method QueryInterface.bulkDelete no longer working when the model parameter is missing. (PostgreSQL) [#5615](https://github.com/sequelize/sequelize/issues/5615) - [FIXED] Method QueryInterface.bulkDelete no longer working when the model parameter is missing. (PostgreSQL) [#5615](https://github.com/sequelize/sequelize/issues/5615)
......
...@@ -36,7 +36,7 @@ module.exports = function (BaseTypes) { ...@@ -36,7 +36,7 @@ module.exports = function (BaseTypes) {
var DECIMAL = BaseTypes.DECIMAL.inherits(); var DECIMAL = BaseTypes.DECIMAL.inherits();
DECIMAL.parse = function (value) { DECIMAL.parse = function (value) {
return parseFloat(value); return value;
}; };
// numeric // numeric
......
...@@ -307,7 +307,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -307,7 +307,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
if (dialect === 'postgres' || dialect === 'sqlite') { if (dialect === 'postgres' || dialect === 'sqlite') {
// postgres actively supports IEEE floating point literals, and sqlite doesn't care what we throw at it // postgres actively supports IEEE floating point literals, and sqlite doesn't care what we throw at it
it('should store and parse IEEE floating point literals (NaN and Infinity', function () { it('should store and parse IEEE floating point literals (NaN and Infinity)', function () {
var Model = this.sequelize.define('model', { var Model = this.sequelize.define('model', {
float: Sequelize.FLOAT, float: Sequelize.FLOAT,
double: Sequelize.DOUBLE, double: Sequelize.DOUBLE,
...@@ -330,4 +330,38 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -330,4 +330,38 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
}); });
}); });
} }
if (dialect === 'postgres') {
it('should parse DECIMAL as string', function () {
var Model = this.sequelize.define('model', {
decimal: Sequelize.DECIMAL,
decimalPre: Sequelize.DECIMAL(10, 4),
decimalWithParser: Sequelize.DECIMAL(32, 15),
decimalWithIntParser: Sequelize.DECIMAL(10, 4),
decimalWithFloatParser: Sequelize.DECIMAL(10, 8)
});
var sampleData = {
id: 1,
decimal: 12345678.12345678,
decimalPre: 123456.1234,
decimalWithParser: '12345678123456781.123456781234567',
decimalWithIntParser: 1.234,
decimalWithFloatParser: 0.12345678
};
return Model.sync({ force: true }).then(function () {
return Model.create(sampleData);
}).then(function () {
return Model.find({id: 1});
}).then(function (user) {
expect(user.get('decimal')).to.be.eql('12345678.12345678');
expect(user.get('decimalPre')).to.be.eql('123456.1234');
expect(user.get('decimalWithParser')).to.be.eql('12345678123456781.123456781234567');
expect(user.get('decimalWithIntParser')).to.be.eql('1.2340');
expect(user.get('decimalWithFloatParser')).to.be.eql('0.12345678');
});
});
}
}); });
...@@ -645,8 +645,8 @@ if (dialect.match(/^postgres/)) { ...@@ -645,8 +645,8 @@ if (dialect.match(/^postgres/)) {
// Check to see if the default value for a range field works // Check to see if the default value for a range field works
expect(newUser.acceptable_marks.length).to.equal(2); expect(newUser.acceptable_marks.length).to.equal(2);
expect(newUser.acceptable_marks[0]).to.equal(0.65); // lower bound expect(newUser.acceptable_marks[0]).to.equal('0.65'); // lower bound
expect(newUser.acceptable_marks[1]).to.equal(1); // upper bound expect(newUser.acceptable_marks[1]).to.equal('1'); // upper bound
expect(newUser.acceptable_marks.inclusive).to.deep.equal([false, false]); // not inclusive expect(newUser.acceptable_marks.inclusive).to.deep.equal([false, false]); // not inclusive
expect(newUser.course_period[0] instanceof Date).to.be.ok; // lower bound expect(newUser.course_period[0] instanceof Date).to.be.ok; // lower bound
expect(newUser.course_period[1] instanceof Date).to.be.ok; // upper bound expect(newUser.course_period[1] instanceof Date).to.be.ok; // upper bound
...@@ -717,8 +717,8 @@ if (dialect.match(/^postgres/)) { ...@@ -717,8 +717,8 @@ if (dialect.match(/^postgres/)) {
return User.create({ username: 'user', email: ['foo@bar.com'], course_period: period }).then(function(newUser) { return User.create({ username: 'user', email: ['foo@bar.com'], course_period: period }).then(function(newUser) {
// Check to see if the default value for a range field works // Check to see if the default value for a range field works
expect(newUser.acceptable_marks.length).to.equal(2); expect(newUser.acceptable_marks.length).to.equal(2);
expect(newUser.acceptable_marks[0]).to.equal(0.65); // lower bound expect(newUser.acceptable_marks[0]).to.equal('0.65'); // lower bound
expect(newUser.acceptable_marks[1]).to.equal(1); // upper bound expect(newUser.acceptable_marks[1]).to.equal('1'); // upper bound
expect(newUser.acceptable_marks.inclusive).to.deep.equal([false, false]); // not inclusive expect(newUser.acceptable_marks.inclusive).to.deep.equal([false, false]); // not inclusive
expect(newUser.course_period[0] instanceof Date).to.be.ok; expect(newUser.course_period[0] instanceof Date).to.be.ok;
expect(newUser.course_period[1] instanceof Date).to.be.ok; expect(newUser.course_period[1] instanceof Date).to.be.ok;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!