Skip to content

Commit

Permalink
added #save
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 23, 2014
1 parent 412c59a commit 024a942
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ Trip.all = function(cb){
});
};

Trip.findById = function(id, cb){
id = Mongo.ObjectID(id);
Trip.collection.findOne({_id:id}, function(err, obj){
var t = _.create(Trip.prototype, obj);
cb(err, t);
});
};

Trip.prototype.save = function(cb){
Trip.collection.save(this, cb);
};

module.exports = Trip;

22 changes: 22 additions & 0 deletions test/unit/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ describe('Trip', function(){
});
});

describe('#save', function(){
it('should save a trip in the database', function(done){
t.save(function(){
Trip.all(function(err, trips){
expect(trips).to.have.length(4);
done();
});
});
});
});

describe('.all', function(){
it('should get all trips', function(done){
Trip.all(function(err, trips){
Expand All @@ -89,5 +100,16 @@ describe('Trip', function(){
});
});
});

describe('.findById', function(){
it('should return a trip from the database', function(done){
Trip.findById('000000000000000000000002', function(err, trip){
expect(trip._id.toString()).to.equal('000000000000000000000002');
expect(trip.cost).to.be.closeTo(178.90, 0.1);
done();
});
});
});

});

0 comments on commit 024a942

Please sign in to comment.