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

Commit 484c0c2d by Jan Aagaard Meier

test(bugfix) Test for issues with sqlite and date parsing. Closes #3611, Closes #2644

1 parent a96308d6
...@@ -423,10 +423,14 @@ DATE.prototype.validate = function(value) { ...@@ -423,10 +423,14 @@ DATE.prototype.validate = function(value) {
}; };
DATE.prototype.$applyTimezone = function (date, options) { DATE.prototype.$applyTimezone = function (date, options) {
if (moment.tz.zone(options.timezone)) { date = moment(date);
date = moment(date).tz(options.timezone);
} else { if (options.timezone) {
date = moment(date).utcOffset(options.timezone); if (moment.tz.zone(options.timezone)) {
date = date.tz(options.timezone);
} else {
date = date.utcOffset(options.timezone);
}
} }
return date; return date;
......
...@@ -12,7 +12,7 @@ var chai = require('chai') ...@@ -12,7 +12,7 @@ var chai = require('chai')
, current = Support.sequelize , current = Support.sequelize
, dialect = Support.getTestDialect(); , dialect = Support.getTestDialect();
describe.only(Support.getTestDialectTeaser('DataTypes'), function() { describe(Support.getTestDialectTeaser('DataTypes'), function() {
it('allows me to return values from a custom parse function', function () { it('allows me to return values from a custom parse function', function () {
var parse = Sequelize.DATE.parse = sinon.spy(function (value) { var parse = Sequelize.DATE.parse = sinon.spy(function (value) {
return moment(value, 'YYYY-MM-DD HH:mm:ss Z'); return moment(value, 'YYYY-MM-DD HH:mm:ss Z');
......
...@@ -10,9 +10,21 @@ if (dialect === 'sqlite') { ...@@ -10,9 +10,21 @@ if (dialect === 'sqlite') {
describe('[SQLITE Specific] DAO', function() { describe('[SQLITE Specific] DAO', function() {
beforeEach(function() { beforeEach(function() {
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
username: DataTypes.STRING username: DataTypes.STRING,
dateField: {
type: DataTypes.DATE,
field: 'date_field'
}
}); });
return this.User.sync({ force: true }); this.Project = this.sequelize.define('project', {
dateField: {
type: DataTypes.DATE,
field: 'date_field'
}
});
this.User.hasMany(this.Project);
return this.sequelize.sync({ force: true });
}); });
describe('findAll', function() { describe('findAll', function() {
...@@ -25,13 +37,39 @@ if (dialect === 'sqlite') { ...@@ -25,13 +37,39 @@ if (dialect === 'sqlite') {
return user.save().then(function() { return user.save().then(function() {
return self.User.create({ username: 'new user' }).then(function() { return self.User.create({ username: 'new user' }).then(function() {
return self.User.findAll({ return self.User.findAll({
where: ['createdAt > ?', new Date(2012, 1, 1)] where: { createdAt: { $gt: new Date(2012, 1, 1) }}
}).then(function(users) { }).then(function(users) {
expect(users).to.have.length(1); expect(users).to.have.length(1);
}); });
}); });
}); });
}); });
it('handles dates with aliasses correctly #3611', function() {
return this.User.create({
dateField: new Date(2010, 10, 10)
}).bind(this).then(function () {
return this.User.findAll().get(0);
}).then(function (user) {
expect(user.get('dateField')).to.be.an.instanceof(Date);
expect(user.get('dateField')).to.equalTime(new Date(2010, 10, 10));
});
});
it('handles dates in includes correctly #2644', function() {
return this.User.create({
projects: [
{ dateField: new Date(1990, 5, 5) }
]
}, { include: [this.Project]}).bind(this).then(function () {
return this.User.findAll({
include: [this.Project]
}).get(0);
}).then(function (user) {
expect(user.projects[0].get('dateField')).to.be.an.instanceof(Date);
expect(user.projects[0].get('dateField')).to.equalTime(new Date(1990, 5, 5));
});
});
}); });
describe('regression tests', function() { describe('regression tests', function() {
...@@ -46,4 +84,4 @@ if (dialect === 'sqlite') { ...@@ -46,4 +84,4 @@ if (dialect === 'sqlite') {
}); });
}); });
}); });
} }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!