Skip to content

Commit

Permalink
[query-params-new] Don't watch default model params obj
Browse files Browse the repository at this point in the history
Subtle bug fix with query-params-new, whereby if you
specified queryParams on your ObjectController but
didn't provide you own model hook, the Ember-supplied
model hook, which returns the params object as the 
model in certain cases, was resulting in that params
object being observed, when definitely should not be,
so we make a copy of the POJO before returning it
as the model

Fixes #4155
  • Loading branch information
machty committed Jan 21, 2014
1 parent 95e8503 commit 6a7b7cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ Ember.Route = Ember.Object.extend(Ember.ActionHandler, {
sawParams = true;
}

if (!name && sawParams) { return params; }
if (!name && sawParams) { return Ember.copy(params); }
else if (!name) { return; }

return this.findModel(name, value);
Expand Down
27 changes: 27 additions & 0 deletions packages/ember/tests/routing/query_params_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,31 @@ if (Ember.FEATURES.isEnabled("query-params-new")) {


});

test("Defaulting to params hash as the model should not result in that params object being watched", function() {
expect(1);

Router.map(function() {
this.route('other');
});

// This causes the params hash, which is returned as a route's
// model if no other model could be resolved given the provided
// params (and no custom model hook was defined), to be watched,
// unless we return a copy of the params hash.
App.ApplicationController = Ember.ObjectController.extend({
queryParams: ['woot']
});

App.OtherRoute = Ember.Route.extend({
model: function(p, trans) {
var m = Ember.meta(trans.params.application);
ok(!m.watching.woot, "A meta object isn't constructed for this params POJO");
}
});

bootApplication();

Ember.run(router, 'transitionTo', 'other');
});
}

0 comments on commit 6a7b7cd

Please sign in to comment.