mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-13 14:39:52 +03:00
b2659d0cbb
refs #6301 Fixtures: - Removed all the old (and now broken) 003 fixture upgrades - Split the 004 fixture upgrade tasks out, each into their own file - Improved the versioning code that figured out which upgrades we should do - Added lots of test coverage to make sure all the fixtures are still being run correctly. Permissions fixtures: - Changed the code that was populating permissions fixtures to be more automated & based only on what is in the permissions.json file. - Added lots of test coverage to make sure all the permissions are still being created correctly. Merging the two things: - Merged the content of permissions.json and fixtures.json into fixtures.json, but using the new structure from permissions.json. - Changed to use the new automated model & relation creation for all fixtures, not just permissions. - The only thing that can't be auto-populated just now is the owner creation, I think that's important enough to do separately. - There were (so far) never any permission updates, so code for updating fixtures stays the same through the merge. - This results in two clear code paths: populate (fill out a brand new DB) and update (make any changes since the last version) Test coverage is now 100% across both updates and populations.
59 lines
2.6 KiB
JavaScript
59 lines
2.6 KiB
JavaScript
/*globals describe, it, afterEach */
|
|
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
|
|
// Stuff we are testing
|
|
versioning = require('../../server/data/schema').versioning,
|
|
errors = require('../../server/errors'),
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('Versioning', function () {
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('getMigrationVersions', function () {
|
|
it('should output a single item if the from and to versions are the same', function () {
|
|
should.exist(versioning.getMigrationVersions);
|
|
versioning.getMigrationVersions('003', '003').should.eql(['003']);
|
|
versioning.getMigrationVersions('004', '004').should.eql(['004']);
|
|
});
|
|
|
|
it('should output an empty array if the toVersion is higher than the fromVersion', function () {
|
|
versioning.getMigrationVersions('003', '002').should.eql([]);
|
|
});
|
|
|
|
it('should output all the versions between two versions', function () {
|
|
versioning.getMigrationVersions('003', '004').should.eql(['003', '004']);
|
|
versioning.getMigrationVersions('003', '005').should.eql(['003', '004', '005']);
|
|
versioning.getMigrationVersions('003', '006').should.eql(['003', '004', '005', '006']);
|
|
versioning.getMigrationVersions('010', '011').should.eql(['010', '011']);
|
|
});
|
|
});
|
|
|
|
describe('getDefaultDatabaseVersion', function () {
|
|
it('should return the correct version', function () {
|
|
var currentVersion = require('../../server/data/schema').defaultSettings.core.databaseVersion.defaultValue;
|
|
// This function has an internal cache, so we call it twice.
|
|
// First, to check that it fetches the correct version from default-settings.json.
|
|
versioning.getDefaultDatabaseVersion().should.eql(currentVersion);
|
|
// Second, to check that it returns the same value from the cache.
|
|
versioning.getDefaultDatabaseVersion().should.eql(currentVersion);
|
|
});
|
|
});
|
|
|
|
describe('showCannotMigrateError', function () {
|
|
it('should output a detailed error message', function () {
|
|
var errorStub = sandbox.stub(errors, 'logAndRejectError');
|
|
versioning.showCannotMigrateError();
|
|
errorStub.calledOnce.should.be.true();
|
|
errorStub.calledWith(
|
|
'Unable to upgrade from version 0.4.2 or earlier',
|
|
'Please upgrade to 0.7.1 first',
|
|
'See http://support.ghost.org/how-to-upgrade/ for instructions.'
|
|
).should.be.true();
|
|
});
|
|
});
|
|
});
|