Permalink
Browse files

register the test authenticator via the app

  • Loading branch information...
1 parent 93a17d4 commit 6d1d2239780e18b5f0a63c82f20db399ae9a8f06 @marcoow marcoow committed Sep 7, 2015
@@ -1,8 +0,0 @@
-import Ember from 'ember';
-import Test from '../authenticators/test';
-
-export default function setupTesting(registry) {
- if (Ember.testing) {
- registry.register('authenticator:test', Test);
- }
-}
@@ -4,7 +4,6 @@ import setupSessionStores from 'ember-simple-auth/initializers/setup-session-sto
import setupSession from 'ember-simple-auth/initializers/setup-session';
import setupSessionService from 'ember-simple-auth/initializers/setup-session-service';
import setupAuthorizers from 'ember-simple-auth/initializers/setup-authorizers';
-import setupTesting from 'ember-simple-auth/initializers/setup-testing';
export default {
name: 'ember-simple-auth',
@@ -15,6 +14,5 @@ export default {
setupSession(registry);
setupSessionService(registry);
setupAuthorizers(registry);
- setupTesting(registry);
}
};
@@ -1,6 +1,19 @@
+import Test from 'ember-simple-auth/authenticators/test';
+
+const TEST_CONTAINER_KEY = 'authenticator:test';
+
+function ensureAuthenticator(app, container) {
+ const authenticator = container.lookup(TEST_CONTAINER_KEY);
+ if (!authenticator) {
+ app.register(TEST_CONTAINER_KEY, Test);
+ }
+}
+
export function authenticateSession(app, sessionData) {
- const session = app.__container__.lookup('service:session');
- session.authenticate('authenticator:test', sessionData);
+ const { __container__: container } = app;
+ const session = container.lookup('service:session');
+ ensureAuthenticator(app, container);
+ session.authenticate(TEST_CONTAINER_KEY, sessionData);
return wait();
};
@@ -1,24 +0,0 @@
-/* jshint expr:true */
-import { it } from 'ember-mocha';
-import { describe, beforeEach } from 'mocha';
-import { expect } from 'chai';
-import sinon from 'sinon';
-import Test from 'ember-simple-auth/authenticators/test';
-import setupTesting from 'ember-simple-auth/initializers/setup-testing';
-
-describe('setupTesting', () => {
- let registry;
-
- beforeEach(() => {
- registry = {
- register() {}
- };
- });
-
- it('registers the test authenticator', () => {
- sinon.spy(registry, 'register');
- setupTesting(registry);
-
- expect(registry.register).to.have.been.calledWith('authenticator:test', Test);
- });
-});

0 comments on commit 6d1d223

Please sign in to comment.