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

Fix issues with normalization in primary (non-fallback) registry. #113

Merged
merged 1 commit into from
Oct 21, 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
9 changes: 9 additions & 0 deletions lib/ember-test-helpers/build-registry.js
Original file line number Diff line number Diff line change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, we should probably also set registry.describe = fallbackRegistry.describe;

See https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/application.js#L1347-L1349

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, this would not be consistent with the current ApplicationInstance init (although perhaps that should be updated to include describe as well?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgeb - Yes, I saw that and decided to match ApplicationInstance's init. This is exactly why I am suggesting a wrapAsFallback method to Ember.Registry that is aware of these things. It seems "wrong" that Ember.Application or ApplicationInstance (and ember-test-helpers) have to do the internal bookkeeping.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm happy to add describe here for now, but I really want to make up an API that can be used by all three parties involved here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to add .describe, please let me know what you think of a .wrap method or somesuch to make this cleaner from ApplicationInstance / ember-test-helpers perspective.

registry.describe = fallbackRegistry.describe;

container = registry.container();
exposeRegistryMethodsWithoutDeprecations(container);
} else {
Expand Down
31 changes: 31 additions & 0 deletions tests/test-module-test.js
Original file line number Diff line number Diff line change
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');
});
}