Skip to content

Commit

Permalink
Merge pull request TryGhost#1650 from hswolff/issue-1644
Browse files Browse the repository at this point in the history
Fix loading of static pages in frontend controller
  • Loading branch information
ErisDS committed Dec 10, 2013
2 parents 119af63 + 9bbf400 commit c1683e5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/server/controllers/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ frontendControllers = {
if (post) {
filters.doFilter('prePostsRender', post).then(function (post) {
api.settings.read('activeTheme').then(function (activeTheme) {
var paths = config.paths().availableThemes[activeTheme];
var paths = config.paths().availableThemes[activeTheme.value];
if (post.page && paths.hasOwnProperty('page')) {
res.render('page', {post: post});
} else {
Expand Down
18 changes: 16 additions & 2 deletions core/test/functional/api/posts_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var testUtils = require('../../utils'),
_ = require('underscore'),
request = require('request');

request = request.defaults({jar:true})
request = request.defaults({jar:true});

describe('Post API', function () {

Expand Down Expand Up @@ -55,13 +55,27 @@ describe('Post API', function () {
});

it('can retrieve a post', function (done) {
request.get(testUtils.API.getApiURL('posts/1/'), function (error, response, body) {
request.get(testUtils.API.getApiURL('posts/5/'), function (error, response, body) {
response.should.have.status(200);
should.not.exist(response.headers['x-cache-invalidate']);
response.should.be.json;
var jsonResponse = JSON.parse(body);
jsonResponse.should.exist;
testUtils.API.checkResponse(jsonResponse, 'post');
jsonResponse.page.should.eql(0);
done();
});
});

it('can retrieve a static page', function (done) {
request.get(testUtils.API.getApiURL('posts/6/'), function (error, response, body) {
response.should.have.status(200);
should.not.exist(response.headers['x-cache-invalidate']);
response.should.be.json;
var jsonResponse = JSON.parse(body);
jsonResponse.should.exist;
testUtils.API.checkResponse(jsonResponse, 'post');
jsonResponse.page.should.eql(1);
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions core/test/integration/model/model_posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var testUtils = require('../../utils'),
sequence = require('when/sequence'),

// Stuff we are testing
DataGenerator = require('../../utils/fixtures/data-generator'),
Models = require('../../../server/models');

describe('Post Model', function () {
Expand Down
109 changes: 108 additions & 1 deletion core/test/unit/frontend_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,120 @@
/*globals describe, beforeEach, afterEach, it*/
var should = require('should'),
var assert = require('assert'),
should = require('should'),
sinon = require('sinon'),
when = require('when'),

// Stuff we are testing
config = require('../../server/config'),
api = require('../../server/api'),
frontend = require('../../server/controllers/frontend');

describe('Frontend Controller', function () {

var ghost,
sandbox,
apiStub;

beforeEach(function () {
sandbox = sinon.sandbox.create();
});

afterEach(function () {
sandbox.restore();
});


describe('homepage', function () {
// No tests yet, shows up in coverage report
});

describe('single', function() {
var mockStaticPost = {
'status': 'published',
'id': 1,
'title': 'Test static page',
'slug': 'test-static-page',
'markdown': 'Test static page content',
'page': 1
};

var mockPost = {
'status': 'published',
'id': 2,
'title': 'Test normal post',
'slug': 'test-normal-post',
'markdown': 'The test normal post content',
'page': 0
};

beforeEach(function () {
apiStub = sandbox.stub(api.posts , 'read', function (args) {
return when(args.id === 1 ? mockStaticPost : mockPost);
});

sandbox.stub(api.settings , 'read', function () {
return when({
'key': 'activeTheme',
'value': 'casper'
});
});

sandbox.stub(config , 'paths', function () {
return {
'availableThemes': {
'casper': {
'assets': null,
'default': '/content/themes/casper/default.hbs',
'index': '/content/themes/casper/index.hbs',
'page': '/content/themes/casper/page.hbs',
'post': '/content/themes/casper/post.hbs'
}
}
};
});
});

it('can render a static page', function(done) {
var req = {
params: {
'id': 1,
'slug': 'test-static-page'
}
};

var res = {
render: function(view, context) {
assert.equal(view, 'page');
assert(context.post, 'Context object has post attribute');
assert.equal(context.post, mockStaticPost);
done();
}
};

frontend.single(req, res, null);

});

it('can render a normal post', function(done) {
var req = {
params: {
'id': 2,
'slug': 'test-normal-post'
}
};

var res = {
render: function(view, context) {
assert.equal(view, 'post');
assert(context.post, 'Context object has post attribute');
assert.equal(context.post, mockPost);
done();
}
};

frontend.single(req, res, null);

});

});
});
13 changes: 10 additions & 3 deletions core/test/utils/fixtures/data-generator.js

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

0 comments on commit c1683e5

Please sign in to comment.