From d81d408eaba62b533649a941f3ac7b8490844b4a Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Wed, 29 May 2013 13:26:08 -0500 Subject: [PATCH] Fix Travis Errors - affects #91 - Move dataProvider initialization outside constructor - Add travis sqlite config that enables debug - Add grunt-cli installation to travis before_script --- .travis.yml | 4 ++- app.js | 2 +- config.js | 8 +++++ core/shared/models/dataProvider.bookshelf.js | 37 +++++++++++++------- core/test/ghost/helpers.js | 4 +-- package.json | 1 - 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a0fa81e6a..0c1e73e9cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,6 @@ node_js: - "0.10" - "0.8" git: - submodules: false \ No newline at end of file + submodules: false +before_script: + - npm install -g grunt-cli \ No newline at end of file diff --git a/app.js b/app.js index c7c2719d2f..02709deebc 100755 --- a/app.js +++ b/app.js @@ -94,7 +94,7 @@ // Expose the promise we will resolve after our pre-loading ghost.loaded = loading.promise; - when.all([filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(ghost)]).then(function () { + when.all([ghost.dataProvider().init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(ghost)]).then(function () { /** * API routes.. diff --git a/config.js b/config.js index 2e2896d913..7792c4a6f6 100644 --- a/config.js +++ b/config.js @@ -63,6 +63,14 @@ } }, + travis: { + client: 'sqlite3', + connection: { + filename: './core/shared/data/tests.db' + }, + debug: true + }, + development: { client: 'sqlite3', connection: { diff --git a/core/shared/models/dataProvider.bookshelf.js b/core/shared/models/dataProvider.bookshelf.js index a4130fcaa4..8923e59dd0 100644 --- a/core/shared/models/dataProvider.bookshelf.js +++ b/core/shared/models/dataProvider.bookshelf.js @@ -6,31 +6,44 @@ (function () { "use strict"; - var knex = require('./knex_init'), + var _ = require('underscore'), + knex = require('./knex_init'), PostsProvider = require('./dataProvider.bookshelf.posts'), UsersProvider = require('./dataProvider.bookshelf.users'), SettingsProvider = require('./dataProvider.bookshelf.settings'), DataProvider, - instance; + instance, + defaultOptions = { + autoInit: false + }; + + DataProvider = function (options) { + options = _.defaults(options || {}, defaultOptions); - DataProvider = function () { if (!instance) { instance = this; - knex.Schema.hasTable('posts').then(null, function () { - // Simple bootstraping of the data model for now. - var migration = require('../data/migration/001'); - return migration.down().then(function () { - return migration.up(); - }); - }).then(function () { - console.log('all done....'); - }); + if (options.autoInit) { + this.init(); + } } return instance; }; + DataProvider.prototype.init = function () { + return knex.Schema.hasTable('posts').then(null, function () { + // Simple bootstraping of the data model for now. + var migration = require('../data/migration/001'); + + return migration.down().then(function () { + return migration.up(); + }); + }).then(function () { + console.log('DataProvider ready'); + }); + }; + DataProvider.prototype.posts = new PostsProvider(); DataProvider.prototype.users = new UsersProvider(); DataProvider.prototype.settings = new SettingsProvider(); diff --git a/core/test/ghost/helpers.js b/core/test/ghost/helpers.js index 3a87bc97cc..11557800eb 100644 --- a/core/test/ghost/helpers.js +++ b/core/test/ghost/helpers.js @@ -1,8 +1,8 @@ (function () { "use strict"; - // Use 'testing' Ghost config - process.env.NODE_ENV = 'testing'; + // Use 'testing' Ghost config; unless we are running on travis (then show queries for debugging) + process.env.NODE_ENV = process.env.TRAVIS ? 'travis' : 'testing'; var knex = require('knex'), migrations = { diff --git a/package.json b/package.json index 54a2841d17..bcda4c9063 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ }, "devDependencies": { "grunt": "~0.4.1", - "grunt-cli": "0.1.9", "grunt-jslint": "0.2.x", "should": "~1.2.2", "grunt-mocha-test": "~0.4.0",