diff --git a/packages/ember-routing-htmlbars/lib/keywords/render.js b/packages/ember-routing-htmlbars/lib/keywords/render.js index 9f3be67702f..82c18f6f7de 100644 --- a/packages/ember-routing-htmlbars/lib/keywords/render.js +++ b/packages/ember-routing-htmlbars/lib/keywords/render.js @@ -186,6 +186,7 @@ export default { } var parentController = read(scope.getLocal('controller')); + let target = parentController || router; var controller; // choose name @@ -195,8 +196,8 @@ export default { controller = factory.create({ model: read(context), - parentController: parentController, - target: parentController + parentController, + target }); node.addDestruction(controller); @@ -205,8 +206,8 @@ export default { generateController(owner, controllerName); controller.setProperties({ - target: parentController, - parentController: parentController + target, + parentController }); } diff --git a/packages/ember-routing-htmlbars/tests/helpers/render_test.js b/packages/ember-routing-htmlbars/tests/helpers/render_test.js index a85739b7a74..05b3d34ee59 100644 --- a/packages/ember-routing-htmlbars/tests/helpers/render_test.js +++ b/packages/ember-routing-htmlbars/tests/helpers/render_test.js @@ -21,6 +21,7 @@ function runSet(object, key, value) { }); } +const ORIGINAL_LEGACY_CONTROLLER_FLAG = Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT; var view, appInstance; QUnit.module('ember-routing-htmlbars: {{render}} helper', { @@ -29,6 +30,7 @@ QUnit.module('ember-routing-htmlbars: {{render}} helper', { }, teardown() { + Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = ORIGINAL_LEGACY_CONTROLLER_FLAG; runDestroy(appInstance); runDestroy(view); @@ -687,3 +689,38 @@ QUnit.test('{{render}} helper should not require view to provide its own templat equal(view.$().text(), 'Hello fish!'); }); + +QUnit.test('{{render}} helper should set router as target when parentController is not found', function() { + expect(2); + + Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false; + + let template = `{{render 'post' post1}}`; + + view = EmberView.create({ + [OWNER]: appInstance, + template: compile(template) + }); + + let postController; + let PostController = EmberController.extend({ + init() { + this._super(...arguments); + postController = this; + } + }); + + let routerStub = { + send(actionName) { + equal(actionName, 'someAction'); + ok(true, 'routerStub#send called'); + } + }; + appInstance.register('router:main', routerStub, { instantiate: false }); + appInstance.register('controller:post', PostController); + appInstance.register('template:post', compile('post template')); + + runAppend(view); + + postController.send('someAction'); +});