Skip to content

Commit

Permalink
Merge pull request #13335 from rwjblue/fix-regression-in-injected-pro…
Browse files Browse the repository at this point in the history
…perties

[BUGFIX release] Ensure injected property assertion checks `container`.
  • Loading branch information
dgeb committed Apr 14, 2016
2 parents 8efc15c + 8c15226 commit 265da6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 265da6d

Please sign in to comment.