mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
|
var should = require('should'),
|
||
|
sinon = require('sinon'),
|
||
|
rewire = require('rewire'),
|
||
|
configUtils = require('../../utils/configUtils'),
|
||
|
rssCache = rewire('../../../server/data/xml/rss/cache'),
|
||
|
|
||
|
sandbox = sinon.sandbox.create();
|
||
|
|
||
|
describe('RSS: Cache', function () {
|
||
|
var generateSpy, generateFeedReset;
|
||
|
|
||
|
afterEach(function () {
|
||
|
configUtils.restore();
|
||
|
sandbox.restore();
|
||
|
generateFeedReset();
|
||
|
});
|
||
|
|
||
|
beforeEach(function () {
|
||
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
||
|
|
||
|
generateSpy = sandbox.spy(rssCache.__get__('generateFeed'));
|
||
|
generateFeedReset = rssCache.__set__('generateFeed', generateSpy);
|
||
|
});
|
||
|
|
||
|
it('should not rebuild xml for same data and url', function (done) {
|
||
|
var xmlData1,
|
||
|
data = {
|
||
|
title: 'Test Title',
|
||
|
description: 'Testing Desc',
|
||
|
permalinks: '/:slug/',
|
||
|
results: {posts: [], meta: {pagination: {pages: 1}}}
|
||
|
};
|
||
|
|
||
|
rssCache.getXML('/rss/', data)
|
||
|
.then(function (_xmlData) {
|
||
|
xmlData1 = _xmlData;
|
||
|
|
||
|
// We should have called generateFeed
|
||
|
generateSpy.callCount.should.eql(1);
|
||
|
|
||
|
// Call RSS again to check that we didn't rebuild
|
||
|
return rssCache.getXML('/rss/', data);
|
||
|
})
|
||
|
.then(function (xmlData2) {
|
||
|
// Assertions
|
||
|
|
||
|
// We should not have called generateFeed again
|
||
|
generateSpy.callCount.should.eql(1);
|
||
|
|
||
|
// The data should be identical, no changing lastBuildDate
|
||
|
xmlData1.should.equal(xmlData2);
|
||
|
|
||
|
done();
|
||
|
})
|
||
|
.catch(done);
|
||
|
});
|
||
|
});
|