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 beta] Ensure @controller passes args correctly #17868

Merged
merged 1 commit into from
Apr 8, 2019
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
46 changes: 0 additions & 46 deletions packages/@ember/-internals/runtime/tests/inject_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { inject } from '@ember/-internals/metal';
import { EMBER_NATIVE_DECORATOR_SUPPORT } from '@ember/canary-features';
import { DEBUG } from '@glimmer/env';
import EmberObject from '../lib/system/object';
import { buildOwner } from 'internal-test-helpers';
Expand Down Expand Up @@ -50,48 +49,3 @@ moduleFor(
}
}
);

if (EMBER_NATIVE_DECORATOR_SUPPORT) {
moduleFor(
'inject - decorator',
class extends AbstractTestCase {
['@test works with native decorators'](assert) {
let owner = buildOwner();

class Service extends EmberObject {}

class Foo extends EmberObject {
@inject('service', 'main') main;
}

owner.register('service:main', Service);
owner.register('foo:main', Foo);

let foo = owner.lookup('foo:main');

assert.ok(foo.main instanceof Service, 'service injected correctly');
}

['@test uses the decorated property key if not provided'](assert) {
let owner = buildOwner();

function service() {
return inject('service', ...arguments);
}

class Service extends EmberObject {}

class Foo extends EmberObject {
@service main;
}

owner.register('service:main', Service);
owner.register('foo:main', Foo);

let foo = owner.lookup('foo:main');

assert.ok(foo.main instanceof Service, 'service injected correctly');
}
}
);
}
4 changes: 2 additions & 2 deletions packages/@ember/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const Controller = EmberObject.extend(ControllerMixin);
@return {ComputedDecorator} injection decorator instance
@public
*/
export function inject(nameOrDesc, options) {
return metalInject('controller', nameOrDesc, options);
export function inject() {
return metalInject('controller', ...arguments);
}

export default Controller;
42 changes: 42 additions & 0 deletions packages/@ember/controller/tests/controller_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Controller, { inject as injectController } from '@ember/controller';
import { EMBER_NATIVE_DECORATOR_SUPPORT } from '@ember/canary-features';
import Service, { inject as injectService } from '@ember/service';
import { Object as EmberObject } from '@ember/-internals/runtime';
import { Mixin, get } from '@ember/-internals/metal';
Expand Down Expand Up @@ -207,3 +208,44 @@ moduleFor(
}
}
);

if (EMBER_NATIVE_DECORATOR_SUPPORT) {
moduleFor(
'Controller Injections',
class extends AbstractTestCase {
['@test works with native decorators'](assert) {
let owner = buildOwner();

class MainController extends Controller {}

class IndexController extends Controller {
@injectController('main') main;
}

owner.register('controller:main', MainController);
owner.register('controller:index', IndexController);

let index = owner.lookup('controller:index');

assert.ok(index.main instanceof Controller, 'controller injected correctly');
}

['@test uses the decorated property key if not provided'](assert) {
let owner = buildOwner();

class MainController extends Controller {}

class IndexController extends Controller {
@injectController main;
}

owner.register('controller:main', MainController);
owner.register('controller:index', IndexController);

let index = owner.lookup('controller:index');

assert.ok(index.main instanceof Controller, 'controller injected correctly');
}
}
);
}
46 changes: 46 additions & 0 deletions packages/@ember/service/tests/service_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { EMBER_NATIVE_DECORATOR_SUPPORT } from '@ember/canary-features';
import Service, { inject as injectService } from '@ember/service';
import { Object as EmberObject } from '@ember/-internals/runtime';
import { buildOwner } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

if (EMBER_NATIVE_DECORATOR_SUPPORT) {
moduleFor(
'inject - decorator',
class extends AbstractTestCase {
['@test works with native decorators'](assert) {
let owner = buildOwner();

class MainService extends Service {}

class Foo extends EmberObject {
@injectService('main') main;
}

owner.register('service:main', MainService);
owner.register('foo:main', Foo);

let foo = owner.lookup('foo:main');

assert.ok(foo.main instanceof Service, 'service injected correctly');
}

['@test uses the decorated property key if not provided'](assert) {
let owner = buildOwner();

class MainService extends Service {}

class Foo extends EmberObject {
@injectService main;
}

owner.register('service:main', MainService);
owner.register('foo:main', Foo);

let foo = owner.lookup('foo:main');

assert.ok(foo.main instanceof Service, 'service injected correctly');
}
}
);
}