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

Commit 45b9990e by overlookmotel Committed by Jan Aagaard Meier

Remove uneccesary options tests (#5875)

* Remove unneccesary tests checking options object not modified

These tests are now performed universally by the tests support shim

* Tidy tests code
1 parent 25530fe3
...@@ -36,16 +36,6 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() { ...@@ -36,16 +36,6 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
}); });
}); });
it('does not modify the passed arguments', function() {
return this.User.create({}).bind(this).then(function(user) {
this.options = {};
return user.getTasks(this.options);
}).then(function() {
expect(this.options).to.deep.equal({});
});
});
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
it('supports transactions', function() { it('supports transactions', function() {
return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) { return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) {
......
...@@ -59,23 +59,6 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() { ...@@ -59,23 +59,6 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() {
}); });
} }
it('does not modify the passed arguments', function() {
var User = this.sequelize.define('user', {})
, Project = this.sequelize.define('project', {});
User.belongsTo(Project);
return this.sequelize.sync({ force: true }).bind(this).then(function() {
return User.create({});
}).then(function(user) {
this.options = {};
return user.getProject(this.options);
}).then(function() {
expect(this.options).to.deep.equal({});
});
});
it('should be able to handle a where object that\'s a first class citizen.', function() { it('should be able to handle a where object that\'s a first class citizen.', function() {
var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING, gender: Sequelize.STRING }) var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING, gender: Sequelize.STRING })
, Task = this.sequelize.define('TaskXYZ', { title: Sequelize.STRING, status: Sequelize.STRING }); , Task = this.sequelize.define('TaskXYZ', { title: Sequelize.STRING, status: Sequelize.STRING });
......
...@@ -835,16 +835,6 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -835,16 +835,6 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
}); });
}); });
it('does not modify the passed arguments', function() {
return this.User.create({}).bind(this).then(function(user) {
this.options = {};
return user.getTasks(this.options);
}).then(function() {
expect(this.options).to.deep.equal({});
});
});
it('should treat the where object of associations as a first class citizen', function() { it('should treat the where object of associations as a first class citizen', function() {
var self = this; var self = this;
this.Article = this.sequelize.define('Article', { this.Article = this.sequelize.define('Article', {
......
...@@ -60,23 +60,6 @@ describe(Support.getTestDialectTeaser('HasOne'), function() { ...@@ -60,23 +60,6 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
}); });
} }
it('does not modify the passed arguments', function() {
var User = this.sequelize.define('user', {})
, Project = this.sequelize.define('project', {});
User.hasOne(Project);
return this.sequelize.sync({ force: true }).bind(this).then(function() {
return User.create({});
}).then(function(user) {
this.options = {};
return user.getProject(this.options);
}).then(function() {
expect(this.options).to.deep.equal({});
});
});
it('should be able to handle a where object that\'s a first class citizen.', function() { it('should be able to handle a where object that\'s a first class citizen.', function() {
var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING }) var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING })
, Task = this.sequelize.define('TaskXYZ', { title: Sequelize.STRING, status: Sequelize.STRING }); , Task = this.sequelize.define('TaskXYZ', { title: Sequelize.STRING, status: Sequelize.STRING });
......
...@@ -1715,14 +1715,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1715,14 +1715,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('does not modify the passed arguments', function() {
var options = { where: ['username = ?', 'user1']};
return this.User.count(options).then(function() {
expect(options).to.deep.equal({ where: ['username = ?', 'user1']});
});
});
describe("options sent to aggregate", function () { describe("options sent to aggregate", function () {
var options, aggregateSpy; var options, aggregateSpy;
......
...@@ -107,14 +107,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -107,14 +107,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
} }
it('does not modify the passed arguments', function() {
var options = { where: ['specialkey = ?', 'awesome']};
return this.UserPrimary.findOne(options).then(function() {
expect(options).to.deep.equal({ where: ['specialkey = ?', 'awesome']});
});
});
it('treats questionmarks in an array', function() { it('treats questionmarks in an array', function() {
var test = false; var test = false;
return this.UserPrimary.findOne({ return this.UserPrimary.findOne({
......
...@@ -1110,13 +1110,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1110,13 +1110,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('does not modify the passed arguments', function() {
var options = { where: ['username = ?', 'awesome']};
return this.User.findAll(options).then(function() {
expect(options).to.deep.equal({ where: ['username = ?', 'awesome']});
});
});
it('can also handle array notation', function() { it('can also handle array notation', function() {
var self = this; var self = this;
return this.User.findAll({where: ['id = ?', this.users[1].id]}).then(function(users) { return this.User.findAll({where: ['id = ?', this.users[1].id]}).then(function(users) {
......
...@@ -251,54 +251,56 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() { ...@@ -251,54 +251,56 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
return this.sequelize.query(this.insertQuery); return this.sequelize.query(this.insertQuery);
}); });
it('executes a query with global benchmarking option and default logger', function() { describe('logging', function () {
var logger = sinon.spy(console, 'log'); it('executes a query with global benchmarking option and default logger', function() {
var sequelize = Support.createSequelizeInstance({ var logger = sinon.spy(console, 'log');
logging: logger, var sequelize = Support.createSequelizeInstance({
benchmark: true logging: logger,
}); benchmark: true
});
return sequelize.query('select 1;').then(function() { return sequelize.query('select 1;').then(function() {
expect(logger.calledOnce).to.be.true; expect(logger.calledOnce).to.be.true;
expect(logger.args[0][0]).to.be.match(/Executed \(default\): select 1; Elapsed time: \d+ms/); expect(logger.args[0][0]).to.be.match(/Executed \(default\): select 1; Elapsed time: \d+ms/);
});
}); });
});
it('executes a query with global benchmarking option and custom logger', function() { it('executes a query with global benchmarking option and custom logger', function() {
var logger = sinon.spy(); var logger = sinon.spy();
var sequelize = Support.createSequelizeInstance({ var sequelize = Support.createSequelizeInstance({
logging: logger, logging: logger,
benchmark: true benchmark: true
}); });
return sequelize.query('select 1;').then(function() { return sequelize.query('select 1;').then(function() {
expect(logger.calledOnce).to.be.true; expect(logger.calledOnce).to.be.true;
expect(logger.args[0][0]).to.be.equal('Executed (default): select 1;'); expect(logger.args[0][0]).to.be.equal('Executed (default): select 1;');
expect(typeof logger.args[0][1] === 'number').to.be.true; expect(typeof logger.args[0][1] === 'number').to.be.true;
});
}); });
});
it('executes a query with benchmarking option and default logger', function() { it('executes a query with benchmarking option and default logger', function() {
var logger = sinon.spy(console, 'log'); var logger = sinon.spy(console, 'log');
return this.sequelize.query('select 1;', { return this.sequelize.query('select 1;', {
logging: logger, logging: logger,
benchmark: true benchmark: true
}).then(function() { }).then(function() {
expect(logger.calledOnce).to.be.true; expect(logger.calledOnce).to.be.true;
expect(logger.args[0][0]).to.be.match(/Executed \(default\): select 1; Elapsed time: \d+ms/); expect(logger.args[0][0]).to.be.match(/Executed \(default\): select 1; Elapsed time: \d+ms/);
});
}); });
});
it('executes a query with benchmarking option and custom logger', function() { it('executes a query with benchmarking option and custom logger', function() {
var logger = sinon.spy(); var logger = sinon.spy();
return this.sequelize.query('select 1;', { return this.sequelize.query('select 1;', {
logging: logger, logging: logger,
benchmark: true benchmark: true
}).then(function() { }).then(function() {
expect(logger.calledOnce).to.be.true; expect(logger.calledOnce).to.be.true;
expect(logger.args[0][0]).to.be.equal('Executed (default): select 1;'); expect(logger.args[0][0]).to.be.equal('Executed (default): select 1;');
expect(typeof logger.args[0][1] === 'number').to.be.true; expect(typeof logger.args[0][1] === 'number').to.be.true;
});
}); });
}); });
......
...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.decrement(['id']); instance.decrement(['id']);
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to decrement', function () {
instance = Model.build({id: 3}, {isNewRecord: false});
var options = { by: 2 };
instance.decrement(['id'], options);
expect(options).to.deep.equal({ by: 2 });
});
}); });
}); });
}); });
...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.destroy(); instance.destroy();
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to destroy', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.destroy(options);
expect(options).to.deep.equal({ transaction: null });
});
}); });
}); });
}); });
...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.increment(['id']); instance.increment(['id']);
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to increment', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { by: 2 };
instance.increment(['id'], options);
expect(options).to.deep.equal({ by: 2 });
});
}); });
}); });
}); });
...@@ -44,14 +44,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -44,14 +44,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.reload(); instance.reload();
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to reload', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.reload(options);
expect(options).to.deep.equal({ transaction: null });
});
}); });
}); });
}); });
...@@ -44,14 +44,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -44,14 +44,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.restore(); instance.restore();
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to restore', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.restore(options);
expect(options).to.deep.equal({ transaction: null });
});
}); });
}); });
}); });
...@@ -52,13 +52,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -52,13 +52,6 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.save(); instance.save();
}).to.not.throw(); }).to.not.throw();
}); });
it('should not modify options when it given to save', function () {
instance = Model.build({});
var options = { transaction: null };
instance.save(options);
expect(options).to.deep.equal({ transaction: null });
});
}); });
}); });
}); });
...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -39,13 +39,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
this.stubDelete.restore(); this.stubDelete.restore();
}); });
it('properly clones options', function() {
var self = this;
return User.destroy(self.deloptions).bind(this).then(function(e) {
expect(self.deloptions).to.be.deep.eql(self.cloneOptions);
});
});
it('can detect complexe objects', function() { it('can detect complexe objects', function() {
var Where = function () { this.secretValue = '1'; }; var Where = function () { this.secretValue = '1'; };
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, sinon = require('sinon')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, _ = require('lodash');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findAndCountAll', function () {
var Model = current.define('model', {
name: DataTypes.STRING
}, { timestamps: false });
var Model2 = current.define('model2', {
name: DataTypes.STRING
}, { timestamps: false });
Model.hasMany(Model2);
Model2.belongsTo(Model);
before(function () {
this.stub = sinon.stub(current.getQueryInterface(), 'select', function () {
return Model.build({});
});
this.stubRaw = sinon.stub(current.getQueryInterface(), 'rawSelect', function () {
return Model.build({});
});
});
beforeEach(function () {
this.stub.reset();
this.stubRaw.reset();
});
after(function () {
this.stub.restore();
this.stubRaw.restore();
});
it('properly clones options values', function() {
var options = {
includes: [
{ model: 'model2', where: {
name: 'hello'
}}
]
};
var optionsClones = _.cloneDeep(options);
return Model.findAndCountAll(options).bind(this).then(function () {
expect(options).to.deep.equal(optionsClones);
});
});
});
});
...@@ -6,8 +6,7 @@ var chai = require('chai') ...@@ -6,8 +6,7 @@ var chai = require('chai')
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
, current = Support.sequelize , current = Support.sequelize
, sinon = require('sinon') , sinon = require('sinon')
, DataTypes = require(__dirname + '/../../../lib/data-types') , DataTypes = require(__dirname + '/../../../lib/data-types');
, _ = require('lodash');
describe(Support.getTestDialectTeaser('Model'), function() { describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findAll', function () { describe('method findAll', function () {
...@@ -89,19 +88,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -89,19 +88,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('properly clones options values', function() {
var options = {
attributes: {
exclude: ['name'],
include: ['name']
}
};
var optionsClones = _.cloneDeep(options);
return Model.findAll(options).bind(this).then(function () {
expect(options).to.deep.equal(optionsClones);
});
});
}); });
}); });
}); });
...@@ -7,8 +7,7 @@ var chai = require('chai') ...@@ -7,8 +7,7 @@ var chai = require('chai')
, current = Support.sequelize , current = Support.sequelize
, sinon = require('sinon') , sinon = require('sinon')
, DataTypes = require(__dirname + '/../../../lib/data-types') , DataTypes = require(__dirname + '/../../../lib/data-types')
, Promise = require('bluebird') , Promise = require('bluebird');
, _ = require('lodash');
describe(Support.getTestDialectTeaser('Model'), function() { describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findOne', function () { describe('method findOne', function () {
...@@ -69,15 +68,5 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -69,15 +68,5 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('properly clones options values', function() {
var options = { where: { id: { $gt: 42 }}}
, optionsClones = _.cloneDeep(options)
, Model = current.define('model');
return Model.findOne(options).bind(this).then(function () {
expect(options).to.deep.equal(optionsClones);
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!