Skip to content

Commit

Permalink
Merge pull request #15176 from spencer516/controller-engine-replace-r…
Browse files Browse the repository at this point in the history
…oute

[BUGFIX] controller `replaceRoute` considers engine's mount point
  • Loading branch information
rwjblue authored Jul 19, 2017
2 parents f7f80ca + b18873a commit 8e7443f
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/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});

Expand Down
27 changes: 27 additions & 0 deletions packages/ember-routing/tests/ext/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 8e7443f

Please sign in to comment.