Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
TESTS=test/*.js | ||
MOCHA=./node_modules/.bin/mocha | ||
|
||
test: | ||
@$(MOCHA) $(TESTS) | ||
|
||
.PHONY: test |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var debug = require('debug')('robe') | ||
, monkManager = require('monk') | ||
, monk; | ||
|
||
function Robe (collectionName) { | ||
this.collection = monk.get(collectionName); | ||
} | ||
|
||
Robe.prototype.all = function (options, callback) { | ||
if(typeof(options) === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
this.collection.find({}, callback); | ||
} | ||
|
||
Robe.prototype.find = function(query, callback) { | ||
this.collection.find(query, callback); | ||
} | ||
|
||
Robe.prototype.findOne = function(query, callback) { | ||
this.collection.findOne(query, callback); | ||
} | ||
|
||
Robe.prototype.insert = function(attrs, callback) { | ||
this.collection.insert(attrs, callback); | ||
} | ||
|
||
Robe.prototype.save = Robe.prototype.insert; | ||
|
||
Robe.prototype.byId = function (id, callback) { | ||
if (!id) { | ||
return callback(new Error('Id must be supplied')); | ||
} | ||
|
||
this.collection.findById(id, callback); | ||
} | ||
|
||
module.exports = function (mongoUrlString) { | ||
monk = monkManager(mongoUrlString); | ||
|
||
return Robe; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
expect = require('expect.js'); | ||
|
||
config = { | ||
db: 'mongo://localhost/robe_test' | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--require test/common.js | ||
--growl | ||
--ui bdd | ||
--reporter spec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var Robe = require('../')(config.db); | ||
|
||
describe('Robe', function() { | ||
describe('Factory', function () { | ||
before(function () { | ||
this.robe = new Robe('TestModel'); | ||
}); | ||
|
||
it('should have a .all function', function() { | ||
expect(this.robe.all).to.be.a('function'); | ||
}); | ||
|
||
it('should have a .find function', function() { | ||
expect(this.robe.find).to.be.a('function'); | ||
}); | ||
|
||
it('should have a .findOne function', function() { | ||
expect(this.robe.findOne).to.be.a('function'); | ||
}); | ||
|
||
it('should have a .insert function', function() { | ||
expect(this.robe.insert).to.be.a('function'); | ||
}); | ||
|
||
it('should have a .byId function', function() { | ||
expect(this.robe.byId).to.be.a('function'); | ||
}); | ||
|
||
it('should have a .save function', function() { | ||
expect(this.robe.save).to.be.a('function'); | ||
}); | ||
}); | ||
}); |