Permalink
Browse files

Merge pull request #1269 from bradleypriest/controller-instantiation

Check that a controller inherits from Ember.Object before instantiating it to the router.
  • Loading branch information...
2 parents d838996 + 3cfc16e commit 2a4f8aab9d764e6d397e6a96e8ca95b672aaabc8 @wagenet wagenet committed Sep 10, 2012
@@ -434,7 +434,10 @@ Ember.Application.registerInjection({
if (!/^[A-Z].*Controller$/.test(property)) { return; }
var name = property.charAt(0).toLowerCase() + property.substr(1),
- controller = app[property].create();
+ controllerClass = app[property], controller;
+
+ if(!Ember.Object.detect(controllerClass)){ return; }
+ controller = app[property].create();
@devinus

devinus Sep 10, 2012

Member

You already defined controllerClass, can't this be controllerClass?

router.set(name, controller);
@@ -106,6 +106,7 @@ test("initialize controllers into a state manager", function() {
app.BarController = Ember.ArrayController.extend();
app.Foo = Ember.Object.create();
app.fooController = Ember.Object.create();
+ app.BazController = {};
var stateManager = Ember.Object.create();
@@ -114,6 +115,7 @@ test("initialize controllers into a state manager", function() {
ok(get(stateManager, 'fooController') instanceof app.FooController, "fooController was assigned");
ok(get(stateManager, 'barController') instanceof app.BarController, "barController was assigned");
ok(get(stateManager, 'foo') === undefined, "foo was not assigned");
+ ok(get(stateManager, 'bazController') === undefined, "bazController was not assigned");
equal(get(stateManager, 'fooController.target'), stateManager, "the state manager is assigned");
equal(get(stateManager, 'barController.target'), stateManager, "the state manager is assigned");

0 comments on commit 2a4f8aa

Please sign in to comment.