2013-11-12 01:35:17 +04:00
|
|
|
/*globals describe, beforeEach, afterEach, it*/
|
2013-12-10 07:38:25 +04:00
|
|
|
var assert = require('assert'),
|
|
|
|
should = require('should'),
|
2013-11-12 01:35:17 +04:00
|
|
|
sinon = require('sinon'),
|
|
|
|
when = require('when'),
|
|
|
|
|
|
|
|
// Stuff we are testing
|
2013-12-10 07:38:25 +04:00
|
|
|
config = require('../../server/config'),
|
|
|
|
api = require('../../server/api'),
|
2013-11-12 01:35:17 +04:00
|
|
|
frontend = require('../../server/controllers/frontend');
|
|
|
|
|
|
|
|
describe('Frontend Controller', function () {
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
var ghost,
|
|
|
|
sandbox,
|
2013-12-30 11:03:29 +04:00
|
|
|
apiSettingsStub;
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-11-12 01:35:17 +04:00
|
|
|
describe('homepage', function () {
|
|
|
|
// No tests yet, shows up in coverage report
|
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
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 () {
|
2013-12-30 11:03:29 +04:00
|
|
|
sandbox.stub(api.posts , 'read', function (args) {
|
|
|
|
return when(args.slug === mockStaticPost.slug ? mockStaticPost : mockPost);
|
2013-12-10 07:38:25 +04:00
|
|
|
});
|
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
apiSettingsStub = sandbox.stub(api.settings , 'read');
|
|
|
|
|
|
|
|
apiSettingsStub.withArgs('activeTheme').returns(when({
|
|
|
|
'key': 'activeTheme',
|
|
|
|
'value': 'casper'
|
|
|
|
}));
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
describe('permalink set to slug', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
apiSettingsStub.withArgs('permalinks').returns(when({
|
|
|
|
value: '/:slug/'
|
|
|
|
}));
|
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
it('can render a static page', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['', 'test-static-page']
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = {
|
|
|
|
render: function(view, context) {
|
|
|
|
assert.equal(view, 'page');
|
|
|
|
assert.equal(context.post, mockStaticPost);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
frontend.single(req, res, null);
|
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
it('won\'t render a static page accessed as a date url', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['2012/12/30', 'test-static-page']
|
|
|
|
};
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
var res = {
|
|
|
|
render: sinon.spy()
|
|
|
|
};
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
frontend.single(req, res, function() {
|
|
|
|
res.render.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can render a normal post', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['', '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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('won\'t render a normal post accessed as a date url', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['2012/12/30', 'test-normal-post']
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = {
|
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
frontend.single(req, res, function() {
|
|
|
|
res.render.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('permalink set to date', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
apiSettingsStub.withArgs('permalinks').returns(when({
|
|
|
|
value: '/:year/:month/:day/:slug/'
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can render a static page', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['', 'test-static-page']
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = {
|
|
|
|
render: function(view, context) {
|
|
|
|
assert.equal(view, 'page');
|
|
|
|
assert.equal(context.post, mockStaticPost);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2013-12-30 11:03:29 +04:00
|
|
|
frontend.single(req, res, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('won\'t render a static page accessed as a date url', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['2012/12/30', 'test-static-page']
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = {
|
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
frontend.single(req, res, function() {
|
|
|
|
res.render.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can render a normal post', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['2012/12/30', '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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('won\'t render a normal post accessed as a slug url', function(done) {
|
|
|
|
var req = {
|
|
|
|
params: ['', 'test-normal-post']
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = {
|
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
frontend.single(req, res, function() {
|
|
|
|
res.render.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
});
|
2013-11-12 01:35:17 +04:00
|
|
|
});
|