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

Remove setOwner() calls #1164

Merged
merged 1 commit into from Jan 4, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/helpers/create-with-container.js
@@ -0,0 +1,14 @@
import Ember from 'ember';

const { setOwner } = Ember;

export default function createWithContainer(Constructor, options, container) {
if (setOwner) {
let instance = Constructor.create(options);
setOwner(instance, container);
return instance;
} else {
options.container = container;
return Constructor.create(options);
}
}
7 changes: 4 additions & 3 deletions tests/unit/internal-session-test.js
Expand Up @@ -7,7 +7,9 @@ import InternalSession from 'ember-simple-auth/internal-session';
import EphemeralStore from 'ember-simple-auth/session-stores/ephemeral';
import Authenticator from 'ember-simple-auth/authenticators/base';

const { RSVP, K, run: { next }, setOwner } = Ember;
import createWithContainer from '../helpers/create-with-container';

const { RSVP, K, run: { next } } = Ember;

describe('InternalSession', () => {
let session;
Expand All @@ -19,8 +21,7 @@ describe('InternalSession', () => {
container = { lookup() {} };
store = EphemeralStore.create();
authenticator = Authenticator.create();
session = InternalSession.create({ store });
setOwner(session, container);
session = createWithContainer(InternalSession, { store }, container);
sinon.stub(container, 'lookup').withArgs('authenticator').returns(authenticator);
});

Expand Down
12 changes: 5 additions & 7 deletions tests/unit/mixins/application-route-mixin-test.js
Expand Up @@ -7,7 +7,9 @@ import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mi
import InternalSession from 'ember-simple-auth/internal-session';
import EphemeralStore from 'ember-simple-auth/session-stores/ephemeral';

const { Route, run: { next }, setOwner } = Ember;
import createWithContainer from '../../helpers/create-with-container';

const { Route, run: { next } } = Ember;

describe('ApplicationRouteMixin', () => {
let session;
Expand All @@ -27,13 +29,9 @@ describe('ApplicationRouteMixin', () => {

containerMock.lookup.withArgs('service:cookies').returns(cookiesMock);

route = Route.extend(ApplicationRouteMixin, {
route = createWithContainer(Route.extend(ApplicationRouteMixin, {
transitionTo() {}
}).create({
session
});

setOwner(route, containerMock);
}), { session }, containerMock);
});

describe('mapping of service events to route methods', () => {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/mixins/authenticated-route-mixin-test.js
Expand Up @@ -8,7 +8,9 @@ import InternalSession from 'ember-simple-auth/internal-session';
import Configuration from 'ember-simple-auth/configuration';
import EphemeralStore from 'ember-simple-auth/session-stores/ephemeral';

const { Mixin, RSVP, Route, setOwner } = Ember;
import createWithContainer from '../../helpers/create-with-container';

const { Mixin, RSVP, Route } = Ember;

describe('AuthenticatedRouteMixin', () => {
let route;
Expand Down Expand Up @@ -46,14 +48,12 @@ describe('AuthenticatedRouteMixin', () => {
containerMock.lookup.withArgs('service:cookies').returns(cookiesMock);
containerMock.lookup.withArgs('service:fastboot').returns(fastbootMock);

route = Route.extend(MixinImplementingBeforeModel, AuthenticatedRouteMixin, {
route = createWithContainer(Route.extend(MixinImplementingBeforeModel, AuthenticatedRouteMixin, {
// pretend this is never FastBoot
_isFastBoot: false,
// replace actual transitionTo as the router isn't set up etc.
transitionTo() {}
}).create({ session });

setOwner(route, containerMock);
}), { session }, containerMock);

sinon.spy(transition, 'send');
sinon.spy(route, 'transitionTo');
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/services/session-test.js
Expand Up @@ -5,7 +5,9 @@ import { expect } from 'chai';
import sinon from 'sinon';
import Session from 'ember-simple-auth/services/session';

const { ObjectProxy, Evented, run: { next }, set, setOwner } = Ember;
import createWithContainer from '../../helpers/create-with-container';

const { ObjectProxy, Evented, run: { next }, set } = Ember;

describe('SessionService', () => {
let sessionService;
Expand All @@ -23,8 +25,7 @@ describe('SessionService', () => {
let stub = sinon.stub(container, 'lookup');
stub.withArgs('authorizer').returns(authorizer);
stub.withArgs('bad-authorizer').returns(undefined);
sessionService = Session.create({ session });
setOwner(sessionService, container);
sessionService = createWithContainer(Session, { session }, container);
});

it('forwards the "authenticationSucceeded" event from the session', (done) => {
Expand Down