diff --git a/.travis.yml b/.travis.yml index d933820..48d46c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,9 @@ before_install: install: - yarn install --no-lockfile +before_script: + - npm rebuild node-sass + script: # Usually, it's ok to finish the test scenario without reverting # to the addon's original dependency state, skipping "cleanup". diff --git a/addon/instance-initializers/ember-parachute.js b/addon/instance-initializers/ember-parachute.js index 29bc859..7645934 100644 --- a/addon/instance-initializers/ember-parachute.js +++ b/addon/instance-initializers/ember-parachute.js @@ -13,27 +13,6 @@ const { export function initialize(/* application */) { Ember.Route.reopen({ - actions: { - /** - * Route hook that fires when query params are changed. - * - * @public - * @param {object} [changed={}] - * @param {object} [present={}] - * @param {object} [removed={}] - * @returns {any} - */ - queryParamsDidChange(changed = {}, present = {}, removed = {}) { - let { controller, routeName } = this; - - if (QueryParams.hasParachute(controller)) { - this._scheduleParachuteChangeEvent(routeName, controller, assign({}, changed, removed)); - } - - return this._super(...arguments); - } - }, - /** * Serialize query param value if a given query param has a `serialize` * method. @@ -96,6 +75,27 @@ export function initialize(/* application */) { tryInvoke(controller, 'queryParamsDidChange', [changeEvent]); sendEvent(controller, 'queryParamsDidChange', [changeEvent]); }); + }, + + actions: { + /** + * Route hook that fires when query params are changed. + * + * @public + * @param {object} [changed={}] + * @param {object} [present={}] + * @param {object} [removed={}] + * @returns {any} + */ + queryParamsDidChange(changed = {}, present = {}, removed = {}) { + let { controller, routeName } = this; + + if (QueryParams.hasParachute(controller)) { + this._scheduleParachuteChangeEvent(routeName, controller, assign({}, changed, removed)); + } + + return this._super(...arguments); + } } }); } diff --git a/addon/utils/lookup-controller.js b/addon/utils/lookup-controller.js index 2fc7be4..7a42bab 100644 --- a/addon/utils/lookup-controller.js +++ b/addon/utils/lookup-controller.js @@ -11,5 +11,18 @@ const { get, getOwner } = Ember; * @returns {Ember.Controller} */ export default function lookupController(route, ownerLookupFn = getOwner) { - return route.controller || ownerLookupFn(route).lookup(`controller:${get(route, 'routeName')}`); + let controller = get(route, 'controller'); + + if (!controller) { + /** + * If the controller doesnt exist, use the class proto instead. Before, we + * would create the controller if it didnt exist which caused a lot of issues + * (especially with authentication) due to the controller being created + * prematurely. + */ + let factory = ownerLookupFn(route).factoryFor(`controller:${get(route, 'routeName')}`); + return factory.class.proto(); + } + + return controller; } diff --git a/tests/unit/utils/lookup-controller-test.js b/tests/unit/utils/lookup-controller-test.js index 3fb8cbe..b10ac89 100644 --- a/tests/unit/utils/lookup-controller-test.js +++ b/tests/unit/utils/lookup-controller-test.js @@ -1,25 +1,34 @@ +import Ember from 'ember'; import lookupController from 'ember-parachute/utils/lookup-controller'; import { module, test } from 'qunit'; module('Unit | Utility | lookup controller'); +const Controller = Ember.Controller.extend({ + parachuteController: true +}) + const dummyRoute = { - controller: { isController: true } + controller: Controller.create() } + function dummyLookup() { return { - lookup() { - return { isController: true }; + factoryFor() { + return { + create: () => Controller.create(), + class: Controller + }; } }; } test('it looks up the controller from a route', function(assert) { let result = lookupController(dummyRoute); - assert.ok(result.isController); + assert.ok(result.parachuteController); }); test('it looks up the controller from a route owner if route controller is not defined', function(assert) { let result = lookupController({}, dummyLookup); - assert.ok(result.isController); + assert.ok(result.parachuteController); });