Skip to content

Commit

Permalink
Fixed issue with infinite recursion when loading packages with relati…
Browse files Browse the repository at this point in the history
…onships. Fixes #22

Turned out to be a simple typo, added unit tests to prevent regressions.
  • Loading branch information
aron committed Jul 25, 2011
1 parent 5ddf390 commit 5ce5414
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CKAN.Model = function ($, _, Backbone, undefined) {

// Provide the dataset key if not already there and current model is
// not a relationship.
if (isLiteral && key !== 'relationship') {
if (isLiteral && key !== 'relationships') {
model.dataset = this;
delete model.package_id;
}
Expand Down
7 changes: 5 additions & 2 deletions test/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ test("._updateChildren()", function () {
resources = dataset.get('resources'),
relationships = dataset.get('relationships'),
existingResources = [new CKAN.Model.Resource({id: 1}), new CKAN.Model.Resource({id: 2})],
newResources = [{id: 3}, {id: 4}, {id: 2, title: 'New title'}],
newResources = [{id: 3, package_id: 1}, {id: 4}, {id: 2, title: 'New title'}],
newRelationships = [{id: 3}];

resources.add(existingResources);
Expand All @@ -133,9 +133,12 @@ test("._updateChildren()", function () {
ok(resources.add.calledWith(newResources[0]), 'Expected resources.add() to have been called with model');
ok(resources.add.calledWith(newResources[1]), 'Expected resources.add() to have been called with model');
ok(existingResources[1].set.calledWith(newResources[2]), 'Expected model.set() to have been called with new data');
equal(newResources[0].dataset, dataset, 'Expected resources to have a dataset assigned');
equal(newResources[0].package_id, undefined, 'Expected resources to have its package_id removed');

ok(relationships.add.calledOnce, 'Expected relationships.add() to have been called');

equal(newRelationships[0].dataset, undefined, 'Expected relationships not to have a dataset')

ok(resources.remove.calledOnce, 'Expected resources.remove() to have been called');
ok(resources.remove.calledWith([existingResources[0]]), 'Expected resources.remove() to have been called with array of models');
});
Expand Down

0 comments on commit 5ce5414

Please sign in to comment.