Created
January 16, 2013 05:41
-
-
Save howarddierking/4544938 to your computer and use it in GitHub Desktop.
Trying to figure out what I'm doing wrong with this module definition. In this implementation, the history member keeps throwing as undefined when calling this.history.push in addToHistory...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var should = require('should'), | |
bugs = require('../bugs.js'); | |
describe('bugs', function(){ | |
describe('when creating a new bug', function(){ | |
describe('with no parameters', function() { | |
it('should return an error'); | |
}); | |
describe('with the default title parameter', function() { | |
it('it should return a new bug object', function(){ | |
var newBug = bugs.createBug('new bug'); | |
should.exist(newBug); | |
}); | |
it('should have the title that was passed as an argument to the create function', function(){ | |
var newBug = bugs.createBug('test bug'); | |
newBug.title.should.equal('test bug'); | |
}); | |
it('should be in an active state', function(){ | |
var newBug = bugs.createBug('test bug'); | |
newBug.status.should.equal('Backlog'); | |
}); | |
it('should have a single item in history indicating that the bug was created', function(){ | |
var newBug = bugs.createBug('test bug'); | |
newBug.history.length.should.equal(1); | |
}); | |
it('should have an item added to the database'); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoclient = require('mongodb').MongoClient, | |
mongolocation = ''; | |
var Bug = (function() { | |
var save = function(){ | |
mongoclient.connect(mongolocation, function(err, db){ | |
if(err) console.dir(err); | |
var bugscollection = db.collection('bugs'); | |
}); | |
}, | |
addToHistory = function(comments, stateChanges){ | |
this.history.push({ | |
addedOn: new Date(), | |
comments: comments, | |
changes: stateChanges }); | |
}, | |
toBacklog = function(comments) { | |
this.status = 'Backlog'; | |
addToHistory(comments, {'status':'Backlog'}); | |
}; | |
return { | |
toBacklog : toBacklog, | |
status : undefined, | |
title : undefined, | |
history : [] | |
}; | |
})(); | |
var createBug = function(title) { | |
var newbug = Object.create(Bug); | |
newbug.title = title; | |
newbug.toBacklog('Bug created'); | |
return newbug; | |
} | |
var getBug = function(bugID){ | |
//todo | |
}; | |
module.exports.createBug = createBug; | |
module.exports.getBug = getBug; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment