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

Commit 01d5f0f4 by Sushant Committed by Jan Aagaard Meier

(refactor-tests) removing old referencesKey use

1 parent efc54f4f
...@@ -1212,7 +1212,6 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -1212,7 +1212,6 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
}); });
describe('findOne', function() { describe('findOne', function() {
([ true, false ]).forEach(function (useNewReferencesStyle) {
it('should work with schemas', function() { it('should work with schemas', function() {
var self = this; var self = this;
var UserModel = this.sequelize.define('User', { var UserModel = this.sequelize.define('User', {
...@@ -1235,10 +1234,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -1235,10 +1234,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
timestamps: false timestamps: false
}); });
var UserIdColumn = useNewReferencesStyle var UserIdColumn = { type: Sequelize.INTEGER, references: { model: UserModel, key: 'Id' } };
? { type: Sequelize.INTEGER, references: UserModel, referencesKey: 'Id' }
: { type: Sequelize.INTEGER, references: { model: UserModel, key: 'Id' } }
;
var ResumeModel = this.sequelize.define('Resume', { var ResumeModel = this.sequelize.define('Resume', {
Id: { Id: {
...@@ -1285,6 +1281,5 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -1285,6 +1281,5 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
}); });
}); });
}); });
});
}); });
}); });
...@@ -2316,12 +2316,8 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2316,12 +2316,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
([ true, false ]).forEach(function (useNewReferencesStyle) {
it('uses an existing dao factory and references the author table', function() { it('uses an existing dao factory and references the author table', function() {
var authorIdColumn = useNewReferencesStyle var authorIdColumn = { type: Sequelize.INTEGER, references: { model: this.Author, key: 'id' } };
? { type: Sequelize.INTEGER, references: this.Author, referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: this.Author, key: 'id' } }
;
var Post = this.sequelize.define('post', { var Post = this.sequelize.define('post', {
title: Sequelize.STRING, title: Sequelize.STRING,
...@@ -2348,10 +2344,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2348,10 +2344,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('uses a table name as a string and references the author table', function() { it('uses a table name as a string and references the author table', function() {
var authorIdColumn = useNewReferencesStyle var authorIdColumn = { type: Sequelize.INTEGER, references: { model: 'authors', key: 'id' } };
? { type: Sequelize.INTEGER, references: 'authors', referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: 'authors', key: 'id' } }
;
var self = this var self = this
, Post = self.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn }); , Post = self.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn });
...@@ -2376,10 +2369,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2376,10 +2369,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
it('emits an error event as the referenced table name is invalid', function() { it('emits an error event as the referenced table name is invalid', function() {
var authorIdColumn = useNewReferencesStyle var authorIdColumn = { type: Sequelize.INTEGER, references: { model: '4uth0r5', key: 'id' } };
? { type: Sequelize.INTEGER, references: '4uth0r5', referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: '4uth0r5', key: 'id' } }
;
var Post = this.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn }); var Post = this.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn });
...@@ -2426,19 +2416,13 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2426,19 +2416,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
comment: 'asdf' comment: 'asdf'
}; };
if (useNewReferencesStyle) { idColumn.references = { model: Member, key: 'id' };
idColumn.references = { model: Member, key: 'id' };
} else {
idColumn.references = Member;
idColumn.referencesKey = 'id';
}
var Profile = this.sequelize.define('Profile', { id: idColumn }); var Profile = this.sequelize.define('Profile', { id: idColumn });
// jshint ignore:end // jshint ignore:end
return this.sequelize.sync({ force: true }); return this.sequelize.sync({ force: true });
}); });
});
}); });
describe('blob', function() { describe('blob', function() {
......
...@@ -47,29 +47,7 @@ if (Support.dialectIsMySQL()) { ...@@ -47,29 +47,7 @@ if (Support.dialectIsMySQL()) {
arguments: [{id: {type: 'INTEGER', after: 'Bar'}}], arguments: [{id: {type: 'INTEGER', after: 'Bar'}}],
expectation: {id: 'INTEGER AFTER `Bar`'} expectation: {id: 'INTEGER AFTER `Bar`'}
}, },
// Old references style
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`pk`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, autoIncrement: true, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL auto_increment DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'}
},
// New references style // New references style
{ {
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}], arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
...@@ -48,55 +48,6 @@ if (dialect.match(/^postgres/)) { ...@@ -48,55 +48,6 @@ if (dialect.match(/^postgres/)) {
expectation: {id: 'INTEGER UNIQUE'} expectation: {id: 'INTEGER UNIQUE'}
}, },
// Old references style
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}
},
// Variants when quoteIdentifiers is false
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES Bar (pk)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
},
// New references style // New references style
{ {
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}], arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
...@@ -58,28 +58,6 @@ if (dialect === 'sqlite') { ...@@ -58,28 +58,6 @@ if (dialect === 'sqlite') {
expectation: {id: 'INTEGER UNIQUE'} expectation: {id: 'INTEGER UNIQUE'}
}, },
// Old references style
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`pk`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'}
},
// New references style // New references style
{ {
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}], arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
...@@ -456,21 +456,4 @@ suite(Support.getTestDialectTeaser('Utils'), function() { ...@@ -456,21 +456,4 @@ suite(Support.getTestDialectTeaser('Utils'), function() {
expect(stack[3].getFunctionName()).to.eql('this_here_test'); expect(stack[3].getFunctionName()).to.eql('this_here_test');
}); });
}); });
suite('formatReferences', function () {
([
[{referencesKey: 1}, {references: {model: undefined, key: 1, deferrable: undefined}, referencesKey: undefined, referencesDeferrable: undefined}],
[{references: 'a'}, {references: {model: 'a', key: undefined, deferrable: undefined}, referencesKey: undefined, referencesDeferrable: undefined}],
[{references: 'a', referencesKey: 1}, {references: {model: 'a', key: 1, deferrable: undefined}, referencesKey: undefined, referencesDeferrable: undefined}],
[{references: {model: 1}}, {references: {model: 1}}],
[{references: 1, referencesKey: 2, referencesDeferrable: 3}, {references: {model: 1, key: 2, deferrable: 3}, referencesKey: undefined, referencesDeferrable: undefined}]
]).forEach(function (test) {
var input = test[0];
var output = test[1];
it(JSON.stringify(input) + ' to ' + JSON.stringify(output), function () {
expect(Utils.formatReferences(input)).to.deep.equal(output);
});
});
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!