From 42c598680dd355e278c1746bf153c30b088eb1b6 Mon Sep 17 00:00:00 2001 From: Wesley Workman Date: Thu, 11 Sep 2014 15:05:49 -0400 Subject: [PATCH] Fixing an issue related to the ES6 resolver. `isolated-container` should call `resolver.normalize(fullName)` before attempting to lookup and inject `needs` values into the container. --- dist/amd/isolated-container.js | 3 ++- dist/cjs/isolated-container.js | 3 ++- dist/globals/main.js | 3 ++- dist/named-amd/main.js | 3 ++- lib/isolated-container.js | 3 ++- test/main.spec.js | 12 ++++++++++-- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dist/amd/isolated-container.js b/dist/amd/isolated-container.js index 1901285c..4a2751b5 100644 --- a/dist/amd/isolated-container.js +++ b/dist/amd/isolated-container.js @@ -15,7 +15,8 @@ define( container.register('component-lookup:main', Ember.ComponentLookup); for (var i = fullNames.length; i > 0; i--) { var fullName = fullNames[i - 1]; - container.register(fullName, resolver.resolve(fullName)); + var normalizedFullName = resolver.normalize(fullName); + container.register(fullName, resolver.resolve(normalizedFullName)); } return container; } diff --git a/dist/cjs/isolated-container.js b/dist/cjs/isolated-container.js index 977fee82..ab27019f 100644 --- a/dist/cjs/isolated-container.js +++ b/dist/cjs/isolated-container.js @@ -12,7 +12,8 @@ exports["default"] = function isolatedContainer(fullNames) { container.register('component-lookup:main', Ember.ComponentLookup); for (var i = fullNames.length; i > 0; i--) { var fullName = fullNames[i - 1]; - container.register(fullName, resolver.resolve(fullName)); + var normalizedFullName = resolver.normalize(fullName); + container.register(fullName, resolver.resolve(normalizedFullName)); } return container; } \ No newline at end of file diff --git a/dist/globals/main.js b/dist/globals/main.js index b1fdc8ed..91e1b137 100644 --- a/dist/globals/main.js +++ b/dist/globals/main.js @@ -13,7 +13,8 @@ exports["default"] = function isolatedContainer(fullNames) { container.register('component-lookup:main', Ember.ComponentLookup); for (var i = fullNames.length; i > 0; i--) { var fullName = fullNames[i - 1]; - container.register(fullName, resolver.resolve(fullName)); + var normalizedFullName = resolver.normalize(fullName); + container.register(fullName, resolver.resolve(normalizedFullName)); } return container; } diff --git a/dist/named-amd/main.js b/dist/named-amd/main.js index 283c4814..07328a54 100644 --- a/dist/named-amd/main.js +++ b/dist/named-amd/main.js @@ -15,7 +15,8 @@ define("ember-qunit/isolated-container", container.register('component-lookup:main', Ember.ComponentLookup); for (var i = fullNames.length; i > 0; i--) { var fullName = fullNames[i - 1]; - container.register(fullName, resolver.resolve(fullName)); + var normalizedFullName = resolver.normalize(fullName); + container.register(fullName, resolver.resolve(normalizedFullName)); } return container; } diff --git a/lib/isolated-container.js b/lib/isolated-container.js index 0293b9c4..e835a5b8 100644 --- a/lib/isolated-container.js +++ b/lib/isolated-container.js @@ -11,7 +11,8 @@ export default function isolatedContainer(fullNames) { container.register('component-lookup:main', Ember.ComponentLookup); for (var i = fullNames.length; i > 0; i--) { var fullName = fullNames[i - 1]; - container.register(fullName, resolver.resolve(fullName)); + var normalizedFullName = resolver.normalize(fullName); + container.register(fullName, resolver.resolve(normalizedFullName)); } return container; } diff --git a/test/main.spec.js b/test/main.spec.js index 3d23734e..ea45da5f 100644 --- a/test/main.spec.js +++ b/test/main.spec.js @@ -35,8 +35,9 @@ var registry = { 'template:components/pretty-color': 'Pretty Color: {{name}}'.compile(), 'route:foo': Ember.Route.extend(), 'controller:foos': Ember.ArrayController.extend(), + 'controller:hello-world': Ember.ObjectController.extend(), 'controller:bar': Ember.Controller.extend({ - needs: ['foos'] + needs: ['foos', 'helloWorld'] }), 'model:post': Post, 'model:comment': Comment, @@ -48,6 +49,9 @@ var registry = { var Resolver = Ember.DefaultResolver.extend({ resolve: function(fullName) { return registry[fullName] || this._super.apply(this, arguments); + }, + normalize: function(fullName) { + return Ember.String.dasherize(fullName); } }); @@ -74,27 +78,31 @@ setResolver(Resolver.create()); //}); moduleFor('controller:bar', 'moduleFor with bar controller', { - needs: ['controller:foos'] + needs: ['controller:foos', 'controller:helloWorld'] }); test('exists', function() { var bar = this.subject(); var foos = bar.get('controllers.foos'); + var helloWorld = bar.get('controllers.helloWorld'); ok(bar); ok(bar instanceof Ember.Controller); ok(foos instanceof Ember.ArrayController); + ok(helloWorld instanceof Ember.ObjectController); }); test('exists again', function() { var bar = this.subject(); var foos = bar.get('controllers.foos'); + var helloWorld = bar.get('controllers.helloWorld'); ok(bar); ok(bar instanceof Ember.Controller); ok(foos instanceof Ember.ArrayController); + ok(helloWorld instanceof Ember.ObjectController); }); moduleForModel('whazzit', 'moduleForModel whazzit without adapter');