0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Merge pull request #5421 from augbog/augbog-feature

Issue #5371 added support for GET endpoint `/tags/slug/:slug`
This commit is contained in:
Hannah Wolfe 2015-06-16 18:31:38 +01:00
commit 70e5554129
3 changed files with 47 additions and 0 deletions

View file

@ -39,6 +39,7 @@ apiRoutes = function apiRoutes(middleware) {
// ## Tags
router.get('/tags', api.http(api.tags.browse));
router.get('/tags/:id', api.http(api.tags.read));
router.get('/tags/slug/:slug', api.http(api.tags.read));
router.post('/tags', api.http(api.tags.add));
router.put('/tags/:id', api.http(api.tags.edit));
router.del('/tags/:id', api.http(api.tags.destroy));

View file

@ -177,6 +177,10 @@ describe('Tags API', function () {
});
describe('Read', function () {
function extractFirstTag(tags) {
return _.filter(tags, {id: 1})[0];
}
it('returns post_count with include post_count', function (done) {
TagAPI.read({context: {user: 1}, include: 'post_count', slug: 'kitchen-sink'}).then(function (results) {
should.exist(results);
@ -190,5 +194,22 @@ describe('Tags API', function () {
done();
}).catch(done);
});
it('with slug', function (done) {
TagAPI.browse({context: {user: 1}}).then(function (results) {
should.exist(results);
should.exist(results.tags);
results.tags.length.should.be.above(0);
var firstTag = extractFirstTag(results.tags);
return TagAPI.read({context: {user: 1}, slug: firstTag.slug});
}).then(function (found) {
should.exist(found);
testUtils.API.checkResponse(found.tags[0], 'tag');
done();
}).catch(done);
});
});
});

View file

@ -91,6 +91,31 @@ describe('Tag Model', function () {
});
});
describe('findOne', function () {
beforeEach(function (done) {
testUtils.fixtures.insertPosts().then(function () {
done();
}).catch(done);
});
it('with slug', function (done) {
var firstTag;
TagModel.findPage().then(function (results) {
should.exist(results);
should.exist(results.tags);
results.tags.length.should.be.above(0);
firstTag = results.tags[0];
return TagModel.findOne({slug: firstTag.slug});
}).then(function (found) {
should.exist(found);
done();
}).catch(done);
});
});
describe('a Post', function () {
it('can add a tag', function (done) {
var newPost = testUtils.DataGenerator.forModel.posts[0],