Skip to content

Commit

Permalink
getschema has to send original schema source, not the actual schema i…
Browse files Browse the repository at this point in the history
…nstance

and some codestyle
  • Loading branch information
capaj committed Jan 29, 2016
1 parent 0b3278c commit 8bebe51
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Moonridge-client
Submodule Moonridge-client updated 1 files
+2 −2 package.json
2 changes: 1 addition & 1 deletion mr-rpc-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ var expose = function (model, schema, opts) {
* @returns {Object} model's schema
*/
getSchema: function () {
return mss.stringify(schema)
return mss.stringify(model.moonridgeSchema)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"express": "^4.13",
"lodash": "^3.10",
"mongoose": "^4.3.7",
"mongoose-schema-serializer": "^1.0.0",
"mongoose-schema-serializer": "^1.0.1",
"socket.io-rpc": "^1.1.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions test/basic-CRUD.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ describe('basic CRUD including working liveQueries', function () {
})

it('should have a method getSchema for getting a schema of the model', function () {
return fighterModel.getSchema().then(schema => {
schema.should.eql({
name: {type: String, required: true},
health: Number,
born: Date,
death: {type: Date, permissions: {R: 4, W: 20}},
owner: {
ref: 'user',
type: 'ObjectId'
}
})
})
})

describe('rerun liveQueries', function () {
Expand Down
24 changes: 10 additions & 14 deletions test/e2e-smoketest/db-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ var mongoose = require('mongoose')
process.on('unhandledRejection', function (error, promise) {
console.error('UNHANDLED REJECTION', error)
})
module.exports = function(MR) {

module.exports = function (MR) {
var location = MR.model('location', {loc: {type: [Number], index: '2dsphere'}}, {
schemaInit: function(schema) {

schemaInit: function (schema) {
}
}) // for testing near queries
var fighter = MR.model('fighter', {
Expand Down Expand Up @@ -36,7 +34,7 @@ module.exports = function(MR) {
})

fighter.schema.on('preupdate', function (doc, previousDocVersion) {
console.log("fighter preupdate callback triggered, is modified ", doc.isModified()) // a good place to put custom save logic
console.log('fighter preupdate callback triggered, is modified ', doc.isModified()) // a good place to put custom save logic
console.log('doc', doc)
console.log('previousDocVersion', previousDocVersion)
})
Expand All @@ -48,7 +46,7 @@ module.exports = function(MR) {
}, {ownerRequired: false})

battleM.schema.on('update', function (doc, previousDocVersion) {
console.log("battle update callback triggered, is modified ", doc.isModified()) // a good place to put custom save logic
console.log('battle update callback triggered, is modified ', doc.isModified()) // a good place to put custom save logic
console.log(doc)
console.log(previousDocVersion)
})
Expand All @@ -68,20 +66,18 @@ module.exports = function(MR) {
//
// })


return Promise.all([].concat([
user.create({
name: 'admin', privilege_level: 50
}).then(function() {
console.log("admin created")
}).then(function () {
console.log('admin created')
}),
user.create({
name: 'testUser', privilege_level: 10
}).then(function() {
console.log("testUser created")
}).then(function () {
console.log('testUser created')
})
])).then(function() {
console.log("all collections should be clean, users created")

])).then(function () {
console.log('all collections should be clean, users created')
})
}

0 comments on commit 8bebe51

Please sign in to comment.