From e23381d17b598ed739b66ef8a2192eae9c3b209a Mon Sep 17 00:00:00 2001 From: ErisDS Date: Sun, 26 May 2013 20:25:17 +0100 Subject: [PATCH] Fixing JSLint and the Mocha api tests --- .../models/dataProvider.bookshelf.base.js | 3 +- .../models/dataProvider.bookshelf.users.js | 5 +- core/test/ghost/api_posts_spec.js | 52 ++++++++--------- core/test/ghost/api_settings_spec.js | 56 +++++++++++-------- core/test/ghost/api_users_spec.js | 46 ++++++++------- 5 files changed, 90 insertions(+), 72 deletions(-) diff --git a/core/shared/models/dataProvider.bookshelf.base.js b/core/shared/models/dataProvider.bookshelf.base.js index 1645c7e2b5..058dda0e3a 100644 --- a/core/shared/models/dataProvider.bookshelf.base.js +++ b/core/shared/models/dataProvider.bookshelf.base.js @@ -1,3 +1,4 @@ +/*global require, module */ (function () { "use strict"; @@ -22,7 +23,7 @@ * @param args (optional) */ BookshelfBase.prototype.findAll = BookshelfBase.prototype.browse = function (args) { - args || (args = {}); + args = args || {}; return this.collection.forge(args).fetch(); }; diff --git a/core/shared/models/dataProvider.bookshelf.users.js b/core/shared/models/dataProvider.bookshelf.users.js index 1b981f71b9..e2f8b38004 100644 --- a/core/shared/models/dataProvider.bookshelf.users.js +++ b/core/shared/models/dataProvider.bookshelf.users.js @@ -43,12 +43,13 @@ * Finds the user by email, and check's the password */ UsersProvider.prototype.check = function (_userdata) { - console.log('just checking', _userdata); 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) { - if (!matched) return when.reject(new Error('Password does not match')); + if (!matched) { + return when.reject(new Error('Password does not match')); + } return user; }); }); diff --git a/core/test/ghost/api_posts_spec.js b/core/test/ghost/api_posts_spec.js index 994752f1b8..48dea9f1d8 100644 --- a/core/test/ghost/api_posts_spec.js +++ b/core/test/ghost/api_posts_spec.js @@ -20,64 +20,64 @@ }); it('can browse', function (done) { - posts.browse(function (err, results) { - if (err) { throw err; } - + posts.browse().then(function (results) { should.exist(results); results.length.should.equal(2); done(); + }, function (error) { + throw error; }); }); it('can read', function (done) { var firstPost; - posts.browse(function (err, results) { - if (err) { throw err; } - + posts.browse().then(function (results) { should.exist(results); results.length.should.be.above(0); firstPost = results.models[0]; - posts.read({slug: firstPost.attributes.slug}, function (err, found) { - if (err) { throw err; } - + 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; }); }); it('can edit', function (done) { var firstPost; - posts.browse(function (err, results) { - if (err) { throw err; } - + 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"}, function (err, edited) { - if (err) { throw err; } - + 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; }); }); @@ -87,9 +87,7 @@ content: 'Test Content 1' }; - posts.add(newPost, function (err, createdPost) { - if (err) { throw err; } - + posts.add(newPost).then(function (createdPost) { should.exist(createdPost); createdPost.attributes.title.should.equal(newPost.title, "title is correct"); @@ -97,6 +95,8 @@ createdPost.attributes.slug.should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct'); done(); + }, function (error) { + throw error; }); }); @@ -105,20 +105,16 @@ ids, hasDeletedId; - posts.browse(function (err, results) { - if (err) { throw err; } - + posts.browse().then(function (results) { should.exist(results); results.length.should.be.above(0); firstPostId = results.models[0].id; - posts.destroy(firstPostId, function (err) { - if (err) { throw err; } + posts.destroy(firstPostId).then(function () { - posts.browse(function (err, newResults) { - if (err) { throw err; } + posts.browse().then(function (newResults) { ids = _.pluck(newResults.models, "id"); @@ -129,8 +125,14 @@ hasDeletedId.should.equal(false); done(); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); }); }); diff --git a/core/test/ghost/api_settings_spec.js b/core/test/ghost/api_settings_spec.js index 46a0991c90..77d88a11ef 100644 --- a/core/test/ghost/api_settings_spec.js +++ b/core/test/ghost/api_settings_spec.js @@ -20,22 +20,22 @@ }); it('can browse', function (done) { - settings.browse(function (err, results) { - if (err) { throw err; } + settings.browse().then(function (results) { should.exist(results); results.length.should.be.above(0); done(); + }, function (error) { + throw error; }); }); it('can read', function (done) { var firstSetting; - settings.browse(function (err, results) { - if (err) { throw err; } + settings.browse().then(function (results) { should.exist(results); @@ -43,16 +43,19 @@ firstSetting = results.models[0]; - settings.read(firstSetting.attributes.key, function (err, found) { - if (err) { throw err; } + 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; }); }); @@ -60,8 +63,7 @@ var firstPost, toEdit = {}; - settings.browse(function (err, results) { - if (err) { throw err; } + settings.browse().then(function (results) { should.exist(results); @@ -73,8 +75,7 @@ // key/value pairs toEdit[firstPost.attributes.key] = "new value"; - settings.edit(toEdit, function (err, edited) { - if (err) { throw err; } + settings.edit(toEdit).then(function (edited) { should.exist(edited); @@ -86,8 +87,12 @@ edited.attributes.value.should.equal('new value'); done(); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); }); @@ -97,8 +102,7 @@ editedPost, toEdit = {}; - settings.browse(function (err, results) { - if (err) { throw err; } + settings.browse().then(function (results) { should.exist(results); @@ -112,8 +116,7 @@ toEdit[firstPost.attributes.key] = "new value1"; toEdit[secondPost.attributes.key] = "new value2"; - settings.edit(toEdit, function (err, edited) { - if (err) { throw err; } + settings.edit(toEdit).then(function (edited) { should.exist(edited); @@ -130,8 +133,11 @@ editedPost.attributes.value.should.equal('new value2'); done(); + }, function (error) { + throw error; }); - + }, function (error) { + throw error; }); }); @@ -141,8 +147,7 @@ value: 'Test Content 1' }; - settings.add(newSetting, function (err, createdSetting) { - if (err) { throw err; } + settings.add(newSetting).then(function (createdSetting) { should.exist(createdSetting); @@ -150,6 +155,8 @@ createdSetting.attributes.value.should.equal(newSetting.value, "value is correct"); done(); + }, function (error) { + throw error; }); }); @@ -158,8 +165,7 @@ ids, hasDeletedId; - settings.browse(function (err, results) { - if (err) { throw err; } + settings.browse().then(function (results) { should.exist(results); @@ -167,11 +173,9 @@ firstSettingId = results.models[0].id; - settings.destroy(firstSettingId, function (err) { - if (err) { throw err; } + settings.destroy(firstSettingId).then(function () { - settings.browse(function (err, newResults) { - if (err) { throw err; } + settings.browse().then(function (newResults) { ids = _.pluck(newResults.models, "id"); @@ -182,8 +186,14 @@ hasDeletedId.should.equal(false); done(); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); }); }); diff --git a/core/test/ghost/api_users_spec.js b/core/test/ghost/api_users_spec.js index be1f8ed666..82c44a08e3 100644 --- a/core/test/ghost/api_users_spec.js +++ b/core/test/ghost/api_users_spec.js @@ -20,22 +20,22 @@ }); it('can browse', function (done) { - users.browse(function (err, results) { - if (err) { throw err; } + users.browse().then(function (results) { should.exist(results); results.length.should.be.above(0); done(); + }, function (error) { + throw error; }); }); it('can read', function (done) { var firstUser; - users.browse(function (err, results) { - if (err) { throw err; } + users.browse().then(function (results) { should.exist(results); @@ -43,14 +43,15 @@ firstUser = results.models[0]; - users.read({email_address: firstUser.attributes.email_address}, function (err, found) { - if (err) { throw err; } + 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; }); }); @@ -59,8 +60,7 @@ it('can edit', function (done) { var firstUser; - users.browse(function (err, results) { - if (err) { throw err; } + users.browse().then(function (results) { should.exist(results); @@ -68,16 +68,18 @@ firstUser = results.models[0]; - users.edit({id: firstUser.id, url: "some.newurl.com"}, function (err, edited) { - if (err) { throw err; } + 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; }); }); @@ -87,10 +89,7 @@ email_address: "test@test1.com" }; - users.add(userData, function (err, createdUser) { - if (err) { - throw err; - } + users.add(userData).then(function (createdUser) { should.exist(createdUser); @@ -98,6 +97,8 @@ createdUser.attributes.email_address.should.eql(userData.email_address, "email address corred"); done(); + }, function (error) { + throw error; }); }); @@ -106,8 +107,7 @@ ids, hasDeletedId; - users.browse(function (err, results) { - if (err) { throw err; } + users.browse().then(function (results) { should.exist(results); @@ -115,11 +115,9 @@ firstUserId = results.models[0].id; - users.destroy(firstUserId, function (err) { - if (err) { throw err; } + users.destroy(firstUserId).then(function () { - users.browse(function (err, newResults) { - if (err) { throw err; } + users.browse().then(function (newResults) { if (newResults.length < 1) { // Bug out if we only had one user and deleted it. @@ -135,8 +133,14 @@ hasDeletedId.should.equal(false); done(); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); + }, function (error) { + throw error; }); }); });