Merge pull request #3317 from sebgie/fix-edit-posts

Fix editing author
This commit is contained in:
Hannah Wolfe 2014-07-18 11:15:41 +01:00
commit d386f66f1e
2 changed files with 15 additions and 3 deletions

View File

@ -18,6 +18,15 @@ utils = {
if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) {
return when.reject(new errors.BadRequestError('No root key (\'' + docName + '\') provided.'));
}
// convert author property to author_id to match the name in the database
// TODO: rename object in database
if (docName === 'posts') {
if (object.posts[0].hasOwnProperty('author')) {
object.posts[0].author_id = object.posts[0].author;
delete object.posts[0].author;
}
}
return when.resolve(object);
}
};

View File

@ -438,9 +438,11 @@ describe('Post API', function () {
}
var jsonResponse = res.body,
changedValue = 'My new Title';
changedTitle = 'My new Title',
changedAuthor = 2;
jsonResponse.posts[0].should.exist;
jsonResponse.posts[0].title = changedValue;
jsonResponse.posts[0].title = changedTitle;
jsonResponse.posts[0].author = changedAuthor;
request.put(testUtils.API.getApiQuery('posts/1/'))
.set('Authorization', 'Bearer ' + accesstoken)
@ -455,7 +457,8 @@ describe('Post API', function () {
var putBody = res.body;
_.has(res.headers, 'x-cache-invalidate').should.equal(true);
putBody.should.exist;
putBody.posts[0].title.should.eql(changedValue);
putBody.posts[0].title.should.eql(changedTitle);
putBody.posts[0].author.should.eql(changedAuthor);
testUtils.API.checkResponse(putBody.posts[0], 'post');
done();