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.
58 lines
2.3 KiB
JavaScript
58 lines
2.3 KiB
JavaScript
/*globals describe, it, afterEach*/
|
|
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
_ = require('lodash'),
|
|
crypto = require('crypto'),
|
|
|
|
// Stuff we are testing
|
|
schema = require('../../server/data/schema'),
|
|
fixtures = require('../../server/data/migration/fixtures'),
|
|
defaultSettings = schema.defaultSettings,
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
// To stop jshint complaining
|
|
should.equal(true, true);
|
|
|
|
describe('Migrations', function () {
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
// Check version integrity
|
|
// These tests exist to ensure that developers are not able to modify the database schema, or permissions fixtures
|
|
// without knowing that they also need to update the default database version,
|
|
// both of which are required for migrations to work properly.
|
|
describe('DB version integrity', function () {
|
|
// Only these variables should need updating
|
|
var currentDbVersion = '004',
|
|
currentSchemaHash = 'a195562bf4915e3f3f610f6d178aba01',
|
|
currentFixturesHash = '17d6aa36a6ba904adca90279eb929381';
|
|
|
|
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
|
// and the values above will need updating as confirmation
|
|
it('should not change without fixing this test', function () {
|
|
var tablesNoValidation = _.cloneDeep(schema.tables),
|
|
schemaHash,
|
|
fixturesHash;
|
|
|
|
_.each(tablesNoValidation, function (table) {
|
|
return _.each(table, function (column, name) {
|
|
table[name] = _.omit(column, 'validations');
|
|
});
|
|
});
|
|
|
|
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation)).digest('hex');
|
|
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures.fixtures)).digest('hex');
|
|
|
|
// Test!
|
|
defaultSettings.core.databaseVersion.defaultValue.should.eql(currentDbVersion);
|
|
schemaHash.should.eql(currentSchemaHash);
|
|
fixturesHash.should.eql(currentFixturesHash);
|
|
schema.versioning.canMigrateFromVersion.should.eql('003');
|
|
});
|
|
});
|
|
|
|
describe('Builder', function () {});
|
|
});
|