Skip to content

Commit

Permalink
added .save
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 19, 2014
1 parent aec9e0d commit 521bdc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/models/vacation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ Vacation.all = function(cb){
Vacation.collection.find().toArray(cb);
};

Vacation.save = function(o, cb){
var v = new Vacation(o);
Vacation.collection.save(v, function(){
cb(v);
});
};

module.exports = Vacation;

19 changes: 16 additions & 3 deletions test/unit/vacation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
var expect = require('chai').expect,
Vacation = require('../../app/models/vacation'),
dbConnect = require('../../app/lib/mongodb'),
Mongo = require('mongodb'),
cp = require('child_process'),
db = 'world-traveler-test';
db = 'world-traveler-test',
o,
v;

describe('Vacation', function(){
before(function(done){
Expand All @@ -19,13 +22,13 @@ describe('Vacation', function(){
beforeEach(function(done){
cp.execFile(__dirname + '/../scripts/clean-db.sh', [db], {cwd:__dirname + '/../scripts'}, function(err, stdout, stderr){
// console.log(stdout, stderr);
o = {lat:'37.688889',lng:'-97.33611100000002',name:'Wichita, KS, USA',from:'2014-10-01',to:'2014-10-11'},
v = new Vacation(o);
done();
});
});
describe('constructor', function(){
it('should create a new Vacation object', function(){
var o = {lat:'37.688889',lng:'-97.33611100000002',name:'Wichita, KS, USA',from:'2014-10-01',to:'2014-10-11'},
v = new Vacation(o);
expect(v).to.be.instanceof(Vacation);
expect(v.name).to.equal('Wichita, KS, USA');
expect(v.lat).to.be.closeTo(37.688889, 0.01);
Expand All @@ -44,5 +47,15 @@ describe('Vacation', function(){
});
});
});

describe('.save', function(){
it('should save a new vacation to the database', function(done){
Vacation.save(o, function(vacation){
expect(vacation._id).to.be.instanceof(Mongo.ObjectID);
done();
});
});
});

});

0 comments on commit 521bdc9

Please sign in to comment.