Test improvement, shows _targetClass camelCase bug
There is an issue where setting _targetClass on hasAndBelongsToMany relations with a camel-case model name, fails. Signed-off-by: Khashayar Hajian <me@khashayar.me>
This commit is contained in:
parent
f9ce6c248d
commit
28a661a81a
|
@ -1604,15 +1604,15 @@ describe('relations', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hasAndBelongsToMany', function () {
|
describe('hasAndBelongsToMany', function () {
|
||||||
var Article, Tag, ArticleTag;
|
var Article, TagName, ArticleTag;
|
||||||
it('can be declared', function (done) {
|
it('can be declared', function (done) {
|
||||||
Article = db.define('Article', {title: String});
|
Article = db.define('Article', {title: String});
|
||||||
Tag = db.define('Tag', {name: String});
|
TagName = db.define('TagName', {name: String});
|
||||||
Article.hasAndBelongsToMany('tags');
|
Article.hasAndBelongsToMany('tagNames');
|
||||||
ArticleTag = db.models.ArticleTag;
|
ArticleTag = db.models.ArticleTagName;
|
||||||
db.automigrate(function () {
|
db.automigrate(function () {
|
||||||
Article.destroyAll(function () {
|
Article.destroyAll(function () {
|
||||||
Tag.destroyAll(function () {
|
TagName.destroyAll(function () {
|
||||||
ArticleTag.destroyAll(done)
|
ArticleTag.destroyAll(done)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1621,11 +1621,11 @@ describe('relations', function () {
|
||||||
|
|
||||||
it('should allow to create instances on scope', function (done) {
|
it('should allow to create instances on scope', function (done) {
|
||||||
Article.create(function (e, article) {
|
Article.create(function (e, article) {
|
||||||
article.tags.create({name: 'popular'}, function (e, t) {
|
article.tagNames.create({name: 'popular'}, function (e, t) {
|
||||||
t.should.be.an.instanceOf(Tag);
|
t.should.be.an.instanceOf(TagName);
|
||||||
ArticleTag.findOne(function (e, at) {
|
ArticleTag.findOne(function (e, at) {
|
||||||
should.exist(at);
|
should.exist(at);
|
||||||
at.tagId.toString().should.equal(t.id.toString());
|
at.tagNameId.toString().should.equal(t.id.toString());
|
||||||
at.articleId.toString().should.equal(article.id.toString());
|
at.articleId.toString().should.equal(article.id.toString());
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1635,7 +1635,7 @@ describe('relations', function () {
|
||||||
|
|
||||||
it('should allow to fetch scoped instances', function (done) {
|
it('should allow to fetch scoped instances', function (done) {
|
||||||
Article.findOne(function (e, article) {
|
Article.findOne(function (e, article) {
|
||||||
article.tags(function (e, tags) {
|
article.tagNames(function (e, tags) {
|
||||||
should.not.exist(e);
|
should.not.exist(e);
|
||||||
should.exist(tags);
|
should.exist(tags);
|
||||||
done();
|
done();
|
||||||
|
@ -1645,12 +1645,12 @@ describe('relations', function () {
|
||||||
|
|
||||||
it('should allow to add connection with instance', function (done) {
|
it('should allow to add connection with instance', function (done) {
|
||||||
Article.findOne(function (e, article) {
|
Article.findOne(function (e, article) {
|
||||||
Tag.create({name: 'awesome'}, function (e, tag) {
|
TagName.create({name: 'awesome'}, function (e, tag) {
|
||||||
article.tags.add(tag, function (e, at) {
|
article.tagNames.add(tag, function (e, at) {
|
||||||
should.not.exist(e);
|
should.not.exist(e);
|
||||||
should.exist(at);
|
should.exist(at);
|
||||||
at.should.be.an.instanceOf(ArticleTag);
|
at.should.be.an.instanceOf(ArticleTag);
|
||||||
at.tagId.should.equal(tag.id);
|
at.tagNameId.should.equal(tag.id);
|
||||||
at.articleId.should.equal(article.id);
|
at.articleId.should.equal(article.id);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1660,12 +1660,12 @@ describe('relations', function () {
|
||||||
|
|
||||||
it('should allow to remove connection with instance', function (done) {
|
it('should allow to remove connection with instance', function (done) {
|
||||||
Article.findOne(function (e, article) {
|
Article.findOne(function (e, article) {
|
||||||
article.tags(function (e, tags) {
|
article.tagNames(function (e, tags) {
|
||||||
var len = tags.length;
|
var len = tags.length;
|
||||||
tags.should.not.be.empty;
|
tags.should.not.be.empty;
|
||||||
article.tags.remove(tags[0], function (e) {
|
article.tagNames.remove(tags[0], function (e) {
|
||||||
should.not.exist(e);
|
should.not.exist(e);
|
||||||
article.tags(true, function (e, tags) {
|
article.tagNames(true, function (e, tags) {
|
||||||
tags.should.have.lengthOf(len - 1);
|
tags.should.have.lengthOf(len - 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1675,7 +1675,7 @@ describe('relations', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set targetClass on scope property', function() {
|
it('should set targetClass on scope property', function() {
|
||||||
should.equal(Article.prototype.tags._targetClass, 'Tag');
|
should.equal(Article.prototype.tagNames._targetClass, 'TagName');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue