Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created January 16, 2013 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/4544938 to your computer and use it in GitHub Desktop.
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...
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');
});
});
});
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