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

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() {
});
describe('findOne', function() {
([ true, false ]).forEach(function (useNewReferencesStyle) {
it('should work with schemas', function() {
var self = this;
var UserModel = this.sequelize.define('User', {
......@@ -1235,10 +1234,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
timestamps: false
});
var UserIdColumn = useNewReferencesStyle
? { type: Sequelize.INTEGER, references: UserModel, referencesKey: 'Id' }
: { type: Sequelize.INTEGER, references: { model: UserModel, key: 'Id' } }
;
var UserIdColumn = { type: Sequelize.INTEGER, references: { model: UserModel, key: 'Id' } };
var ResumeModel = this.sequelize.define('Resume', {
Id: {
......@@ -1286,5 +1282,4 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), 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() {
var authorIdColumn = useNewReferencesStyle
? { type: Sequelize.INTEGER, references: this.Author, referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: this.Author, key: 'id' } }
;
var authorIdColumn = { type: Sequelize.INTEGER, references: { model: this.Author, key: 'id' } };
var Post = this.sequelize.define('post', {
title: Sequelize.STRING,
......@@ -2348,10 +2344,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it('uses a table name as a string and references the author table', function() {
var authorIdColumn = useNewReferencesStyle
? { type: Sequelize.INTEGER, references: 'authors', referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: 'authors', key: 'id' } }
;
var authorIdColumn = { type: Sequelize.INTEGER, references: { model: 'authors', key: 'id' } };
var self = this
, Post = self.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn });
......@@ -2376,10 +2369,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it('emits an error event as the referenced table name is invalid', function() {
var authorIdColumn = useNewReferencesStyle
? { type: Sequelize.INTEGER, references: '4uth0r5', referencesKey: 'id' }
: { type: Sequelize.INTEGER, references: { model: '4uth0r5', key: 'id' } }
;
var authorIdColumn = { type: Sequelize.INTEGER, references: { model: '4uth0r5', key: 'id' } };
var Post = this.sequelize.define('post', { title: Sequelize.STRING, authorId: authorIdColumn });
......@@ -2426,12 +2416,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
comment: 'asdf'
};
if (useNewReferencesStyle) {
idColumn.references = { model: Member, key: 'id' };
} else {
idColumn.references = Member;
idColumn.referencesKey = 'id';
}
var Profile = this.sequelize.define('Profile', { id: idColumn });
// jshint ignore:end
......@@ -2439,7 +2424,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({ force: true });
});
});
});
describe('blob', function() {
beforeEach(function() {
......
......@@ -48,28 +48,6 @@ if (Support.dialectIsMySQL()) {
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
{
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
......@@ -48,55 +48,6 @@ if (dialect.match(/^postgres/)) {
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
{
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
......@@ -58,28 +58,6 @@ if (dialect === 'sqlite') {
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
{
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
......@@ -456,21 +456,4 @@ suite(Support.getTestDialectTeaser('Utils'), function() {
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!