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

[BUGFIX release] Ensure injected property assertion checks container. #13335

Merged
merged 1 commit into from
Apr 14, 2016
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
2 changes: 1 addition & 1 deletion packages/ember-metal/lib/injected_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function InjectedProperty(type, name) {

function injectedPropertyGet(keyName) {
var desc = this[keyName];
let owner = getOwner(this);
let owner = getOwner(this) || this.container; // fallback to `container` for backwards compat

assert(`InjectedProperties should be defined with the Ember.inject computed property macros.`, desc && desc.isDescriptor && desc.type);
assert(`Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`, owner);
Expand Down
17 changes: 16 additions & 1 deletion packages/ember-metal/tests/injected_property_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ QUnit.test('injected properties should be overridable', function() {
equal(get(obj, 'foo'), 'bar', 'should return the overriden value');
});

QUnit.test('getting on an object without a container should fail assertion', function() {
QUnit.test('getting on an object without an owner or container should fail assertion', function() {
var obj = {};
defineProperty(obj, 'foo', new InjectedProperty('type', 'name'));

Expand All @@ -31,6 +31,21 @@ QUnit.test('getting on an object without a container should fail assertion', fun
}, /Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container./);
});

QUnit.test('getting on an object without an owner but with a container should not fail', function() {
var obj = {
container: {
lookup(key) {
ok(true, 'should call container.lookup');
return key;
}
}
};

defineProperty(obj, 'foo', new InjectedProperty('type', 'name'));

equal(get(obj, 'foo'), 'type:name', 'should return the value of container.lookup');
});

QUnit.test('getting should return a lookup on the container', function() {
expect(2);

Expand Down