diff --git a/lib/hooks/blueprints/actions/add.js b/lib/hooks/blueprints/actions/add.js index 1d2a1bed0..f02de1511 100644 --- a/lib/hooks/blueprints/actions/add.js +++ b/lib/hooks/blueprints/actions/add.js @@ -116,7 +116,7 @@ module.exports = function addToCollection (req, res) { ChildModel.subscribe(req, newChildRecord); ChildModel.introduce(newChildRecord); } - ChildModel.publishCreate(newChildRecord, !req.options.mirror && req); + ChildModel._publishCreate(newChildRecord, !req.options.mirror && req); } createdChild = true; @@ -159,7 +159,7 @@ module.exports = function addToCollection (req, res) { async_data.parent.save(function saved(err) { // Ignore `insert` errors for duplicate adds - // (but keep in mind, we should not publishAdd if this is the case...) + // (but keep in mind, we should not _publishAdd if this is the case...) var isDuplicateInsertError = (err && typeof err === 'object' && err.length && err[0] && err[0].type === 'insert'); if (err && !isDuplicateInsertError) return res.negotiate(err); @@ -170,7 +170,7 @@ module.exports = function addToCollection (req, res) { // Subscribe to the model you're adding to, if this was a socket request if (req.isSocket) { Model.subscribe(req, async_data.parent); } // Publish to subscribed sockets - Model.publishAdd(async_data.parent[Model.primaryKey], relation, async_data.actualChildPkValue, !req.options.mirror && req, {noReverse: createdChild}); + Model._publishAdd(async_data.parent[Model.primaryKey], relation, async_data.actualChildPkValue, !req.options.mirror && req, {noReverse: createdChild}); } // Finally, look up the parent record again and populate the relevant collection. diff --git a/lib/hooks/blueprints/actions/create.js b/lib/hooks/blueprints/actions/create.js index bb8b5306c..2c64d0109 100644 --- a/lib/hooks/blueprints/actions/create.js +++ b/lib/hooks/blueprints/actions/create.js @@ -19,36 +19,36 @@ var _ = require('lodash'); */ module.exports = function createRecord (req, res) { - var Model = actionUtil.parseModel(req); - - // Create data object (monolithic combination of all parameters) - // Omit the blacklisted params (like JSONP callback param, etc.) - var data = actionUtil.parseValues(req); - - - // Create new instance of model using data from params - Model.create(data).exec(function created (err, newInstance) { - - // Differentiate between waterline-originated validation errors - // and serious underlying issues. Respond with badRequest if a - // validation error is encountered, w/ validation info. - if (err) return res.negotiate(err); - - // If we have the pubsub hook, use the model class's publish method - // to notify all subscribers about the created item - if (req._sails.hooks.pubsub) { - if (req.isSocket) { - Model.subscribe(req, newInstance); - Model.introduce(newInstance); - } - // Make sure data is JSON-serializable before publishing - var publishData = _.isArray(newInstance) ? - _.map(newInstance, function(instance) {return instance.toJSON();}) : - newInstance.toJSON(); - Model.publishCreate(publishData, !req.options.mirror && req); - } - - // Send JSONP-friendly response if it's supported - res.created(newInstance); - }); + var Model = actionUtil.parseModel(req); + + // Create data object (monolithic combination of all parameters) + // Omit the blacklisted params (like JSONP callback param, etc.) + var data = actionUtil.parseValues(req); + + + // Create new instance of model using data from params + Model.create(data).exec(function created (err, newInstance) { + + // Differentiate between waterline-originated validation errors + // and serious underlying issues. Respond with badRequest if a + // validation error is encountered, w/ validation info. + if (err) return res.negotiate(err); + + // If we have the pubsub hook, use the model class's publish method + // to notify all subscribers about the created item + if (req._sails.hooks.pubsub) { + if (req.isSocket) { + Model.subscribe(req, newInstance); + Model.introduce(newInstance); + } + // Make sure data is JSON-serializable before publishing + var publishData = _.isArray(newInstance) ? + _.map(newInstance, function(instance) {return instance.toJSON();}) : + newInstance.toJSON(); + Model._publishCreate(publishData, !req.options.mirror && req); + } + + // Send JSONP-friendly response if it's supported + res.created(newInstance); + }); }; diff --git a/lib/hooks/blueprints/actions/destroy.js b/lib/hooks/blueprints/actions/destroy.js index 18fea87c8..f0617f75c 100644 --- a/lib/hooks/blueprints/actions/destroy.js +++ b/lib/hooks/blueprints/actions/destroy.js @@ -33,7 +33,7 @@ module.exports = function destroyOneRecord (req, res) { if (err) return res.negotiate(err); if (req._sails.hooks.pubsub) { - Model.publishDestroy(pk, !req._sails.config.blueprints.mirror && req, {previous: record}); + Model._publishDestroy(pk, !req._sails.config.blueprints.mirror && req, {previous: record}); if (req.isSocket) { Model.unsubscribe(req, record); Model.retire(record); diff --git a/lib/hooks/blueprints/actions/remove.js b/lib/hooks/blueprints/actions/remove.js index f6f4d2a2f..d6cbfd96b 100644 --- a/lib/hooks/blueprints/actions/remove.js +++ b/lib/hooks/blueprints/actions/remove.js @@ -57,7 +57,7 @@ module.exports = function remove(req, res) { // If we have the pubsub hook, use the model class's publish method // to notify all subscribers about the removed item if (req._sails.hooks.pubsub) { - Model.publishRemove(parentRecord[Model.primaryKey], relation, childPk, !req._sails.config.blueprints.mirror && req); + Model._publishRemove(parentRecord[Model.primaryKey], relation, childPk, !req._sails.config.blueprints.mirror && req); } return res.ok(parentRecord); diff --git a/lib/hooks/blueprints/actions/update.js b/lib/hooks/blueprints/actions/update.js index 338b988d5..063a887dc 100644 --- a/lib/hooks/blueprints/actions/update.js +++ b/lib/hooks/blueprints/actions/update.js @@ -80,7 +80,7 @@ module.exports = function updateOneRecord (req, res) { // to notify all subscribers about the update. if (req._sails.hooks.pubsub) { if (req.isSocket) { Model.subscribe(req, records); } - Model.publishUpdate(pk, _.cloneDeep(values), !req.options.mirror && req, { + Model._publishUpdate(pk, _.cloneDeep(values), !req.options.mirror && req, { previous: _.cloneDeep(matchingRecord.toJSON()) }); } diff --git a/lib/hooks/pubsub/README.md b/lib/hooks/pubsub/README.md index 04f647dbd..0d3452d0f 100644 --- a/lib/hooks/pubsub/README.md +++ b/lib/hooks/pubsub/README.md @@ -17,7 +17,7 @@ socket.on('debug', function (msg) { .. }); ###### Server ```javascript // Any of the pubsub methods.. -User.publishUpdate() +User._publishUpdate() sails.sockets.emit() ``` diff --git a/lib/hooks/pubsub/index.js b/lib/hooks/pubsub/index.js index 2ffd05064..c2616cece 100644 --- a/lib/hooks/pubsub/index.js +++ b/lib/hooks/pubsub/index.js @@ -98,11 +98,11 @@ module.exports = function(sails) { 'unsubscribe', 'publish', 'room', - 'publishCreate', - 'publishUpdate', - 'publishDestroy', - 'publishAdd', - 'publishRemove' + '_publishCreate', + '_publishUpdate', + '_publishDestroy', + '_publishAdd', + '_publishRemove' ); sails.models[identity] = AugmentedModel; } @@ -556,7 +556,7 @@ module.exports = function(sails) { * @api public */ - publishUpdate: function (id, changes, req, options) { + _publishUpdate: function (id, changes, req, options) { var reverseAssociation; // Make sure there's an options object @@ -570,12 +570,12 @@ module.exports = function(sails) { if ( !validId ) { return sails.log.error( 'Invalid usage of `' + this.identity + - '.publishUpdate(id, changes, [socketToOmit])`' + '._publishUpdate(id, changes, [socketToOmit])`' ); } - if (_.isFunction(this.beforePublishUpdate)) { - this.beforePublishUpdate(id, changes, req, options); + if (_.isFunction(this._beforePublishUpdate)) { + this._beforePublishUpdate(id, changes, req, options); } // Coerce id to match the attribute type of the primary key of the model @@ -625,19 +625,19 @@ module.exports = function(sails) { if (!reverseAssociation) {return;} - // If this is a to-many association, do publishAdd or publishRemove as necessary + // If this is a to-many association, do _publishAdd or _publishRemove as necessary // on the other side if (reverseAssociation.type === 'collection') { // If there was a previous value, alert the previously associated model if (previous[key]) { - ReferencedModel.publishRemove(previousPK, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishRemove(previousPK, reverseAssociation.alias, id, req, {noReverse:true}); } // If there's a new value (i.e. it's not null), alert the newly associated model if (val) { - ReferencedModel.publishAdd(newPK, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishAdd(newPK, reverseAssociation.alias, id, req, {noReverse:true}); } } - // Otherwise do a publishUpdate + // Otherwise do a _publishUpdate else { var pubData = {}; @@ -645,12 +645,12 @@ module.exports = function(sails) { // If there was a previous association, notify it that it has been nullified if (previous[key]) { pubData[reverseAssociation.alias] = null; - ReferencedModel.publishUpdate(previousPK, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(previousPK, pubData, req, {noReverse:true}); } // If there's a new association, notify it that it has been linked if (val) { pubData[reverseAssociation.alias] = id; - ReferencedModel.publishUpdate(newPK, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(newPK, pubData, req, {noReverse:true}); } } @@ -684,35 +684,35 @@ module.exports = function(sails) { // Find any values that were removed from the collection var removedPKs = _.difference(previousPKs, updatedPKs); - // If this is a to-many association, do publishAdd or publishRemove as necessary + // If this is a to-many association, do _publishAdd or _publishRemove as necessary // on the other side if (reverseAssociation.type === 'collection') { // Alert any removed models _.each(removedPKs, function(pk) { - ReferencedModel.publishRemove(pk, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishRemove(pk, reverseAssociation.alias, id, req, {noReverse:true}); }); // Alert any added models _.each(addedPKs, function(pk) { - ReferencedModel.publishAdd(pk, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishAdd(pk, reverseAssociation.alias, id, req, {noReverse:true}); }); } - // Otherwise do a publishUpdate + // Otherwise do a _publishUpdate else { // Alert any removed models _.each(removedPKs, function(pk) { var pubData = {}; pubData[reverseAssociation.alias] = null; - ReferencedModel.publishUpdate(pk, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(pk, pubData, req, {noReverse:true}); }); // Alert any added models _.each(addedPKs, function(pk) { var pubData = {}; pubData[reverseAssociation.alias] = id; - ReferencedModel.publishUpdate(pk, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(pk, pubData, req, {noReverse:true}); }); } @@ -734,8 +734,8 @@ module.exports = function(sails) { // Broadcast to the model instance room this.publish(id, this.identity, 'update', data, socketToOmit); - if (_.isFunction(this.afterPublishUpdate)) { - this.afterPublishUpdate(id, changes, req, options); + if (_.isFunction(this._afterPublishUpdate)) { + this._afterPublishUpdate(id, changes, req, options); } @@ -751,7 +751,7 @@ module.exports = function(sails) { * */ - publishDestroy: function (id, req, options) { + _publishDestroy: function (id, req, options) { var reverseAssociation; options = options || {}; @@ -761,12 +761,12 @@ module.exports = function(sails) { if ( invalidId ) { return sails.log.error( 'Invalid usage of `' + this.identity + - '.publishDestroy(id, [socketToOmit])`' + '._publishDestroy(id, [socketToOmit])`' ); } - if (_.isFunction(this.beforePublishDestroy)) { - this.beforePublishDestroy(id, req, options); + if (_.isFunction(this._beforePublishDestroy)) { + this._beforePublishDestroy(id, req, options); } // Coerce id to match the attribute type of the primary key of the model @@ -816,11 +816,11 @@ module.exports = function(sails) { if (reverseAssociation.type === 'model') { var pubData = {}; pubData[reverseAssociation.alias] = null; - ReferencedModel.publishUpdate(referencedModelId, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(referencedModelId, pubData, req, {noReverse:true}); } // If it's a to-many, publish a "removed" alert else { - ReferencedModel.publishRemove(referencedModelId, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishRemove(referencedModelId, reverseAssociation.alias, id, req, {noReverse:true}); } } } @@ -836,11 +836,11 @@ module.exports = function(sails) { if (reverseAssociation.type === 'model') { var pubData = {}; pubData[reverseAssociation.alias] = null; - ReferencedModel.publishUpdate(associatedModel[ReferencedModel.primaryKey], pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(associatedModel[ReferencedModel.primaryKey], pubData, req, {noReverse:true}); } // If it's a to-many, publish a "removed" alert else { - ReferencedModel.publishRemove(associatedModel[ReferencedModel.primaryKey], reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishRemove(associatedModel[ReferencedModel.primaryKey], reverseAssociation.alias, id, req, {noReverse:true}); } }); } @@ -850,15 +850,15 @@ module.exports = function(sails) { } - if (_.isFunction(this.afterPublishDestroy)) { - this.afterPublishDestroy(id, req, options); + if (_.isFunction(this._afterPublishDestroy)) { + this._afterPublishDestroy(id, req, options); } }, /** - * publishAdd + * _publishAdd * * @param {[type]} id [description] * @param {[type]} alias [description] @@ -866,7 +866,7 @@ module.exports = function(sails) { * @param {[type]} socketToOmit [description] */ - publishAdd: function(id, alias, added, req, options) { + _publishAdd: function(id, alias, added, req, options) { var reverseAssociation; // Make sure there's an options object @@ -879,7 +879,7 @@ module.exports = function(sails) { if ( invalidId || invalidAlias || invalidAddedId ) { return sails.log.error( 'Invalid usage of `' + this.identity + - '.publishAdd(id, alias, idAdded|recordAdded, [socketToOmit])`' + '._publishAdd(id, alias, idAdded|recordAdded, [socketToOmit])`' ); } @@ -902,7 +902,7 @@ module.exports = function(sails) { // If we don't find a primary key value, we'll log an error and return early. if (!_.isString(idAdded) && !_.isNumber(idAdded)) { sails.log.error( - 'Invalid usage of publishAdd(): expected object provided '+ + 'Invalid usage of _publishAdd(): expected object provided '+ 'for `recordAdded` to have a `%s` attribute', reverseModel.primaryKey ); return; @@ -910,8 +910,8 @@ module.exports = function(sails) { } // Lifecycle event - if (_.isFunction(this.beforePublishAdd)) { - this.beforePublishAdd(id, alias, idAdded, req); + if (_.isFunction(this._beforePublishAdd)) { + this._beforePublishAdd(id, alias, idAdded, req); } // If a request object was sent, get its socket, otherwise assume a socket was sent. @@ -954,32 +954,32 @@ module.exports = function(sails) { // Find the reverse association, if any reverseAssociation = _.find(reverseModel.associations, {alias: _.find(this.associations, {alias: alias}).via}) ; if (reverseAssociation) { - // If this is a many-to-many association, do a publishAdd for the + // If this is a many-to-many association, do a _publishAdd for the // other side. if (reverseAssociation.type === 'collection') { - reverseModel.publishAdd(idAdded, reverseAssociation.alias, id, req, {noReverse:true}); + reverseModel._publishAdd(idAdded, reverseAssociation.alias, id, req, {noReverse:true}); } - // Otherwise, do a publishUpdate + // Otherwise, do a _publishUpdate else { data = {}; data[reverseAssociation.alias] = id; - reverseModel.publishUpdate(idAdded, data, req, {noReverse:true}); + reverseModel._publishUpdate(idAdded, data, req, {noReverse:true}); } } } - if (_.isFunction(this.afterPublishAdd)) { - this.afterPublishAdd(id, alias, idAdded, req); + if (_.isFunction(this._afterPublishAdd)) { + this._afterPublishAdd(id, alias, idAdded, req); } }, /** - * publishRemove + * _publishRemove * * @param {[type]} id [description] * @param {[type]} alias [description] @@ -987,7 +987,7 @@ module.exports = function(sails) { * @param {[type]} socketToOmit [description] */ - publishRemove: function(id, alias, idRemoved, req, options) { + _publishRemove: function(id, alias, idRemoved, req, options) { var reverseAssociation; // Make sure there's an options object @@ -1000,11 +1000,11 @@ module.exports = function(sails) { if ( invalidId || invalidAlias || invalidRemovedId ) { return sails.log.error( 'Invalid usage of `' + this.identity + - '.publishRemove(id, alias, idRemoved, [socketToOmit])`' + '._publishRemove(id, alias, idRemoved, [socketToOmit])`' ); } - if (_.isFunction(this.beforePublishRemove)) { - this.beforePublishRemove(id, alias, idRemoved, req); + if (_.isFunction(this._beforePublishRemove)) { + this._beforePublishRemove(id, alias, idRemoved, req); } // Coerce id to match the attribute type of the primary key of the model @@ -1037,24 +1037,24 @@ module.exports = function(sails) { reverseAssociation = _.find(reverseModel.associations, {alias: _.find(this.associations, {alias: alias}).via}); if (reverseAssociation) { - // If this is a many-to-many association, do a publishAdd for the + // If this is a many-to-many association, do a _publishAdd for the // other side. if (reverseAssociation.type === 'collection') { - reverseModel.publishRemove(idRemoved, reverseAssociation.alias, id, req, {noReverse:true}); + reverseModel._publishRemove(idRemoved, reverseAssociation.alias, id, req, {noReverse:true}); } - // Otherwise, do a publishUpdate + // Otherwise, do a _publishUpdate else { var data = {}; data[reverseAssociation.alias] = null; - reverseModel.publishUpdate(idRemoved, data, req, {noReverse:true}); + reverseModel._publishUpdate(idRemoved, data, req, {noReverse:true}); } } } - if (_.isFunction(this.afterPublishRemove)) { - this.afterPublishRemove(id, alias, idRemoved, req); + if (_.isFunction(this._afterPublishRemove)) { + this._afterPublishRemove(id, alias, idRemoved, req); } }, @@ -1068,7 +1068,7 @@ module.exports = function(sails) { * @param {Request|Socket} req - Optional request for broadcast. * @api private */ - publishCreate: function(models, req, options){ + _publishCreate: function(models, req, options){ var self = this; // Pluralize so we can use this method regardless of it is an array or not @@ -1076,7 +1076,7 @@ module.exports = function(sails) { //Publish all models _.each(models, function(values){ - self.publishCreateSingle(values, req, options); + self._publishCreateSingle(values, req, options); }); }, /** @@ -1089,7 +1089,7 @@ module.exports = function(sails) { * @api private */ - publishCreateSingle: function(values, req, options) { + _publishCreateSingle: function(values, req, options) { var self = this; var reverseAssociation; @@ -1097,14 +1097,14 @@ module.exports = function(sails) { if (_.isUndefined(values[this.primaryKey])) { return sails.log.error( - 'Invalid usage of publishCreate() :: ' + + 'Invalid usage of _publishCreate() :: ' + 'Values must have an `'+this.primaryKey+'`, instead got ::\n' + util.inspect(values) ); } - if (_.isFunction(this.beforePublishCreate)) { - this.beforePublishCreate(values, req); + if (_.isFunction(this._beforePublishCreate)) { + this._beforePublishCreate(values, req); } var id = values[this.primaryKey]; @@ -1144,13 +1144,13 @@ module.exports = function(sails) { if (!reverseAssociation) {return;} - // If this is a to-many association, do publishAdd on the other side + // If this is a to-many association, do _publishAdd on the other side // TODO -- support nested creates. For now, we can't tell if an object value here represents // a NEW object or an existing one, so we'll ignore it. if (reverseAssociation.type === 'collection' && !_.isObject(val)) { - ReferencedModel.publishAdd(val, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishAdd(val, reverseAssociation.alias, id, req, {noReverse:true}); } - // Otherwise do a publishUpdate + // Otherwise do a _publishUpdate // TODO -- support nested creates. For now, we can't tell if an object value here represents // a NEW object or an existing one, so we'll ignore it. else { @@ -1159,7 +1159,7 @@ module.exports = function(sails) { if (!_.isObject(val)) { pubData[reverseAssociation.alias] = id; - ReferencedModel.publishUpdate(val, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(val, pubData, req, {noReverse:true}); } } @@ -1183,12 +1183,12 @@ module.exports = function(sails) { if (_.isObject(pk)) { return; } - ReferencedModel.publishAdd(pk, reverseAssociation.alias, id, req, {noReverse:true}); + ReferencedModel._publishAdd(pk, reverseAssociation.alias, id, req, {noReverse:true}); }); } - // Otherwise do a publishUpdate + // Otherwise do a _publishUpdate else { // Alert any added models @@ -1200,7 +1200,7 @@ module.exports = function(sails) { } var pubData = {}; pubData[reverseAssociation.alias] = id; - ReferencedModel.publishUpdate(pk, pubData, req, {noReverse:true}); + ReferencedModel._publishUpdate(pk, pubData, req, {noReverse:true}); }); } @@ -1255,8 +1255,8 @@ module.exports = function(sails) { this.introduce(values[this.primaryKey]); } - if (_.isFunction(this.afterPublishCreate)) { - this.afterPublishCreate(values, req); + if (_.isFunction(this._afterPublishCreate)) { + this._afterPublishCreate(values, req); } }, diff --git a/test/hooks/pubsub/publishAdd.test.js b/test/hooks/pubsub/publishAdd.test.js index 81eecc34c..c36701981 100644 --- a/test/hooks/pubsub/publishAdd.test.js +++ b/test/hooks/pubsub/publishAdd.test.js @@ -13,7 +13,7 @@ var sailsIOClient = require('../../helpers/sails.io.js'); describe('Pubsub hook', function (){ - describe('publishAdd()', function (){ + describe('_publishAdd()', function (){ var app = Sails(); @@ -35,8 +35,8 @@ describe('Pubsub hook', function (){ }, 'POST /dock/:id/addVessel': function (req, res){ // (notice we're not actually doing anything to the database- - // this is just testing publishAdd) - app.models.dock.publishAdd(req.param('id'), 'vessels', req.param('vessel')); + // this is just testing _publishAdd) + app.models.dock._publishAdd(req.param('id'), 'vessels', req.param('vessel')); return res.send(); } }, @@ -135,7 +135,7 @@ describe('Pubsub hook', function (){ //////////////////////////////////////////////////////////////////////////////// describe('invoked with the id of the child record', function (){ - // Lenny triggers publishAdd with a vessel id + // Lenny triggers _publishAdd with a vessel id before(function (done){ clientSocks.lenny.post('/dock/1/addVessel', { vessel: 47 @@ -157,7 +157,7 @@ describe('Pubsub hook', function (){ describe('invoked with an object representing the child record', function (){ - // Lenny triggers publishAdd with an entire vessel object + // Lenny triggers _publishAdd with an entire vessel object before(function (done){ clientSocks.lenny.post('/dock/1/addVessel', { vessel: { @@ -184,7 +184,7 @@ describe('Pubsub hook', function (){ describe('invoked with an object representing the child record, but missing the primary key value', function (){ - // Larry triggers publishAdd with a vessel object with no PK value + // Larry triggers _publishAdd with a vessel object with no PK value before(function (done){ clientSocks.larry.post('/dock/1/addVessel', { vessel: { @@ -194,7 +194,7 @@ describe('Pubsub hook', function (){ if (jwr.error) { return done(jwr.error); } // // NOTE: - // publishAdd does not currently throw an error, in keeping with + // _publishAdd does not currently throw an error, in keeping with // the approach taken by the other methods there. // // This could be changed in the future. diff --git a/test/hooks/pubsub/publishCreate.test.js b/test/hooks/pubsub/publishCreate.test.js index 1c40dbec7..a922c49b2 100644 --- a/test/hooks/pubsub/publishCreate.test.js +++ b/test/hooks/pubsub/publishCreate.test.js @@ -12,7 +12,7 @@ var sailsIOClient = require('../../helpers/sails.io.js'); describe('Pubsub hook', function (){ - describe('publishCreate()', function (){ + describe('_publishCreate()', function (){ var app = Sails(); @@ -42,9 +42,9 @@ describe('Pubsub hook', function (){ routes: { 'POST /pet': function (req, res){ // (notice we're not actually doing anything to the database- - // this is just testing publishCreate) + // this is just testing _publishCreate) try { - app.models.pet.publishCreate({id: 1, randomData: 'helloWorld!'}); + app.models.pet._publishCreate({id: 1, randomData: 'helloWorld!'}); } catch (e) { return res.json(500, {error: e.message}); } @@ -126,7 +126,7 @@ describe('Pubsub hook', function (){ //////////////////////////////////////////////////////////////////////////////// describe('invoked with the id of the new record and some random data', function (){ - // Lenny triggers publishCreate with a new pet + // Lenny triggers _publishCreate with a new pet before(function (done){ clientSocks.lenny.post('/pet', { name: 'socks'