Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding services/factories in the registry. #96

Merged
merged 1 commit into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/ember-test-helpers/build-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function exposeRegistryMethodsWithoutDeprecations(container) {
}

export default function(resolver) {
var registry, container;
var fallbackRegistry, registry, container;
var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
});
Expand All @@ -41,10 +41,12 @@ export default function(resolver) {
}

if (Ember.Application.buildRegistry) {
registry = Ember.Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember.ComponentLookup);
fallbackRegistry = Ember.Application.buildRegistry(namespace);
fallbackRegistry.register('component-lookup:main', Ember.ComponentLookup);

registry = registry;
registry = new Ember.Registry({
fallback: fallbackRegistry
});
container = registry.container();
exposeRegistryMethodsWithoutDeprecations(container);
} else {
Expand Down
7 changes: 5 additions & 2 deletions lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export default Klass.extend({
this.container = items.container;
this.registry = items.registry;


var thingToRegisterWith = this.registry || this.container;
var router = resolver.resolve('router:main');
router = router || Ember.Router.extend();
Expand All @@ -253,7 +252,11 @@ export default Klass.extend({
thingToRegisterWith.register(fullName, resolver.resolve(normalizedFullName));
}

thingToRegisterWith.resolver = function() { };
if (this.registry) {
this.registry.fallback.resolver = function() {};
} else {
this.container.resolver = function() {};
}
},

_setupIntegratedContainer: function() {
Expand Down
29 changes: 28 additions & 1 deletion tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function moduleFor(fullName, description, callbacks) {
function setupRegistry() {
setResolverRegistry({
'component:x-foo': Ember.Component.extend(),
'component:not-the-subject': Ember.Component.extend()
'component:not-the-subject': Ember.Component.extend(),
'foo:thing': Ember.Object.extend({
fromDefaultRegistry: true
})
});
}

Expand Down Expand Up @@ -176,3 +179,27 @@ test("throws an error when declaring integration: true and needs in the same mod

ok(result, "should throw an Error when integration: true and needs are provided");
});

moduleFor('component:x-foo', 'should be able to override factories in integration mode', {
beforeSetup: function() {
setupRegistry();
},

integration: true
});

test('gets the default by default', function() {
var thing = this.container.lookup('foo:thing');

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

test('can override the default', function() {
this.registry.register('foo:thing', Ember.Object.extend({
notTheDefault: true
}));
var thing = this.container.lookup('foo:thing');

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