Skip to content

Commit

Permalink
Merge pull request #30 from mbschuster/dev
Browse files Browse the repository at this point in the history
made the test pass
  • Loading branch information
ekryski committed Mar 24, 2012
2 parents d5045d2 + 0be2c4d commit 118451e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
3 changes: 2 additions & 1 deletion controllers/home.js
Original file line number Diff line number Diff line change
@@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = (function () {

var listing;

function initialize ( options ) {
Expand Down
50 changes: 47 additions & 3 deletions test/unit/controllers/homeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down

0 comments on commit 118451e

Please sign in to comment.