Skip to content

Commit

Permalink
Merge pull request #11767 from martndemus/deprecate-needs
Browse files Browse the repository at this point in the history
[BUGFIX release] Deprecate Controller#needs
  • Loading branch information
rwjblue committed Jul 16, 2015
2 parents 5c704b6 + f795801 commit b19eb2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 5 additions & 2 deletions packages/ember-application/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function verifyNeedsDependencies(controller, container, needs) {
var defaultControllersComputedProperty = computed(function() {
var controller = this;

Ember.deprecate('Controller#needs is deprecated, please use Ember.inject.controller() instead');

return {
needs: get(controller, 'needs'),
container: get(controller, 'container'),
Expand Down Expand Up @@ -151,11 +153,11 @@ ControllerMixin.reopen({
/**
@method controllerFor
@see {Ember.Route#controllerFor}
@deprecated Use `needs` instead
@deprecated Use `Ember.inject.controller()` instead.
@public
*/
controllerFor(controllerName) {
Ember.deprecate('Controller#controllerFor is deprecated, please use Controller#needs instead');
Ember.deprecate('Controller#controllerFor is deprecated, please use Ember.inject.controller() instead');
return controllerFor(get(this, 'container'), controllerName);
},

Expand All @@ -175,6 +177,7 @@ ControllerMixin.reopen({
```
@see {Ember.ControllerMixin#needs}
@deprecated Use `Ember.inject.controller()` instead.
@property {Object} controllers
@default null
@public
Expand Down
29 changes: 23 additions & 6 deletions packages/ember-application/tests/system/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Registry } from 'ember-runtime/system/container';
import { A } from 'ember-runtime/system/native_array';
import { computed } from 'ember-metal/computed';

QUnit.module('Controller dependencies');
QUnit.module('Controller dependencies [DEPRECATED]');

QUnit.test('If a controller specifies a dependency, but does not have a container it should error', function() {
var AController = Controller.extend({
Expand All @@ -29,7 +29,11 @@ QUnit.test('If a controller specifies a dependency, it is accessible', function(

registry.register('controller:posts', Controller.extend());

var postController = container.lookup('controller:post');
var postController;
expectDeprecation(function() {
postController = container.lookup('controller:post');
}, /Controller#needs is deprecated, please use Ember.inject.controller\(\) instead/);

var postsController = container.lookup('controller:posts');

equal(postsController, postController.get('controllers.posts'), 'controller.posts must be auto synthesized');
Expand Down Expand Up @@ -73,8 +77,14 @@ QUnit.test('Mixin sets up controllers if there is needs before calling super', f
registry.register('controller:posts', Controller.extend());

container.lookup('controller:posts').set('model', A(['a', 'b', 'c']));
deepEqual(['a', 'b', 'c'], container.lookup('controller:other').get('model.model').toArray());
deepEqual(['a', 'b', 'c'], container.lookup('controller:another').get('model.model').toArray());

expectDeprecation(function() {
deepEqual(['a', 'b', 'c'], container.lookup('controller:other').get('model.model').toArray());
}, /Controller#needs is deprecated, please use Ember.inject.controller\(\) instead/);

expectDeprecation(function() {
deepEqual(['a', 'b', 'c'], container.lookup('controller:another').get('model.model').toArray());
}, /Controller#needs is deprecated, please use Ember.inject.controller\(\) instead/);
});

QUnit.test('raises if trying to get a controller that was not pre-defined in `needs`', function() {
Expand All @@ -87,7 +97,10 @@ QUnit.test('raises if trying to get a controller that was not pre-defined in `ne
}));

var fooController = container.lookup('controller:foo');
var barController = container.lookup('controller:bar');
var barController;
expectDeprecation(function() {
barController = container.lookup('controller:bar');
}, /Controller#needs is deprecated, please use Ember.inject.controller\(\) instead/);

throws(function() {
fooController.get('controllers.bar');
Expand All @@ -112,7 +125,11 @@ QUnit.test('setting the value of a controller dependency should not be possible'

registry.register('controller:posts', Controller.extend());

var postController = container.lookup('controller:post');
var postController;
expectDeprecation(function() {
postController = container.lookup('controller:post');
}, /Controller#needs is deprecated, please use Ember.inject.controller\(\) instead/);

container.lookup('controller:posts');

throws(function() {
Expand Down
4 changes: 2 additions & 2 deletions packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,8 @@ QUnit.test('the {{link-to}} helper does not throw an error if its route has exit
Ember.TEMPLATES.application = compile('{{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}{{#link-to \'post\' defaultPost id=\'default-post-link\'}}Default Post{{/link-to}}{{#if currentPost}}{{#link-to \'post\' id=\'post-link\'}}Post{{/link-to}}{{/if}}');

App.ApplicationController = Ember.Controller.extend({
needs: ['post'],
currentPost: Ember.computed.alias('controllers.post.model')
postController: Ember.inject.controller('post'),
currentPost: Ember.computed.alias('postController.model')
});

App.PostController = Ember.Controller.extend({
Expand Down

0 comments on commit b19eb2c

Please sign in to comment.