Skip to content

Commit

Permalink
Project: toConfig() must not use stale relations
Browse files Browse the repository at this point in the history
Modify Project.toConfig() to always fetch the related models like model
and datasource definitions from the datastore, bypassing any possibly
stale cached values.

Related: strongloop/loopback#256
  • Loading branch information
Miroslav Bajtoš committed May 14, 2014
1 parent 0622dcc commit 9fab7cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Project.prototype.toConfig = function(cb) {

function findAndReduce(type) {
return function(cb) {
project[type](function(err, objects) {
var FORCE_RELOAD = true;
project[type](FORCE_RELOAD, function(err, objects) {
if(err) return cb(err);
config[type] = objects.reduce(reduce, {});
cb();
Expand Down
37 changes: 37 additions & 0 deletions test/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,43 @@ describe('Project', function () {
});
});
});

it('should ignore cached relations', function(done) {
var dir = SANDBOX;

async.waterfall([
function load(next) {
loadProject(next)
},
function fillProjectModelsCache(project, next) {
project.models(function(err) {
next(err, project);
});
},
function updateModelOptions(project, next) {
project.models(
{ where: { name: 'foo-bar'}, limit: 1},
function(err, res) {
if (err) return done(err);
var model = res[0];
model.options.newOption = true;
model.save(function(err) {
next(err, project);
});
});
},
function save(project, next) {
project.saveToFiles(dir, function(err) {
next(err, project);
});
},
function verify(project, next) {
var modelsJson = path.join(dir, 'models.json');
assertJSONFileHas(modelsJson, 'foo-bar.options.newOption', true);
next();
},
], done);
});
});

describe('project.getDataSourceByName(name, cb)', function () {
Expand Down

0 comments on commit 9fab7cc

Please sign in to comment.