Skip to content

Commit

Permalink
Merge pull request #113 from rwjblue/fix-normalization-for-primary-re…
Browse files Browse the repository at this point in the history
…gistry

Fix issues with normalization in primary (non-fallback) registry.
  • Loading branch information
dgeb committed Oct 21, 2015
2 parents 0ff87cd + d4f0266 commit 165af78
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/ember-test-helpers/build-registry.js
Expand Up @@ -47,6 +47,15 @@ export default function(resolver) {
registry = new Ember.Registry({
fallback: fallbackRegistry
});

// these properties are set on the fallback registry by `buildRegistry`
// and on the primary registry within the ApplicationInstance constructor
// but we need to manually recreate them since ApplicationInstance's are not
// exposed externally
registry.normalizeFullName = fallbackRegistry.normalizeFullName;
registry.makeToString = fallbackRegistry.makeToString;
registry.describe = fallbackRegistry.describe;

container = registry.container();
exposeRegistryMethodsWithoutDeprecations(container);
} else {
Expand Down
31 changes: 31 additions & 0 deletions tests/test-module-test.js
Expand Up @@ -15,7 +15,11 @@ function setupRegistry() {
'component:not-the-subject': Ember.Component.extend(),
'foo:thing': Ember.Object.extend({
fromDefaultRegistry: true
}),
'service:other-thing': Ember.Object.extend({
fromDefaultRegistry: true
})

});
}

Expand Down Expand Up @@ -203,4 +207,31 @@ if (hasEmberVersion(1,11)) {
ok(!thing.fromDefaultRegistry, 'should not be found from the default registry');
ok(thing.notTheDefault, 'found from the overridden factory');
});

test('gets the default with fullName normalization by default', function() {
this.register('foo:needs-service', Ember.Object.extend({
otherThing: Ember.inject.service()
}));

var foo = this.container.lookup('foo:needs-service');
var thing = foo.get('otherThing');

ok(thing.fromDefaultRegistry, 'found from the default registry');
});

test('can override the default with fullName normalization', function() {
this.register('service:other-thing', Ember.Object.extend({
notTheDefault: true
}));

this.register('foo:needs-service', Ember.Object.extend({
otherThing: Ember.inject.service()
}));

var foo = this.container.lookup('foo:needs-service');
var thing = foo.get('otherThing');

ok(!thing.fromDefaultRegistry, 'should not be found from the default registry');
ok(thing.notTheDefault, 'found from the overridden factory');
});
}

0 comments on commit 165af78

Please sign in to comment.