From 1744ed3504912f6b62d1e3c5b5d160c05c6f8196 Mon Sep 17 00:00:00 2001 From: Xavier Cambar Date: Mon, 23 Feb 2015 16:51:26 +0100 Subject: [PATCH] [BUGFIX beta] Ember.DefaultResolver resolves with hyphens. --- packages/ember-application/lib/system/resolver.js | 6 ++++++ .../system/dependency_injection/default_resolver_test.js | 6 ++++++ .../tests/system/dependency_injection/normalization_test.js | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/packages/ember-application/lib/system/resolver.js b/packages/ember-application/lib/system/resolver.js index 979f4fbecdd..be02a9d9c25 100644 --- a/packages/ember-application/lib/system/resolver.js +++ b/packages/ember-application/lib/system/resolver.js @@ -145,6 +145,12 @@ export default EmberObject.extend({ }); } + if (name.indexOf('-') > -1) { + result = result.replace(/-(.)/g, function(m) { + return m.charAt(1).toUpperCase(); + }); + } + return type + ':' + result; } else { return fullName; diff --git a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js index 181201d6ad4..91223f97527 100644 --- a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js +++ b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js @@ -160,6 +160,12 @@ QUnit.test('the default resolver resolves helpers on the namespace', function() equal(resolvedLegacyHandlebars, LegacyHandlebarsBoundHelper, 'resolves legacy Handlebars bound helper'); }); +QUnit.test('the default resolver resolves to the same instance no matter the notation ', function() { + application.NestedPostController = Controller.extend({}); + + equal(locator.lookup('controller:nested-post'), locator.lookup('controller:nested_post'), 'looks up NestedPost controller on application'); +}); + QUnit.test('the default resolver throws an error if the fullName to resolve is invalid', function() { throws(function() { registry.resolve(undefined);}, TypeError, /Invalid fullName/ ); throws(function() { registry.resolve(null); }, TypeError, /Invalid fullName/ ); diff --git a/packages/ember-application/tests/system/dependency_injection/normalization_test.js b/packages/ember-application/tests/system/dependency_injection/normalization_test.js index e00f29a21f7..a989e5b4335 100644 --- a/packages/ember-application/tests/system/dependency_injection/normalization_test.js +++ b/packages/ember-application/tests/system/dependency_injection/normalization_test.js @@ -22,14 +22,18 @@ QUnit.test('normalization', function() { equal(registry.normalize('controller:posts'), 'controller:posts'); equal(registry.normalize('controller:posts_index'), 'controller:postsIndex'); equal(registry.normalize('controller:posts.index'), 'controller:postsIndex'); + equal(registry.normalize('controller:posts-index'), 'controller:postsIndex'); equal(registry.normalize('controller:posts.post.index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:posts_post.index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:posts.post_index'), 'controller:postsPostIndex'); + equal(registry.normalize('controller:posts.post-index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:postsIndex'), 'controller:postsIndex'); equal(registry.normalize('controller:blogPosts.index'), 'controller:blogPostsIndex'); equal(registry.normalize('controller:blog/posts.index'), 'controller:blog/postsIndex'); + equal(registry.normalize('controller:blog/posts-index'), 'controller:blog/postsIndex'); equal(registry.normalize('controller:blog/posts.post.index'), 'controller:blog/postsPostIndex'); equal(registry.normalize('controller:blog/posts_post.index'), 'controller:blog/postsPostIndex'); + equal(registry.normalize('controller:blog/posts_post-index'), 'controller:blog/postsPostIndex'); equal(registry.normalize('template:blog/posts_index'), 'template:blog/posts_index'); });