0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Model & test cleanup

This commit is contained in:
Hannah Wolfe 2014-07-19 14:17:56 +01:00
parent 94fca08500
commit 5a6af020c5
2 changed files with 54 additions and 54 deletions

View file

@ -180,7 +180,7 @@ Post = ghostBookshelf.Model.extend({
}, },
tags: function () { tags: function () {
return this.belongsToMany(Tag); return this.belongsToMany('Tag');
}, },
fields: function () { fields: function () {

View file

@ -46,59 +46,59 @@ describe('Tag Model', function () {
describe('a Post', function () { describe('a Post', function () {
var PostModel = Models.Post; var PostModel = Models.Post;
// it('can add a tag', function (done) { it('can add a tag', function (done) {
// var newPost = testUtils.DataGenerator.forModel.posts[0], var newPost = testUtils.DataGenerator.forModel.posts[0],
// newTag = testUtils.DataGenerator.forModel.tags[0], newTag = testUtils.DataGenerator.forModel.tags[0],
// createdPostID; createdPostID;
//
// when.all([ when.all([
// PostModel.add(newPost, context), PostModel.add(newPost, context),
// TagModel.add(newTag, context) TagModel.add(newTag, context)
// ]).then(function (models) { ]).then(function (models) {
// var createdPost = models[0], var createdPost = models[0],
// createdTag = models[1]; createdTag = models[1];
//
// createdPostID = createdPost.id; createdPostID = createdPost.id;
// return createdPost.tags().attach(createdTag); return createdPost.tags().attach(createdTag);
// }).then(function () { }).then(function () {
// return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']}); return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']});
// }).then(function (postWithTag) { }).then(function (postWithTag) {
// postWithTag.related('tags').length.should.equal(1); postWithTag.related('tags').length.should.equal(1);
// done(); done();
// }).catch(done); }).catch(done);
//
// }); });
//
// it('can remove a tag', function (done) { it('can remove a tag', function (done) {
// // The majority of this test is ripped from above, which is obviously a Bad Thing. // The majority of this test is ripped from above, which is obviously a Bad Thing.
// // Would be nice to find a way to seed data with relations for cases like this, // Would be nice to find a way to seed data with relations for cases like this,
// // because there are more DB hits than needed // because there are more DB hits than needed
// var newPost = testUtils.DataGenerator.forModel.posts[0], var newPost = testUtils.DataGenerator.forModel.posts[0],
// newTag = testUtils.DataGenerator.forModel.tags[0], newTag = testUtils.DataGenerator.forModel.tags[0],
// createdTagID, createdTagID,
// createdPostID; createdPostID;
//
// when.all([ when.all([
// PostModel.add(newPost, context), PostModel.add(newPost, context),
// TagModel.add(newTag, context) TagModel.add(newTag, context)
// ]).then(function (models) { ]).then(function (models) {
// var createdPost = models[0], var createdPost = models[0],
// createdTag = models[1]; createdTag = models[1];
//
// createdPostID = createdPost.id; createdPostID = createdPost.id;
// createdTagID = createdTag.id; createdTagID = createdTag.id;
// return createdPost.tags().attach(createdTag); return createdPost.tags().attach(createdTag);
// }).then(function () { }).then(function () {
// return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']}); return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']});
// }).then(function (postWithTag) { }).then(function (postWithTag) {
// return postWithTag.tags().detach(createdTagID); return postWithTag.tags().detach(createdTagID);
// }).then(function () { }).then(function () {
// return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']}); return PostModel.findOne({id: createdPostID, status: 'all'}, { withRelated: ['tags']});
// }).then(function (postWithoutTag) { }).then(function (postWithoutTag) {
// postWithoutTag.related('tags').length.should.equal(0); postWithoutTag.related('tags').length.should.equal(0);
// done(); done();
// }).catch(done); }).catch(done);
// }); });
describe('setting tags from an array on update', function () { describe('setting tags from an array on update', function () {
// When a Post is updated, iterate through the existing tags, and detach any that have since been removed. // When a Post is updated, iterate through the existing tags, and detach any that have since been removed.