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

Commit 2210ce44 by Jan Aagaard Meier

Updating tests to fit new naming scheme

1 parent 87a2540c
......@@ -25,6 +25,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Create a composite primary key for doubled linked self reference [#1891](https://github.com/sequelize/sequelize/issues/1891)
- [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead.
- [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
#### Backwards compatability changes
......
......@@ -48,7 +48,7 @@ module.exports = (function() {
this.options.useHooks = options.useHooks;
// Get singular name, trying to uppercase the first letter, unless the model forbids it
var singular = this.__getSingularName(true);
var singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = {
get: 'get' + singular,
......@@ -144,8 +144,5 @@ module.exports = (function() {
return this;
};
BelongsTo.prototype.__getSingularName = Helpers.__getSingularName;
BelongsTo.prototype.__getPluralName = Helpers.__getPluralName;
return BelongsTo;
})();
......@@ -142,13 +142,13 @@ module.exports = (function() {
};
}
} else {
this.as = this.target.options.name.singular;
this.as = this.target.options.name.plural;
this.options.name = this.target.options.name;
}
// Get singular and plural names, trying to uppercase the first letter, unless the model forbids it
var plural = this.__getPluralName(true)
, singular = this.__getSingularName(true);
var plural = Utils.uppercaseFirst(this.options.name.plural)
, singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = {
get: 'get' + plural,
......@@ -200,7 +200,7 @@ module.exports = (function() {
if (this.isSelfAssociation && this.foreignIdentifier === this.identifier) {
this.foreignIdentifier = Utils._.camelizeIf(
[this.__getSingularName(), this.source.primaryKeyAttribute].join('_'),
[this.options.name.singular, this.source.primaryKeyAttribute].join('_'),
!this.source.options.underscored
);
......@@ -478,9 +478,6 @@ module.exports = (function() {
return this;
};
HasMany.prototype.__getSingularName = Helpers.__getSingularName;
HasMany.prototype.__getPluralName = Helpers.__getPluralName;
/**
* The method checks if it is ok to delete the previously defined foreign key.
* This is done because we need to keep the foreign key if another association
......
......@@ -48,7 +48,7 @@ module.exports = (function() {
this.options.useHooks = options.useHooks;
// Get singular name, trying to uppercase the first letter, unless the model forbids it
var singular = this.__getSingularName(true);
var singular = Utils.uppercaseFirst(this.options.name.singular);
this.accessors = {
get: 'get' + singular,
......@@ -152,8 +152,5 @@ module.exports = (function() {
return this;
};
HasOne.prototype.__getSingularName = Helpers.__getSingularName;
HasOne.prototype.__getPluralName = Helpers.__getPluralName;
return HasOne;
})();
......@@ -3,18 +3,6 @@
var Utils = require('./../utils');
module.exports = {
__getSingularName: function (tryUppercase) {
return !this.options.name.verbatim && tryUppercase ?
Utils.uppercaseFirst(this.options.name.singular) :
this.options.name.singular ;
},
__getPluralName: function (tryUppercase) {
return !this.options.name.verbatim && tryUppercase ?
Utils.uppercaseFirst(this.options.name.plural) :
this.options.name.plural ;
},
checkNamingCollision: function (association) {
if (association.source.rawAttributes.hasOwnProperty(association.as)) {
throw new Error("Naming collision between attribute '" + association.as + "' and association '" + association.as + "' on model " + association.source.name + '. To remedy this, change either foreignKey or as in your association definition');
......
......@@ -228,7 +228,7 @@ Mixin.belongsTo = singleLinked(BelongsTo);
* @param {object} [options]
* @param {boolean} [options.hooks=false] Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks
* @param {Model|string} [options.through] The name of the table that is used to join source and target in n:m associations. Can also be a sequelize model if you want to define the junction table yourself and add extra attributes to it.
* @param {string|object} [options.as] The alias of this model. If you provide a string, it should be plural, and will be singularized using node.inflection. If you want to control the singular version yourself, provide an object with `plural` and `singular` keys, and optionally a `verbatim` key (to control whethet the first letter of the name should be upper cased in getter / setter methods). See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the pluralized name of target
* @param {string|object} [options.as] The alias of this model. If you provide a string, it should be plural, and will be singularized using node.inflection. If you want to control the singular version yourself, provide an object with `plural` and `singular` keys. See also the `name` option passed to `sequelize.define`. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the pluralized name of target
* @param {string|object} [options.foreignKey] The name of the foreign key in the target table / join table or an object representing the type definition for the foreign column (see `Sequelize.define` for syntax). Defaults to the name of source + primary key of source
* @param {string} [options.onDelete='SET NULL|CASCADE'] Cascade if this is a n:m, and set null if it is a 1:m
* @param {string} [options.onUpdate='CASCADE']
......
......@@ -1224,12 +1224,13 @@ module.exports = (function() {
var association = dao.associations[key]
, associationName;
if (association.associationType === 'BelongsTo') {
associationName = Utils.singularize(association.associationAccessor[0].toLowerCase() + association.associationAccessor.slice(1));
} else {
associationName = association.accessors.get.replace('get', '');
associationName = associationName[0].toLowerCase() + associationName.slice(1);
}
// if (association.associationType === 'BelongsTo') {
// associationName = Utils.singularize(association.associationAccessor[0].toLowerCase() + association.associationAccessor.slice(1));
// } else {
// associationName = association.accessors.get.replace('get', '');
// associationName = associationName[0].toLowerCase() + associationName.slice(1);
// }
associationName = association.as;
if (associationName === attribute) {
associationToReturn = association;
......
......@@ -376,7 +376,7 @@ module.exports = (function() {
var indexTable = tableName.split('.');
options = Utils._.extend({
indicesType: null,
indexName: Utils._.underscored(indexTable[indexTable.length - 1] + '_' + onlyAttributeNames.join('_')),
indexName: Utils.inflection.underscore(indexTable[indexTable.length - 1] + '_' + onlyAttributeNames.join('_')),
parser: null
}, options || {});
......@@ -397,7 +397,7 @@ module.exports = (function() {
, indexName = indexNameOrAttributes;
if (typeof indexName !== 'string') {
indexName = Utils._.underscored(tableName + '_' + indexNameOrAttributes.join('_'));
indexName = Utils.inflection.underscore(tableName + '_' + indexNameOrAttributes.join('_'));
}
return Utils._.template(sql)({
......
......@@ -67,11 +67,11 @@ module.exports = (function() {
if (length && length.index < modifierLastIndex) {
dataType = dataType.replace(length[0], '');
// Since the legnth was placed before the modifier, removing the legnth has changed the index
// Since the legnth was placed before the modifier, removing the length has changed the index
if (length.index < modifierLastIndex) {
modifierLastIndex -= length[0].length;
}
dataType = Utils._.insert(dataType, modifierLastIndex, length[0]).trim();
dataType = Utils.spliceStr(dataType, modifierLastIndex, 0, length[0]).trim();
}
modifierLastIndex = -1;
......@@ -315,7 +315,7 @@ module.exports = (function() {
, indexName = indexNameOrAttributes;
if (typeof indexName !== 'string') {
indexName = Utils._.underscored(tableName + '_' + indexNameOrAttributes.join('_'));
indexName = Utils.inflection.underscore(tableName + '_' + indexNameOrAttributes.join('_'));
}
return Utils._.template(sql, { tableName: this.quoteIdentifiers(tableName), indexName: indexName });
......
......@@ -368,7 +368,7 @@ module.exports = (function() {
var include = this.options.includeMap[key]
, association = include.association
, self = this
, accessor = Utils.camelize(key, true)
, accessor = key
, childOptions
, primaryKeyAttribute = include.model.primaryKeyAttribute
, isEmpty;
......@@ -386,16 +386,12 @@ module.exports = (function() {
};
}
if (include.originalAttributes === undefined || include.originalAttributes.length) {
// downcase the first char
accessor = accessor.slice(0, 1).toLowerCase() + accessor.slice(1);
if (association.isSingleAssociation) {
if (Array.isArray(value)) {
value = value[0];
}
isEmpty = value && value[primaryKeyAttribute] === null;
accessor = Utils.singularize(accessor);
self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.model.build(value, childOptions);
} else {
isEmpty = value[0] && value[0][primaryKeyAttribute] === null;
......
......@@ -1715,9 +1715,7 @@ module.exports = (function() {
include.hasParentRequired = options.hasParentRequired || !!options.required;
options.includeMap[include.as] = include;
options.includeMap[include.as.substr(0, 1).toLowerCase() + include.as.substr(1)] = include;
options.includeNames.push(include.as);
options.includeNames.push(include.as.substr(0, 1).toLowerCase() + include.as.substr(1));
if (include.association.isMultiAssociation || include.hasMultiAssociation) {
options.hasMultiAssociation = true;
......
......@@ -348,10 +348,9 @@ module.exports = (function() {
* @param {Boolean} [options.underscoredAll=false] Converts camelCased model names to underscored tablenames if true
* @param {Boolean} [options.freezeTableName=false] If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. Otherwise, the dao name will be pluralized
* @param {Boolean} [options.freezeAssociations=false] If freezeAssociations is true, sequelize will not try to alter the DAO name to get the table name of the associated tables. Otherwise, the dao name will be pluralized
* @param {Object} [options.name] An object with the attributes, `singular`, `plural`, and `verbatim`, that are used when this model is associated to others.
* @param {Object} [options.name] An object with two attributes, `singular` and `plural`, which are used when this model is associated to others.
* @param {String} [options.name.singular=inflection.singularize(modelName)]
* @param {String} [options.name.plural=inflection.pluralize(modelName)]
* @param {Boolean} [options.name.verbatim=false] Controls whether the names should always be used verbatim, i.e. no upper- / lower casing applied. If false, the first letter will be upper cased for getter / setter methods such as `getTasks` and `addTask`
* @param {String|Boolean} [options.createdAt] Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true
* @param {String|Boolean} [options.updatedAt] Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true
* @param {String|Boolean} [options.deletedAt] Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true
......@@ -388,8 +387,7 @@ module.exports = (function() {
options = Utils._.merge({
name: {
plural: Utils.inflection.pluralize(modelName),
singular: Utils.inflection.singularize(modelName),
verbatim: false
singular: Utils.inflection.singularize(modelName)
}
}, options);
......
......@@ -63,6 +63,9 @@ var Utils = module.exports = {
uppercaseFirst: function (s) {
return s[0].toUpperCase() + s.slice(1);
},
spliceStr: function (str, index, count, add) {
return str.slice(0, index) + add + str.slice(index + count);
},
camelize: function(str){
return str.trim().replace(/[-_\s]+(.)?/g, function(match, c){ return c.toUpperCase(); });
},
......
......@@ -45,6 +45,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.Label.belongsTo(this.Article);
this.Article.hasMany(this.Label);
expect(Object.keys(this.Label.rawAttributes)).to.deep.equal([ 'id', 'text', 'ArticleId' ]);
expect(Object.keys(this.Label.rawAttributes).length).to.equal(3);
});
......@@ -839,7 +840,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
it("get associated objects with an eager load", function() {
return this.User.find({where: {username: 'John'}, include: [ this.Task ]}).then(function (john) {
expect(john.tasks).to.have.length(2);
expect(john.Tasks).to.have.length(2);
});
});
......@@ -860,7 +861,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
]
});
}).then(function (john) {
expect(john.tasks).to.have.length(2);
expect(john.Tasks).to.have.length(2);
});
});
......
......@@ -481,11 +481,11 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
]
})
expect(product.tags).to.be.ok
expect(product.tags.length).to.equal(2)
expect(product.tags[0].Model).to.equal(Tag)
expect(product.user).to.be.ok
expect(product.user.Model).to.equal(User)
expect(product.Tags).to.be.ok
expect(product.Tags.length).to.equal(2)
expect(product.Tags[0].Model).to.equal(Tag)
expect(product.User).to.be.ok
expect(product.User.Model).to.equal(User)
})
it('should support includes with aliases', function () {
......@@ -500,9 +500,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
last_name: Sequelize.STRING
})
Product.hasMany(Tag, {as: 'Categories'})
Product.hasMany(User, {as: 'Followers', through: 'product_followers'})
User.hasMany(Product, {as: 'Following', through: 'product_followers'})
Product.hasMany(Tag, {as: 'categories'})
Product.hasMany(User, {as: 'followers', through: 'product_followers'})
User.hasMany(Product, {as: 'following', through: 'product_followers'})
var product = Product.build({
id: 1,
......@@ -1174,11 +1174,11 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
it('supports distinct option', function(done) {
var Post = this.sequelize.define('Post',{})
var PostComment = this.sequelize.define('PostComment',{})
Post.hasMany(PostComment)
Post.hasMany(PostComment)
Post.sync({ force: true }).success(function() {
PostComment.sync({ force: true }).success(function() {
Post.create({}).success(function(post){
......@@ -1195,7 +1195,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
describe('min', function() {
......
......@@ -350,8 +350,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, task) {
expect(err).to.be.null
expect(task).to.exist
expect(task.worker).to.exist
expect(task.worker.name).to.equal('worker')
expect(task.Worker).to.exist
expect(task.Worker.name).to.equal('worker')
done()
})
})
......@@ -382,10 +382,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, environment) {
expect(err).to.be.null
expect(environment).to.exist
expect(environment.privateDomain).to.exist
expect(environment.privateDomain.ip).to.equal('192.168.0.1')
expect(environment.publicDomain).to.exist
expect(environment.publicDomain.ip).to.equal('91.65.189.19')
expect(environment.PrivateDomain).to.exist
expect(environment.PrivateDomain.ip).to.equal('192.168.0.1')
expect(environment.PublicDomain).to.exist
expect(environment.PublicDomain.ip).to.equal('91.65.189.19')
done()
})
})
......@@ -415,7 +415,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.sequelize.sync({ force: true }).success(function() {
self.Group.create({ name: 'people' }).success(function() {
self.User.create({ username: 'someone', GroupPKeagerbelongName: 'people' }).success(function() {
self.User.create({ username: 'someone', GroupPKeagerbelongName: 'people' }).success(function() {
self.User.find({
where: {
username: 'someone'
......@@ -425,7 +425,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(err).to.be.null
expect(someUser).to.exist
expect(someUser.username).to.equal('someone')
expect(someUser.groupPKeagerbelong.name).to.equal('people')
expect(someUser.GroupPKeagerbelong.name).to.equal('people')
done()
})
})
......@@ -465,10 +465,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(messages.length).to.equal(2);
expect(messages[0].message).to.equal('hi there!');
expect(messages[0].user.username).to.equal('test_testerson');
expect(messages[0].User.username).to.equal('test_testerson');
expect(messages[1].message).to.equal('a second message');
expect(messages[1].user.username).to.equal('test_testerson');
expect(messages[1].User.username).to.equal('test_testerson');
done()
......@@ -524,8 +524,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, worker) {
expect(err).to.be.null
expect(worker).to.exist
expect(worker.task).to.exist
expect(worker.task.title).to.equal('homework')
expect(worker.Task).to.exist
expect(worker.Task.title).to.equal('homework')
done()
})
})
......@@ -558,7 +558,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(err).to.be.null
expect(someGroup).to.exist
expect(someGroup.name).to.equal('people')
expect(someGroup.userPKeagerone.username).to.equal('someone')
expect(someGroup.UserPKeagerone.username).to.equal('someone')
done()
})
})
......@@ -602,8 +602,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, worker) {
expect(err).to.be.null
expect(worker).to.exist
expect(worker.toDo).to.exist
expect(worker.toDo.title).to.equal('homework')
expect(worker.ToDo).to.exist
expect(worker.ToDo.title).to.equal('homework')
done()
})
})
......@@ -613,7 +613,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDo' } ]
}).complete(function(err, worker) {
expect(worker.toDo.title).to.equal('homework')
expect(worker.ToDo.title).to.equal('homework')
done()
})
})
......@@ -663,8 +663,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, worker) {
expect(err).to.be.null
expect(worker).to.exist
expect(worker.tasks).to.exist
expect(worker.tasks[0].title).to.equal('homework')
expect(worker.Tasks).to.exist
expect(worker.Tasks[0].title).to.equal('homework')
done()
})
})
......@@ -695,8 +695,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function (err, fetchedContact) {
expect(err).to.be.null
expect(fetchedContact).to.exist
expect(fetchedContact.photos.length).to.equal(1)
expect(fetchedContact.phoneNumbers.length).to.equal(2)
expect(fetchedContact.Photos.length).to.equal(1)
expect(fetchedContact.PhoneNumbers.length).to.equal(2)
done()
})
})
......@@ -739,7 +739,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(err).to.be.null
expect(someUser).to.exist
expect(someUser.username).to.equal('someone')
expect(someUser.groupPKeagerones[0].name).to.equal('people')
expect(someUser.GroupPKeagerones[0].name).to.equal('people')
done()
})
})
......@@ -784,8 +784,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, worker) {
expect(err).to.be.null
expect(worker).to.exist
expect(worker.toDos).to.exist
expect(worker.toDos[0].title).to.equal('homework')
expect(worker.ToDos).to.exist
expect(worker.ToDos[0].title).to.equal('homework')
done()
})
})
......@@ -795,7 +795,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDos' } ]
}).complete(function(err, worker) {
expect(worker.toDos[0].title).to.equal('homework')
expect(worker.ToDos[0].title).to.equal('homework')
done()
})
})
......@@ -830,8 +830,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it('returns the associated models when using through as string and alias', function (done) {
var self = this
this.Product.hasMany(this.Tag, {as: 'Tags', through: 'product_tag'})
this.Tag.hasMany(this.Product, {as: 'Products', through: 'product_tag'})
this.Product.hasMany(this.Tag, {as: 'tags', through: 'product_tag'})
this.Tag.hasMany(this.Product, {as: 'products', through: 'product_tag'})
this.sequelize.sync().done(function () {
async.auto({
......@@ -890,7 +890,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
id: tags[0].id
},
include: [
{model: self.Product, as: 'Products'}
{model: self.Product, as: 'products'}
]
}).done(function (err, tag) {
expect(tag).to.exist
......@@ -910,7 +910,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
id: products[0].id
},
include: [
{model: self.Tag, as: 'Tags'}
{model: self.Tag, as: 'tags'}
]
}).done(function (err, product) {
expect(product).to.exist
......
......@@ -598,8 +598,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, tasks) {
expect(err).to.be.null
expect(tasks).to.exist
expect(tasks[0].worker).to.exist
expect(tasks[0].worker.name).to.equal('worker')
expect(tasks[0].Worker).to.exist
expect(tasks[0].Worker.name).to.equal('worker')
done()
})
})
......@@ -642,8 +642,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, workers) {
expect(err).to.be.null
expect(workers).to.exist
expect(workers[0].taskHasOne).to.exist
expect(workers[0].taskHasOne.title).to.equal('homework')
expect(workers[0].TaskHasOne).to.exist
expect(workers[0].TaskHasOne.title).to.equal('homework')
done()
})
})
......@@ -695,8 +695,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, workers) {
expect(err).to.be.null
expect(workers).to.exist
expect(workers[0].toDo).to.exist
expect(workers[0].toDo.title).to.equal('homework')
expect(workers[0].ToDo).to.exist
expect(workers[0].ToDo.title).to.equal('homework')
done()
})
})
......@@ -706,7 +706,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDo' } ]
}).complete(function(err, workers) {
expect(workers[0].toDo.title).to.equal('homework')
expect(workers[0].ToDo.title).to.equal('homework')
done()
})
})
......@@ -715,8 +715,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
describe('hasMany', function() {
beforeEach(function(done) {
var self = this
self.Task = self.sequelize.define('Task', { title: Sequelize.STRING })
self.Worker = self.sequelize.define('Worker', { name: Sequelize.STRING })
self.Task = self.sequelize.define('task', { title: Sequelize.STRING })
self.Worker = self.sequelize.define('worker', { name: Sequelize.STRING })
self.Worker.hasMany(self.Task)
self.Worker.sync({ force: true }).success(function() {
......@@ -739,7 +739,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var self = this
expect(function() {
self.Task.findAll({ include: [ self.Worker ] })
}).to.throw(Error, 'Worker is not associated to Task!')
}).to.throw(Error, 'worker is not associated to task!')
done()
})
......@@ -803,8 +803,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).complete(function(err, workers) {
expect(err).to.be.null
expect(workers).to.exist
expect(workers[0].toDos).to.exist
expect(workers[0].toDos[0].title).to.equal('homework')
expect(workers[0].ToDos).to.exist
expect(workers[0].ToDos[0].title).to.equal('homework')
done()
})
})
......@@ -814,7 +814,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDos' } ]
}).complete(function(err, workers) {
expect(workers[0].toDos[0].title).to.equal('homework')
expect(workers[0].ToDos[0].title).to.equal('homework')
done()
})
})
......@@ -865,10 +865,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
beforeEach(function(done) {
var self = this
self.Continent = this.sequelize.define('Continent', { name: Sequelize.STRING })
self.Country = this.sequelize.define('Country', { name: Sequelize.STRING })
self.Industry = this.sequelize.define('Industry', { name: Sequelize.STRING })
self.Person = this.sequelize.define('Person', { name: Sequelize.STRING, lastName: Sequelize.STRING })
self.Continent = this.sequelize.define('continent', { name: Sequelize.STRING })
self.Country = this.sequelize.define('country', { name: Sequelize.STRING })
self.Industry = this.sequelize.define('industry', { name: Sequelize.STRING })
self.Person = this.sequelize.define('person', { name: Sequelize.STRING, lastName: Sequelize.STRING })
self.Continent.hasMany(self.Country)
self.Country.belongsTo(self.Continent)
......@@ -876,7 +876,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.Industry.hasMany(self.Country)
self.Country.hasMany(self.Person)
self.Person.belongsTo(self.Country)
self.Country.hasMany(self.Person, { as: 'Residents', foreignKey: 'CountryResidentId' })
self.Country.hasMany(self.Person, { as: 'residents', foreignKey: 'CountryResidentId' })
self.Person.belongsTo(self.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' })
this.sequelize.sync({ force: true }).success(function () {
......@@ -982,15 +982,15 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
beforeEach(function(done) {
var self = this
self.Continent = this.sequelize.define('Continent', { name: Sequelize.STRING })
self.Country = this.sequelize.define('Country', { name: Sequelize.STRING })
self.Person = this.sequelize.define('Person', { name: Sequelize.STRING, lastName: Sequelize.STRING })
self.Continent = this.sequelize.define('continent', { name: Sequelize.STRING })
self.Country = this.sequelize.define('country', { name: Sequelize.STRING })
self.Person = this.sequelize.define('person', { name: Sequelize.STRING, lastName: Sequelize.STRING })
self.Continent.hasMany(self.Country)
self.Country.belongsTo(self.Continent)
self.Country.hasMany(self.Person)
self.Person.belongsTo(self.Country)
self.Country.hasMany(self.Person, { as: 'Residents', foreignKey: 'CountryResidentId' })
self.Country.hasMany(self.Person, { as: 'residents', foreignKey: 'CountryResidentId' })
self.Person.belongsTo(self.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' })
this.sequelize.sync({ force: true }).success(function () {
......@@ -1093,8 +1093,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var self = this
async.forEach([ [ 'ASC', 'Europe', 'France', 'Fred' ], [ 'DESC', 'Europe', 'England', 'Kim' ] ], function(params, callback) {
self.Continent.findAll({
include: [ { model: self.Country, include: [ self.Person, {model: self.Person, as: 'Residents' } ] } ],
order: [ [ self.Country, {model: self.Person, as: 'Residents' }, 'lastName', params[0] ] ]
include: [ { model: self.Country, include: [ self.Person, {model: self.Person, as: 'residents' } ] } ],
order: [ [ self.Country, {model: self.Person, as: 'residents' }, 'lastName', params[0] ] ]
}).done(function(err, continents) {
expect(err).not.to.be.ok
expect(continents).to.exist
......@@ -1115,8 +1115,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var self = this
async.forEach([ [ 'ASC', 'Europe', 'France', 'Fred' ], [ 'DESC', 'Europe', 'England', 'Kim' ] ], function(params, callback) {
self.Continent.findAll({
include: [ { model: self.Country, include: [ self.Person, {model: self.Person, as: 'Residents' } ] } ],
order: [ [ { model: self.Country }, {model: self.Person, as: 'Residents' }, 'lastName', params[0] ] ],
include: [ { model: self.Country, include: [ self.Person, {model: self.Person, as: 'residents' } ] } ],
order: [ [ { model: self.Country }, {model: self.Person, as: 'residents' }, 'lastName', params[0] ] ],
limit: 3
}).done(function(err, continents) {
expect(err).not.to.be.ok
......@@ -1139,8 +1139,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
beforeEach(function(done) {
var self = this
self.Country = this.sequelize.define('Country', { name: Sequelize.STRING })
self.Industry = this.sequelize.define('Industry', { name: Sequelize.STRING })
self.Country = this.sequelize.define('country', { name: Sequelize.STRING })
self.Industry = this.sequelize.define('industry', { name: Sequelize.STRING })
self.IndustryCountry = this.sequelize.define('IndustryCountry', { numYears: Sequelize.INTEGER })
self.Country.hasMany(self.Industry, {through: self.IndustryCountry})
......
......@@ -629,17 +629,17 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
Page.create({ content: 'om nom nom' }).success(function(page) {
book.setPages([ page ]).success(function() {
Book.find({
where: (dialect === 'postgres' ? '"Book"."id"=' : '`Book`.`id`=') + book.id,
where: { id : book.id },
include: [Page]
}).success(function(leBook) {
page.updateAttributes({ content: 'something totally different' }).success(function(page) {
expect(leBook.pages.length).to.equal(1)
expect(leBook.pages[0].content).to.equal('om nom nom')
expect(leBook.Pages.length).to.equal(1)
expect(leBook.Pages[0].content).to.equal('om nom nom')
expect(page.content).to.equal('something totally different')
leBook.reload().success(function(leBook) {
expect(leBook.pages.length).to.equal(1)
expect(leBook.pages[0].content).to.equal('something totally different')
expect(leBook.Pages.length).to.equal(1)
expect(leBook.Pages[0].content).to.equal('something totally different')
expect(page.content).to.equal('something totally different')
done()
})
......@@ -853,7 +853,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
var self = this
return this.User.create({ username: 'user' }).then(function (user) {
var updatedAt = user.updatedAt
return new self.sequelize.Promise(function (resolve) {
setTimeout(function () {
user.updateAttributes({
......@@ -865,7 +865,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
resolve()
})
}, 2000)
}, 2000)
})
})
})
......@@ -1030,8 +1030,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
self.UserEager.find({where: {age: 1}, include: [{model: self.ProjectEager, as: 'Projects'}]}).success(function(user) {
expect(user.username).to.equal('joe')
expect(user.age).to.equal(1)
expect(user.projects).to.exist
expect(user.projects.length).to.equal(2)
expect(user.Projects).to.exist
expect(user.Projects.length).to.equal(2)
user.age = user.age + 1 // happy birthday joe
......@@ -1040,8 +1040,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect(user.username).to.equal('joe')
expect(user.age).to.equal(2)
expect(user.projects).to.exist
expect(user.projects.length).to.equal(2)
expect(user.Projects).to.exist
expect(user.Projects.length).to.equal(2)
done()
})
})
......@@ -1069,10 +1069,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
_bart = simpsons[0]
_lisa = simpsons[1]
expect(_bart.projects).to.exist
expect(_lisa.projects).to.exist
expect(_bart.projects.length).to.equal(2)
expect(_lisa.projects.length).to.equal(2)
expect(_bart.Projects).to.exist
expect(_lisa.Projects).to.exist
expect(_bart.Projects.length).to.equal(2)
expect(_lisa.Projects.length).to.equal(2)
_bart.age = _bart.age + 1 // happy birthday bart - off to Moe's
......@@ -1108,10 +1108,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
user.setProjects([homework, party]).success(function() {
self.ProjectEager.findAll({include: [{model: self.UserEager, as: 'Poobah'}]}).success(function(projects) {
expect(projects.length).to.equal(2)
expect(projects[0].poobah).to.exist
expect(projects[1].poobah).to.exist
expect(projects[0].poobah.username).to.equal('poobah')
expect(projects[1].poobah.username).to.equal('poobah')
expect(projects[0].Poobah).to.exist
expect(projects[1].Poobah).to.exist
expect(projects[0].Poobah.username).to.equal('poobah')
expect(projects[1].Poobah.username).to.equal('poobah')
projects[0].title = 'partymore'
projects[1].title = 'partymore'
......@@ -1123,10 +1123,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
self.ProjectEager.findAll({where: {title: 'partymore', overdue_days: 0}, include: [{model: self.UserEager, as: 'Poobah'}]}).success(function(savedprojects) {
expect(savedprojects.length).to.equal(2)
expect(savedprojects[0].poobah).to.exist
expect(savedprojects[1].poobah).to.exist
expect(savedprojects[0].poobah.username).to.equal('poobah')
expect(savedprojects[1].poobah.username).to.equal('poobah')
expect(savedprojects[0].Poobah).to.exist
expect(savedprojects[1].Poobah).to.exist
expect(savedprojects[0].Poobah.username).to.equal('poobah')
expect(savedprojects[1].Poobah.username).to.equal('poobah')
done()
})
......
......@@ -141,13 +141,13 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
describe('includes', function () {
it('should support basic includes', function () {
var Product = this.sequelize.define('Product', {
var Product = this.sequelize.define('product', {
title: Sequelize.STRING
})
var Tag = this.sequelize.define('Tag', {
var Tag = this.sequelize.define('tag', {
name: Sequelize.STRING
})
var User = this.sequelize.define('User', {
var User = this.sequelize.define('user', {
first_name: Sequelize.STRING,
last_name: Sequelize.STRING
})
......@@ -188,10 +188,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
var Product = this.sequelize.define('Product', {
title: Sequelize.STRING
})
var Tag = this.sequelize.define('Tag', {
var Tag = this.sequelize.define('tag', {
name: Sequelize.STRING
})
var User = this.sequelize.define('User', {
var User = this.sequelize.define('user', {
first_name: Sequelize.STRING,
last_name: Sequelize.STRING
})
......
......@@ -93,8 +93,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
}).done(function (err, task) {
expect(err).not.to.be.ok
expect(task.user).to.be.ok
expect(task.user.group).to.be.ok
expect(task.User).to.be.ok
expect(task.User.Group).to.be.ok
done()
})
})
......@@ -186,8 +186,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
}).done(function (err, group) {
expect(err).not.to.be.ok
expect(group.user).to.be.ok
expect(group.user.task).to.be.ok
expect(group.User).to.be.ok
expect(group.User.task).to.be.ok
done()
})
})
......@@ -237,11 +237,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
}).done(function (err, user) {
expect(err).not.to.be.ok
expect(user.tasks).to.be.ok
expect(user.tasks.length).to.equal(4)
expect(user.Tasks).to.be.ok
expect(user.Tasks.length).to.equal(4)
user.tasks.forEach(function (task) {
expect(task.project).to.be.ok
expect(task.Project).to.be.ok
})
done()
......@@ -294,9 +294,9 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
}).done(function (err, worker) {
expect(err).not.to.be.ok
expect(worker.project).to.be.ok
expect(worker.project.tasks).to.be.ok
expect(worker.project.tasks.length).to.equal(4)
expect(worker.Project).to.be.ok
expect(worker.Project.tasks).to.be.ok
expect(worker.Project.tasks.length).to.equal(4)
done()
})
......@@ -372,11 +372,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}).done(function (err, user) {
expect(err).not.to.be.ok
expect(user.products.length).to.equal(4)
expect(user.products[0].tags.length).to.equal(2)
expect(user.products[1].tags.length).to.equal(1)
expect(user.products[2].tags.length).to.equal(3)
expect(user.products[3].tags.length).to.equal(0)
expect(user.Products.length).to.equal(4)
expect(user.Products[0].tags.length).to.equal(2)
expect(user.Products[1].tags.length).to.equal(1)
expect(user.Products[2].tags.length).to.equal(3)
expect(user.Products[3].tags.length).to.equal(0)
done()
})
})
......@@ -514,22 +514,22 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]}
]
}).done(function (err, user) {
user.memberships.sort(sortById)
expect(user.memberships.length).to.equal(2)
expect(user.memberships[0].group.name).to.equal('Developers')
expect(user.memberships[0].rank.canRemove).to.equal(1)
expect(user.memberships[1].group.name).to.equal('Designers')
expect(user.memberships[1].rank.canRemove).to.equal(0)
user.products.sort(sortById)
expect(user.products.length).to.equal(2)
expect(user.products[0].tags.length).to.equal(2)
expect(user.products[1].tags.length).to.equal(1)
expect(user.products[0].category).to.be.ok
expect(user.products[1].category).not.to.be.ok
expect(user.products[0].prices.length).to.equal(2)
expect(user.products[1].prices.length).to.equal(4)
user.Memberships.sort(sortById)
expect(user.Memberships.length).to.equal(2)
expect(user.Memberships[0].group.name).to.equal('Developers')
expect(user.Memberships[0].rank.canRemove).to.equal(1)
expect(user.Memberships[1].group.name).to.equal('Designers')
expect(user.Memberships[1].rank.canRemove).to.equal(0)
user.Products.sort(sortById)
expect(user.Products.length).to.equal(2)
expect(user.Products[0].tags.length).to.equal(2)
expect(user.Products[1].tags.length).to.equal(1)
expect(user.Products[0].category).to.be.ok
expect(user.Products[1].category).not.to.be.ok
expect(user.Products[0].prices.length).to.equal(2)
expect(user.Products[1].prices.length).to.equal(4)
done()
})
......@@ -564,10 +564,10 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}).done(function(err, tasks) {
expect(err).not.to.be.ok
expect(tasks[0].title).to.equal('FooBar')
expect(tasks[0].project.title).to.equal('BarFoo');
expect(tasks[0].Project.title).to.equal('BarFoo');
expect(_.omit(tasks[0].get(), 'project')).to.deep.equal({ title: 'FooBar' })
expect(tasks[0].project.get()).to.deep.equal({ title: 'BarFoo'})
expect(tasks[0].Project.get()).to.deep.equal({ title: 'BarFoo'})
done()
})
......@@ -583,7 +583,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
someProperty: Sequelize.VIRTUAL, // Since we specify the AS part as a part of the literal string, not with sequelize syntax, we have to tell sequelize about the field
comment_title: Sequelize.STRING
});
Post.hasMany(PostComment);
return this.sequelize.sync({ force: true }).then(function () {
......@@ -606,9 +606,9 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
})
}).then(function (posts) {
expect(posts[0].postComments[0].get('someProperty')).to.be.ok;
expect(posts[0].postComments[0].get('someProperty2')).to.be.ok;
expect(posts[0].postComments[0].get('commentTitle')).to.equal('WAT');
expect(posts[0].PostComments[0].get('someProperty')).to.be.ok;
expect(posts[0].PostComments[0].get('someProperty2')).to.be.ok;
expect(posts[0].PostComments[0].get('commentTitle')).to.equal('WAT');
});
});
......@@ -638,7 +638,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
include: [{model: Group, as: 'OutsourcingCompanies'}]
}).done(function (err, group) {
expect(err).not.to.be.ok
expect(group.outsourcingCompanies.length).to.equal(3)
expect(group.OutsourcingCompanies.length).to.equal(3)
done()
})
})
......@@ -665,12 +665,12 @@ describe(Support.getTestDialectTeaser("Include"), function () {
User.find({
where: {
id: user.id
},
},
include: [Group]
}).success(function (user) {
expect(user.dateField.getTime()).to.equal(Date.UTC(2014, 1, 20))
expect(user.groups[0].dateField.getTime()).to.equal(Date.UTC(2014, 1, 20))
done()
})
})
......@@ -713,8 +713,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}]
}).success(function (groups) {
expect(groups.length).to.equal(1)
expect(groups[0].members[0].name).to.equal('Member')
expect(groups[0].Members[0].name).to.equal('Member')
done()
})
})
......@@ -771,11 +771,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect(err).not.to.be.ok
expect(result.length).to.eql(1)
expect(result[0].item.test).to.eql('def')
expect(result[0].Item.test).to.eql('def')
done()
})
})
})
})
})
it('should support Sequelize.or()', function (done) {
......@@ -826,7 +826,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
done()
})
})
})
})
})
})
......@@ -876,11 +876,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect(result.count).to.eql(1)
expect(result.rows.length).to.eql(1)
expect(result.rows[0].item.test).to.eql('def')
expect(result.rows[0].Item.test).to.eql('def')
done()
})
})
})
})
})
})
})
\ No newline at end of file
})
......@@ -236,13 +236,13 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
return page
.updateAttributes({ content: 'something totally different' })
.then(function (page) {
expect(leBook.pages[0].content).to.equal('om nom nom')
expect(leBook.Pages[0].content).to.equal('om nom nom')
expect(page.content).to.equal('something totally different')
return leBook
.reload()
.then(function (leBook) {
expect(leBook.pages[0].content).to.equal('something totally different')
expect(leBook.Pages[0].content).to.equal('something totally different')
expect(page.content).to.equal('something totally different')
done()
})
......@@ -566,4 +566,4 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
})
})
});
});
\ 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!