Merge pull request #75 from tgriesser/test-cleanup

Test cleanup - using promises properly
This commit is contained in:
Hannah Wolfe 2013-05-27 05:48:25 -07:00
commit 1e47f4e825
13 changed files with 148 additions and 184 deletions

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

@ -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 () {

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"
}
}