Permalink
Browse files

Merge pull request #30 from mbschuster/dev

made the test pass
  • Loading branch information...
2 parents d5045d2 + 0be2c4d commit 118451e588b9e3a77d61065bb054e95700489f39 @ekryski ekryski committed Mar 24, 2012
Showing with 51 additions and 5 deletions.
  1. +1 −1 app.js
  2. +2 −1 controllers/home.js
  3. +1 −0 models/index.js
  4. +47 −3 test/unit/controllers/homeTest.js
View
2 app.js
@@ -37,7 +37,7 @@ Vibe = mongoose.model('Vibe');
Amenity = mongoose.model('Amenity');
Tag = mongoose.model( 'Tag' );
-app.models. = require( './models' );
+app.models = require( './models' );
app.models.initialize( { app: app } );
app.controllers = require( './controllers' );
View
3 controllers/home.js
@@ -1,8 +1,9 @@
module.exports = ( function () {
+ var app
var Listing;
function initialize ( options ){
- var app = options.app;
+ app = options.app;
Listing = app.models.listing.getModel();
}
View
1 models/index.js
@@ -1,4 +1,5 @@
module.exports = (function () {
+
var listing;
function initialize ( options ) {
View
50 test/unit/controllers/homeTest.js
@@ -7,13 +7,57 @@ describe( 'sharpodz.test.unit.controllers.home', function() {
var mockRequest = {};
var mockResponse = { render: stub.sync() };
- var mockApp = { };
+ var listings = [{
+ images: ['one','two']
+ },{
+ images: ['three','four']
+ }
+ ];
+ var expectedListing = [{
+ images: ['one','two'],
+ mainImage: 'one'
+ }
+ ];
+ var expectedLatest = {
+ images: ['three','four'],
+ mainImage: 'three'
+ }
+
+ var mockListing = {
+ find: stub.sync(null, {
+ limit : stub.sync(null, {
+ sort: stub.sync(null, {
+ exec: stub.async(null, listings)
+ })
+ })
+ })
+ };
+
+ var mockApp = {
+ models: {
+ listing: {
+ getModel: function() {
+ return mockListing;
+ }
+ }
+ }
+ };
describe( 'index', function() {
it( 'should call the database and grab the first 7 listings', function( done ) {
- homeController.initialize( mockApp );
-
+ homeController.initialize( { app: mockApp } );
+ homeController.index(mockRequest, mockResponse);
+ mockListing.find.called.withAnyArguments();
+ listings[0].mainImage.should.equal(expectedListing[0].mainImage);
+ mockResponse.render.called.withArguments('index', {
+ locals: {
+ title: "Test",
+ is_home: true,
+ results: expectedListing,
+ latest: expectedLatest
+ }
+ });
done();
} );

0 comments on commit 118451e

Please sign in to comment.