From 97daa2bdec293a7b9ceac5a586b7cbd996b54620 Mon Sep 17 00:00:00 2001 From: polygonix Date: Mon, 3 Mar 2014 16:41:37 +1100 Subject: [PATCH 1/2] Detect tag.hbs template in themes closes #2320 - changed detection from "tag" to "tag.hbs" in "frontend.js" contrroller --- core/server/controllers/frontend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/server/controllers/frontend.js b/core/server/controllers/frontend.js index 90310596cd..72fb6ee3ab 100644 --- a/core/server/controllers/frontend.js +++ b/core/server/controllers/frontend.js @@ -125,7 +125,7 @@ frontendControllers = { filters.doFilter('prePostsRender', page.posts).then(function (posts) { api.settings.read('activeTheme').then(function (activeTheme) { var paths = config().paths.availableThemes[activeTheme.value], - view = paths.hasOwnProperty('tag') ? 'tag' : 'index', + view = paths.hasOwnProperty('tag.hbs') ? 'tag' : 'index', // Format data for template response = _.extend(formatPageResponse(posts, page), { From f6021210c64f2ebfc7ddf1ed30eacd25aa5747a7 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Tue, 4 Mar 2014 13:06:22 +0000 Subject: [PATCH 2/2] Add test for tag.hbs template. refs #2321 --- core/test/unit/frontend_spec.js | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/core/test/unit/frontend_spec.js b/core/test/unit/frontend_spec.js index 8823def0ba..7ad37bdde7 100644 --- a/core/test/unit/frontend_spec.js +++ b/core/test/unit/frontend_spec.js @@ -144,6 +144,106 @@ describe('Frontend Controller', function () { }); }); + describe('tag', function() { + var mockPosts = [{ + 'status': 'published', + 'id': 1, + 'title': 'Test static page', + 'slug': 'test-static-page', + 'markdown': 'Test static page content', + 'page': 1, + 'published_at': new Date('2013/12/30').getTime() + }, { + 'status': 'published', + 'id': 2, + 'title': 'Test normal post', + 'slug': 'test-normal-post', + 'markdown': 'The test normal post content', + 'page': 0, + 'published_at': new Date('2014/1/2').getTime() + }], + mockTags = [{ + 'name': 'video', + 'slug': 'video', + 'id': 1 + },{ + 'name': 'audio', + 'slug': 'audio', + 'id': 2 + }], + // Helper function to prevent unit tests + // from failing via timeout when they + // should just immediately fail + failTest = function(done, msg) { + return function() { + done(new Error(msg)); + }; + }; + + beforeEach(function () { + sandbox.stub(api.posts, 'browse', function (args) { + return when({ + posts: mockPosts, + page: 1, + pages: 1, + aspect: {tag: mockTags[0]} + }); + }); + + apiSettingsStub = sandbox.stub(api.settings, 'read'); + + apiSettingsStub.withArgs('activeTheme').returns(when({ + 'key': 'activeTheme', + 'value': 'casper' + })); + + apiSettingsStub.withArgs('postsPerPage').returns(when({ + 'key': 'postsPerPage', + 'value': '10' + })); + + frontend.__set__('config', sandbox.stub().returns({ + 'paths': { + 'subdir': '', + 'availableThemes': { + 'casper': { + 'assets': null, + 'default.hbs': '/content/themes/casper/default.hbs', + 'index.hbs': '/content/themes/casper/index.hbs', + 'page.hbs': '/content/themes/casper/page.hbs', + 'tag.hbs': '/content/themes/casper/tag.hbs' + } + } + } + })); + }); + + describe('custom tag template', function () { + + beforeEach(function () { + apiSettingsStub.withArgs('permalinks').returns(when({ + value: '/tag/:slug/' + })); + }); + + it('it will render custom tag template if it exists', function (done) { + var req = { + path: '/tag/' + mockTags[0].slug, + params: {} + }, + res = { + render: function (view, context) { + assert.equal(view, 'tag'); + assert.equal(context.tag, mockTags[0]); + done(); + } + }; + + frontend.tag(req, res, failTest(done)); + }); + }); + }); + describe('tag redirects', function () { var res;