Skip to content

Commit

Permalink
initialize baucis controller synchronously and store it on model
Browse files Browse the repository at this point in the history
  • Loading branch information
capaj committed Feb 20, 2016
1 parent 912968b commit 8054609
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions moonridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function connect (connString, opts) {
function regNewModel (name, schema, opts) {
var model = MRModel.apply(moonridgeSingleton, arguments)
models[name] = model
model.controller = baucis.rest(name)
return model
}

Expand All @@ -70,7 +71,7 @@ function registerUserModel (schemaExtend, opts) {
_.extend(userSchema, schemaExtend)
userModel = MRModel.call(moonridgeSingleton, 'user', userSchema, opts)
models['user'] = userModel

userModel.controller = baucis.rest('user')
return userModel
}

Expand All @@ -89,7 +90,6 @@ function bootstrap () {

Object.keys(models).forEach(function (modelName) {
var model = models[modelName]
baucis.rest(modelName)
model._exposeCallback(server)
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moonridge",
"version": "0.9.27",
"version": "0.9.28",
"main": "moonridge.js",
"author": "Capaj <capajj@gmail.com>",
"description": "Isomorphic library, which allows you to use Mongoose.js models via socket.io-rpc doing regular queries and liveQueries",
Expand Down Expand Up @@ -41,7 +41,7 @@
"baucis-swagger": "^1.1.2",
"debug": "^2.2.0",
"lodash": "^3.10",
"mongoose": "^4.4.2",
"mongoose": "^4.4.4",
"mongoose-schema-serializer": "^1.0.1",
"socket.io-rpc": "^1.1.3"
},
Expand Down
12 changes: 12 additions & 0 deletions test/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ describe('Moonridge model', function () {
let server
let LQ

it('should have a baucis controller', function () {
sampleModel = MR.model('first_test_model', {
name: String
})
const ctrl = sampleModel.controller
expect(ctrl).to.be.a('function')
expect(ctrl.put).to.be.a('function')
expect(ctrl.get).to.be.a('function')
expect(ctrl.delete).to.be.a('function')
expect(ctrl.post).to.be.a('function')
})

it('should run schemaInit on registering a new model', function (done) {
sampleModel = MR.model('sample_model', {
name: String
Expand Down

0 comments on commit 8054609

Please sign in to comment.