From f7519303ce8954bee9caaed124176ca82ac303ac Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 5 Jan 2017 17:38:42 -0500 Subject: [PATCH] [BUGFIX beta] Exempt routes that share a controller from duplicate assertion. --- packages/ember-routing/lib/system/router.js | 3 ++- .../overlapping_query_params_test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/ember-routing/lib/system/router.js b/packages/ember-routing/lib/system/router.js index 00794ace15e..fd79b318928 100644 --- a/packages/ember-routing/lib/system/router.js +++ b/packages/ember-routing/lib/system/router.js @@ -858,8 +858,9 @@ const EmberRouter = EmberObject.extend(Evented, { for (let i = 0; i < qpMeta.qps.length; i++) { let qp = qpMeta.qps[i]; let urlKey = qp.urlKey; + let qpOther = qpsByUrlKey[urlKey]; - if (qpsByUrlKey[urlKey]) { + if (qpOther && qpOther.controllerName !== qp.controllerName) { let otherQP = qpsByUrlKey[urlKey]; assert(`You're not allowed to have more than one controller property map to the same query param key, but both \`${otherQP.scopedPropertyName}\` and \`${qp.scopedPropertyName}\` map to \`${urlKey}\`. You can fix this by mapping one of the controller properties to a different query param key via the \`as\` config option, e.g. \`${otherQP.prop}: { as: \'other-${otherQP.prop}\' }\``, false); } diff --git a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js index 21eb460fe75..22f2333cb01 100644 --- a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js @@ -1,4 +1,5 @@ import { Controller } from 'ember-runtime'; +import { Route } from 'ember-routing'; import { run, Mixin } from 'ember-metal'; import { QueryParamTestCase, moduleFor } from 'internal-test-helpers'; @@ -106,6 +107,20 @@ moduleFor('Query Params - overlapping query param property names', class extends }); } + ['@test query params does not error when a query parameter exists for route instances that share a controller'](assert) { + assert.expect(1); + + let parentController = Controller.extend({ + queryParams: { page: 'page' } + }); + this.registerController('parent', parentController); + this.registerRoute('parent.child', Route.extend({controllerName: 'parent'})); + + return this.setupBase('/parent').then(() => { + this.transitionTo('parent.child', { queryParams: { page: 2 } }); + this.assertCurrentPath('/parent/child?page=2'); + }); + } ['@test query params in the same route hierarchy with the same url key get auto-scoped'](assert) { assert.expect(1);