From f64f214552dde3f7b853504766040af701e29302 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sun, 1 Mar 2015 10:15:50 -0500 Subject: [PATCH] [BUGFIX beta] Deprecate `{{link-to}}` unwrapping a controllers model. --- packages/ember-routing-htmlbars/lib/helpers/link-to.js | 3 +++ .../ember-routing-htmlbars/tests/helpers/link-to_test.js | 4 +++- packages/ember/tests/helpers/link_to_test.js | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/ember-routing-htmlbars/lib/helpers/link-to.js b/packages/ember-routing-htmlbars/lib/helpers/link-to.js index 3fa97a4c202..e1a78473818 100644 --- a/packages/ember-routing-htmlbars/lib/helpers/link-to.js +++ b/packages/ember-routing-htmlbars/lib/helpers/link-to.js @@ -288,6 +288,7 @@ import 'ember-htmlbars'; */ function linkToHelper(params, hash, options, env) { var queryParamsObject; + var view = env.data.view; Ember.assert("You must provide one or more parameters to the link-to helper.", params.length); @@ -321,6 +322,8 @@ function linkToHelper(params, hash, options, env) { if (!lazyValue._isController) { while (ControllerMixin.detect(lazyValue.value())) { + Ember.deprecate('Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. Please update `' + view + '` to use `{{link-to "post" someController.model}}` instead.'); + lazyValue = lazyValue.get('model'); } } diff --git a/packages/ember-routing-htmlbars/tests/helpers/link-to_test.js b/packages/ember-routing-htmlbars/tests/helpers/link-to_test.js index 921f9565e5d..a13e48db319 100644 --- a/packages/ember-routing-htmlbars/tests/helpers/link-to_test.js +++ b/packages/ember-routing-htmlbars/tests/helpers/link-to_test.js @@ -95,7 +95,9 @@ QUnit.test("unwraps controllers", function() { template: compile(template) }); - runAppend(view); + expectDeprecation(function() { + runAppend(view); + }, /Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated./); equal(view.$().text(), 'Text'); }); diff --git a/packages/ember/tests/helpers/link_to_test.js b/packages/ember/tests/helpers/link_to_test.js index 3ae9b1f057a..6232a258ae9 100644 --- a/packages/ember/tests/helpers/link_to_test.js +++ b/packages/ember/tests/helpers/link_to_test.js @@ -628,9 +628,9 @@ QUnit.test("Issue 4201 - Shorthand for route.index shouldn't throw errors about QUnit.test("The {{link-to}} helper unwraps controllers", function() { if (Ember.FEATURES.isEnabled('ember-routing-transitioning-classes')) { - expect(4); - } else { expect(5); + } else { + expect(6); } Router.map(function() { @@ -659,7 +659,9 @@ QUnit.test("The {{link-to}} helper unwraps controllers", function() { Ember.TEMPLATES.filter = compile('

{{model.filter}}

'); Ember.TEMPLATES.index = compile('{{#link-to "filter" this id="link"}}Filter{{/link-to}}'); - bootApplication(); + expectDeprecation(function() { + bootApplication(); + }, /Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated./); Ember.run(function() { router.handleURL("/"); });