Merge branch 'master' into pagination

* master:
  done handler in final then, to ensure errors in last block are reported
  missing a done or two
  using grunt validate for npm test, fixing random jslint errors
  using promises correctly in tests
  adding mocha, getting npm test working
This commit is contained in:
Tim Griesser 2013-05-27 10:11:55 -04:00
commit 4d0b2ee0c4
13 changed files with 148 additions and 184 deletions

View File

@ -64,7 +64,7 @@
console.log('user found: ', user);
req.session.user = "ghostadmin";
res.redirect(req.query.redirect || '/ghost/');
}, function(err) {
}, function (err) {
// Do something here to signal the reason for an error
console.log(err.stack);
res.redirect('/ghost/login/');

View File

@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
var _ = require('underscore'),
@ -8,7 +8,7 @@
* Basic error handling helpers
*/
errors = {
throwError: function(err) {
throwError: function (err) {
if (!err) {
return;
}

View File

@ -20,12 +20,12 @@
// Simple bootstraping of the data model for now.
var migration = require('../data/migration/001');
migration.down().then(function() {
migration.up().then(function () {
return migration.down().then(function () {
return migration.up();
});
}).then(function () {
console.log('all done....');
});
});
});
}
return instance;

View File

@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
var _ = require('underscore'),

View File

@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
var _ = require('underscore'),
@ -17,7 +17,7 @@
util.inherits(SettingsProvider, BaseProvider);
SettingsProvider.prototype.read = function(_key) {
SettingsProvider.prototype.read = function (_key) {
// Allow for just passing the key instead of attributes
if (_.isString(_key)) {
_key = { key: _key };
@ -25,7 +25,7 @@
return BaseProvider.prototype.read.call(this, _key);
};
SettingsProvider.prototype.edit = function(_data) {
SettingsProvider.prototype.edit = function (_data) {
return when.all(_.map(_data, function (value, key) {
return this.model.forge({ key: key }).fetch().then(function (setting) {
return setting.set('value', value).save();

View File

@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
var util = require('util'),
@ -30,7 +30,7 @@
// Clone the _user so we don't expose the hashed password unnecessarily
userData = _.extend({}, _user);
return nodefn.call(bcrypt.hash, _user.password, 10).then(function(hash) {
return nodefn.call(bcrypt.hash, _user.password, 10).then(function (hash) {
userData.password = hash;
return BaseProvider.prototype.add.call(self, userData);
});
@ -46,7 +46,7 @@
return this.model.forge({
email_address: _userdata.email
}).fetch().then(function (user) {
return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function(matched) {
return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) {
if (!matched) {
return when.reject(new Error('Password does not match'));
}

View File

@ -29,7 +29,7 @@
DataProvider.prototype.globals.data = [];
DataProvider.prototype.globals.findAll = function() {
DataProvider.prototype.globals.findAll = function () {
return when(this.data);
};

View File

@ -26,9 +26,7 @@
results.length.should.equal(2);
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can read', function (done) {
@ -41,44 +39,38 @@
firstPost = results.models[0];
posts.read({slug: firstPost.attributes.slug}).then(function (found) {
return posts.read({slug: firstPost.attributes.slug});
}).then(function (found) {
should.exist(found);
found.attributes.title.should.equal(firstPost.attributes.title);
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can edit', function (done) {
var firstPost;
posts.browse().then(function (results) {
should.exist(results);
results.length.should.be.above(0);
firstPost = results.models[0];
posts.edit({id: firstPost.id, title: "new title"}).then(function (edited) {
return posts.edit({id: firstPost.id, title: "new title"});
}).then(function (edited) {
should.exist(edited);
edited.attributes.title.should.equal('new title');
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can add', function (done) {
@ -95,26 +87,27 @@
createdPost.attributes.slug.should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct');
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can delete', function (done) {
var firstPostId,
ids,
hasDeletedId;
var firstPostId;
posts.browse().then(function (results) {
should.exist(results);
results.length.should.be.above(0);
firstPostId = results.models[0].id;
posts.destroy(firstPostId).then(function () {
return posts.destroy(firstPostId);
posts.browse().then(function (newResults) {
}).then(function () {
return posts.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
ids = _.pluck(newResults.models, "id");
@ -125,15 +118,8 @@
hasDeletedId.should.equal(false);
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
});
}());

View File

@ -27,9 +27,7 @@
results.length.should.be.above(0);
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can read', function (done) {
@ -43,20 +41,17 @@
firstSetting = results.models[0];
settings.read(firstSetting.attributes.key).then(function (found) {
return settings.read(firstSetting.attributes.key);
}).then(function (found) {
should.exist(found);
found.attributes.value.should.equal(firstSetting.attributes.value);
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can edit single', function (done) {
@ -75,7 +70,9 @@
// key/value pairs
toEdit[firstPost.attributes.key] = "new value";
settings.edit(toEdit).then(function (edited) {
return settings.edit(toEdit);
}).then(function (edited) {
should.exist(edited);
@ -87,13 +84,8 @@
edited.attributes.value.should.equal('new value');
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can edit multiple', function (done) {
@ -116,7 +108,9 @@
toEdit[firstPost.attributes.key] = "new value1";
toEdit[secondPost.attributes.key] = "new value2";
settings.edit(toEdit).then(function (edited) {
return settings.edit(toEdit);
}).then(function (edited) {
should.exist(edited);
@ -133,12 +127,8 @@
editedPost.attributes.value.should.equal('new value2');
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can add', function (done) {
@ -155,15 +145,11 @@
createdSetting.attributes.value.should.equal(newSetting.value, "value is correct");
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can delete', function (done) {
var firstSettingId,
ids,
hasDeletedId;
var firstSettingId;
settings.browse().then(function (results) {
@ -173,9 +159,15 @@
firstSettingId = results.models[0].id;
settings.destroy(firstSettingId).then(function () {
return settings.destroy(firstSettingId);
settings.browse().then(function (newResults) {
}).then(function () {
return settings.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
ids = _.pluck(newResults.models, "id");
@ -186,15 +178,8 @@
hasDeletedId.should.equal(false);
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
});
}());

View File

@ -20,6 +20,7 @@
});
it('can browse', function (done) {
users.browse().then(function (results) {
should.exist(results);
@ -27,9 +28,8 @@
results.length.should.be.above(0);
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can read', function (done) {
@ -43,18 +43,18 @@
firstUser = results.models[0];
users.read({email_address: firstUser.attributes.email_address}).then(function (found) {
return users.read({email_address: firstUser.attributes.email_address});
}).then(function (found) {
should.exist(found);
found.attributes.username.should.equal(firstUser.attributes.username);
done();
}, function (error) {
throw error;
});
});
}).then(null, done);
});
it('can edit', function (done) {
@ -68,19 +68,17 @@
firstUser = results.models[0];
users.edit({id: firstUser.id, url: "some.newurl.com"}).then(function (edited) {
return users.edit({id: firstUser.id, url: "some.newurl.com"});
}).then(function (edited) {
should.exist(edited);
edited.attributes.url.should.equal('some.newurl.com');
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can add', function (done) {
@ -97,15 +95,11 @@
createdUser.attributes.email_address.should.eql(userData.email_address, "email address corred");
done();
}, function (error) {
throw error;
});
}).then(null, done);
});
it('can delete', function (done) {
var firstUserId,
ids,
hasDeletedId;
var firstUserId;
users.browse().then(function (results) {
@ -115,9 +109,14 @@
firstUserId = results.models[0].id;
users.destroy(firstUserId).then(function () {
return users.destroy(firstUserId);
users.browse().then(function (newResults) {
}).then(function () {
return users.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
if (newResults.length < 1) {
// Bug out if we only had one user and deleted it.
@ -133,15 +132,8 @@
hasDeletedId.should.equal(false);
done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}).then(null, done);
});
});

View File

@ -19,7 +19,7 @@
errors.throwError(toThrow);
};
runThrowError.should.throw("test1");
runThrowError.should['throw']("test1");
});
it("throws error strings", function () {
@ -28,7 +28,7 @@
errors.throwError(toThrow);
};
runThrowError.should.throw("test2");
runThrowError.should['throw']("test2");
});
it("logs errors", function () {
@ -52,7 +52,7 @@
logStub.restore();
});
it("logs promise errors with custom messages", function(done) {
it("logs promise errors with custom messages", function (done) {
var def = when.defer(),
prom = def.promise,
logStub = sinon.stub(console, "log");
@ -71,12 +71,12 @@
def.reject();
});
it("logs promise errors and redirects", function(done) {
it("logs promise errors and redirects", function (done) {
var def = when.defer(),
prom = def.promise,
req = null,
res = {
redirect: function() {
redirect: function () {
return;
}
},

View File

@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
// Use 'testing' Ghost config
@ -13,7 +13,7 @@
resetData: function () {
return migrations.one.down().then(function () {
return migrations.one.up();
}, function() {
}, function () {
throw new Error("Failed to reset data");
});
}

View File

@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "node app",
"test": "nodeunit core/test/ghost"
"test": "grunt validate"
},
"dependencies": {
"express": "3.1.x",
@ -28,6 +28,7 @@
"grunt-mocha-test": "~0.4.0",
"grunt-shell": "~0.2.2",
"grunt-contrib-sass": "~0.3.0",
"sinon": "~1.7.2"
"sinon": "~1.7.2",
"mocha": "~1.10.0"
}
}