Skip to content

Commit

Permalink
changed the key that is used for the data summary to be the same as t…
Browse files Browse the repository at this point in the history
…he cacheKey for the object constructor:id
  • Loading branch information
Josh Callender committed Jul 29, 2014
1 parent 1c332e1 commit 75f74c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion server/viewEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ViewEngine.prototype.getBootstrappedData = function getBootstrappedData(locals,
_.each(list, function (value, key) {
if (app.modelUtils.isModel(value) || app.modelUtils.isCollection(value)) {
var tempObject = {},
key = (key !== value.cid && isNaN(parseInt(key))) ? key : value.cid;
key = app.modelUtils.modelName(value.constructor) + ':' + value.id

tempObject[key] = value;
_.defaults(bootstrappedData, scope.getBootstrappedData(tempObject, app));
Expand Down
37 changes: 19 additions & 18 deletions test/server/viewEngine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('ViewEngine', function() {

it('should create bootstrap data from models and collection', function () {
var locals = {
foo: new Model({ id: 321, foo: 'bar' }, { app: app }),
foo: new Model({ id: 321, foo: 'bar' }, { app: app }),
bar: new Collection([ new Model({ id: 123, foo: 'bar' }, { app: app} ) ], { app: app })
},
expectedData = {
Expand All @@ -97,7 +97,7 @@ describe('ViewEngine', function() {
},
data;

expectedData[locals.bar.models[0].cid] = {
expectedData['model:' + locals.bar.models[0].id] = {
data: { foo: 'bar', id: 123 },
summary: { model: 'model', id: 123 }
}
Expand All @@ -123,7 +123,7 @@ describe('ViewEngine', function() {
data: { bar: bar, id: 321 },
summary: { model: 'model', id: 321 }
},
bar: {
'model:123': {
data: { id: 123 },
summary: { model: 'model', id: 123 }
}
Expand All @@ -135,32 +135,33 @@ describe('ViewEngine', function() {
});

it('should create a flat bootstrap object if a model has a nested collection', function () {
var foo = new Model({ id: 321, foo: 'foo' }, { app: app }),
var foo = new Model({ id: 321, foo: 'foo' }, { app: app }),
baz = new Collection([foo], { app: app }),
bar = new Model({ id: 123, foo: 'bar', items: baz }, { app: app }),
bar = new Model({ id: 123, foo: 'bar', items: baz }, { app: app }),
locals = {
foo: foo,
bar: bar
},
expectedData = {
foo: {
data: { foo: 'foo', id: 321 },
summary: { model: 'model', id: 321 }
},
bar: {
data: { foo: 'bar', id: 123, items: baz },
summary: { model: 'model', id: 123 }
data: { foo: 'bar', id: 123, items: baz },
summary: { model: 'model', id: 123 }
},
items: {
data: [ { foo: 'foo', id: 321 } ],
summary: { collection: 'collection', ids: [ 321 ], meta: {}, params: {} }
'model:321': {
data: { foo: 'foo', id: 321 },
summary: { model: 'model', id: 321 }
}
},
data;

expectedData[baz.models[0].cid] = {
data: { foo: 'foo', id: 321 },
summary: { model: 'model', id: 321 }
baz.id = 111;
expectedData['collection:' + baz.id] = {
data: [{ foo: 'foo', id: 321 }],
summary: {
collection: 'collection',
ids: [321],
meta: {},
params: {}
}
};

data = viewEngine.getBootstrappedData(locals, app);
Expand Down

0 comments on commit 75f74c8

Please sign in to comment.