From b18873a34966ca700f5968626f45bdc46f80544a Mon Sep 17 00:00:00 2001 From: Spencer Price Date: Wed, 26 Apr 2017 15:13:09 -0700 Subject: [PATCH] [BUGFIX] controller replaceRoute in engine --- packages/ember-routing/lib/ext/controller.js | 2 +- .../tests/ext/controller_test.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/ember-routing/lib/ext/controller.js b/packages/ember-routing/lib/ext/controller.js index 28187b4d4e0..9f6333bba4d 100644 --- a/packages/ember-routing/lib/ext/controller.js +++ b/packages/ember-routing/lib/ext/controller.js @@ -211,7 +211,7 @@ ControllerMixin.reopen({ // target may be either another controller or a router let target = get(this, 'target'); let method = target.replaceRoute || target.replaceWith; - return method.apply(target, prefixRouteNameArg(target, args)); + return method.apply(target, prefixRouteNameArg(this, args)); } }); diff --git a/packages/ember-routing/tests/ext/controller_test.js b/packages/ember-routing/tests/ext/controller_test.js index 5e47c51cee1..ecde59cea44 100644 --- a/packages/ember-routing/tests/ext/controller_test.js +++ b/packages/ember-routing/tests/ext/controller_test.js @@ -30,3 +30,30 @@ QUnit.test('transitionToRoute considers an engine\'s mountPoint', function() { let queryParams = {}; strictEqual(controller.transitionToRoute(queryParams), queryParams, 'passes query param only transitions through'); }); + +QUnit.test('replaceRoute considers an engine\'s mountPoint', function() { + expect(4); + + let router = { + replaceWith(route) { + return route; + } + }; + + let engineInstance = buildOwner({ + ownerOptions: { + routable: true, + mountPoint: 'foo.bar' + } + }); + + let controller = Controller.create({ target: router }); + setOwner(controller, engineInstance); + + strictEqual(controller.replaceRoute('application'), 'foo.bar.application', 'properly prefixes application route'); + strictEqual(controller.replaceRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes'); + throws(() => controller.replaceRoute('/posts'), 'throws when trying to use a url'); + + let queryParams = {}; + strictEqual(controller.replaceRoute(queryParams), queryParams, 'passes query param only transitions through'); +});