This commit is contained in:
Ritchie Martori 2014-04-16 07:39:13 -07:00
commit 83e74ab414
3 changed files with 7 additions and 5 deletions

View File

@ -88,7 +88,7 @@ Change.setup();
* @param {Array} changes Changes that were tracked
*/
Change.track = function(modelName, modelIds, callback) {
Change.rectifyModelChanges = function(modelName, modelIds, callback) {
var tasks = [];
var Change = this;
@ -127,6 +127,7 @@ Change.idForModel = function(modelName, modelId) {
*/
Change.findOrCreate = function(modelName, modelId, callback) {
assert(loopback.getModel(modelName), modelName + ' does not exist');
var id = this.idForModel(modelName, modelId);
var Change = this;

View File

@ -596,6 +596,7 @@ Model.getChangeModel = function() {
assert(this.dataSource, 'Cannot getChangeModel(): ' + this.modelName
+ ' is not attached to a dataSource');
changeModel.attachTo(this.dataSource);
return changeModel;
}
@ -631,7 +632,7 @@ Model.enableChangeTracking = function() {
var cleanupInterval = Model.settings.changeCleanupInterval || 30000;
Model.on('changed', function(obj) {
Change.track(Model.modelName, [obj.id], function(err) {
Change.rectifyModelChanges(Model.modelName, [obj.id], function(err) {
if(err) {
console.error(Model.modelName + ' Change Tracking Error:');
console.error(err);
@ -640,7 +641,7 @@ Model.enableChangeTracking = function() {
});
Model.on('deleted', function(obj) {
Change.track(Model.modelName, [obj.id], function(err) {
Change.rectifyModelChanges(Model.modelName, [obj.id], function(err) {
if(err) {
console.error(Model.modelName + ' Change Tracking Error:');
console.error(err);

View File

@ -42,11 +42,11 @@ describe('Change', function(){
});
});
describe('Change.track(modelName, modelIds, callback)', function () {
describe('Change.rectifyModelChanges(modelName, modelIds, callback)', function () {
describe('using an existing untracked model', function () {
beforeEach(function(done) {
var test = this;
Change.track(this.modelName, [this.modelId], function(err, trakedChagnes) {
Change.rectifyModelChanges(this.modelName, [this.modelId], function(err, trakedChagnes) {
if(err) return done(err);
test.trakedChagnes = trakedChagnes;
done();