Skip to content

Commit

Permalink
[BUGFIX release] Ensure {{render}} sets up target properly.
Browse files Browse the repository at this point in the history
When the _ENABLE_LEGACY_CONTROLLER_SUPPORT flag is disabled, the
`controller` local is `undefined`. This causes the controller created by
`{{render}}` to have an undefined `target` (so it swallows any actions
triggered).

This properly sets the `target` to `router:main` if there is no
`parentController` present.

(cherry picked from commit 6f01942)
  • Loading branch information
rwjblue committed Mar 26, 2016
1 parent 382cb3a commit 39d6bef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/ember-routing-htmlbars/lib/keywords/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default {
}

var parentController = read(scope.getLocal('controller'));
let target = parentController || router;
var controller;

// choose name
Expand All @@ -195,8 +196,8 @@ export default {

controller = factory.create({
model: read(context),
parentController: parentController,
target: parentController
parentController,
target
});

node.addDestruction(controller);
Expand All @@ -205,8 +206,8 @@ export default {
generateController(owner, controllerName);

controller.setProperties({
target: parentController,
parentController: parentController
target,
parentController
});
}

Expand Down
37 changes: 37 additions & 0 deletions packages/ember-routing-htmlbars/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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);

Expand Down Expand Up @@ -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');
});

0 comments on commit 39d6bef

Please sign in to comment.