Skip to content

Commit

Permalink
closes #101 - data model updates
Browse files Browse the repository at this point in the history
Further changes to the data model to ensure created_by, author_id and updated_by are all set to user 1
Updated settings such that the default type is always 'general', and changed the types in the fixtures to be slightly more useful
Added additional assertions to tests to cover more assumptions about data
  • Loading branch information
ErisDS committed Jun 17, 2013
1 parent 316985f commit d15f1f8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
16 changes: 8 additions & 8 deletions core/shared/data/fixtures/001.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions core/shared/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
return {
uuid: uuid.v4(),
status: 'draft'
// TODO: language: ghost.config().defaultLang);
};
},

Expand All @@ -43,15 +44,22 @@
this.set('published_by', 1);
}

this.set('updated_by', 1);
// refactoring of ghost required in order to make these details available here
// this.set('language', this.get('language') || ghost.config().defaultLang);
// this.set('status', this.get('status') || ghost.statuses().draft);
},

creating: function () {
if (!this.get('slug')) {
this.generateSlug();
}

if (!this.get('created_by')) {
this.set('created_by', 1);
}

if (!this.get('author_id')) {
this.set('author_id', 1);
}
},

generateSlug: function () {
Expand Down
3 changes: 2 additions & 1 deletion core/shared/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
hasTimestamps: true,
defaults: function () {
return {
uuid: uuid.v4()
uuid: uuid.v4(),
type: 'general'
};
}
}, {
Expand Down
22 changes: 18 additions & 4 deletions core/test/ghost/api_posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@
});

it('can add, defaulting as a draft', function (done) {
var newPost = {
title: 'Test Title 1',
content: 'Test Content 1'
};
var createdPostUpdatedDate,
newPost = {
title: 'Test Title 1',
content: 'Test Content 1'
};

PostModel.add(newPost).then(function (createdPost) {
return new PostModel({id: createdPost.id}).fetch();
Expand All @@ -78,12 +79,25 @@
createdPost.get('title').should.equal(newPost.title, "title is correct");
createdPost.get('content').should.equal(newPost.content, "content is correct");
createdPost.get('slug').should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct');
//createdPost.get('created_at').should.be.instanceOf(Date); - why is this not true?
createdPost.get('created_by').should.equal(1);
createdPost.get('author_id').should.equal(1);
createdPost.get('created_by').should.equal(createdPost.get('author_id'));
//createdPost.get('updated_at').should.be.instanceOf(Date); - why is this not true?
createdPost.get('updated_by').should.equal(1);
should.equal(createdPost.get('published_at'), null);
should.equal(createdPost.get('published_by'), null);

createdPostUpdatedDate = createdPost.get('updated_at');

// Set the status to published to check that `published_at` is set.
return createdPost.save({status: 'published'});
}).then(function (publishedPost) {
publishedPost.get('published_at').should.be.instanceOf(Date);
publishedPost.get('published_by').should.equal(1);
publishedPost.get('updated_at').should.be.instanceOf(Date);
publishedPost.get('updated_by').should.equal(1);
publishedPost.get('updated_at').should.not.equal(createdPostUpdatedDate);

done();
}).then(null, done);
Expand Down
1 change: 1 addition & 0 deletions core/test/ghost/api_settings_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
createdSetting.has('uuid').should.equal(true);
createdSetting.attributes.key.should.equal(newSetting.key, "key is correct");
createdSetting.attributes.value.should.equal(newSetting.value, "value is correct");
createdSetting.attributes.type.should.equal("general");

done();
}).then(null, done);
Expand Down

0 comments on commit d15f1f8

Please sign in to comment.