diff --git a/packages/ember-application/lib/system/application-instance.js b/packages/ember-application/lib/system/application-instance.js index f6d05f1a22e..f1793f34fb9 100644 --- a/packages/ember-application/lib/system/application-instance.js +++ b/packages/ember-application/lib/system/application-instance.js @@ -75,7 +75,6 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, { var application = get(this, 'application'); - set(this, 'customEvents', get(application, 'customEvents')); set(this, 'rootElement', get(application, 'rootElement')); // Create a per-instance registry that will use the application's registry @@ -188,7 +187,9 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, { */ setupEventDispatcher() { var dispatcher = this.lookup('event_dispatcher:main'); - dispatcher.setup(this.customEvents, this.rootElement); + var applicationCustomEvents = get(this.application, 'customEvents'); + + dispatcher.setup(applicationCustomEvents, this.rootElement); return dispatcher; }, diff --git a/packages/ember-application/tests/system/application_instance_test.js b/packages/ember-application/tests/system/application_instance_test.js index c5acdd1a6b1..40d21ab4a3a 100644 --- a/packages/ember-application/tests/system/application_instance_test.js +++ b/packages/ember-application/tests/system/application_instance_test.js @@ -65,3 +65,22 @@ QUnit.test('properties (and aliases) are correctly assigned for accessing the co strictEqual(appInstance.registry, appInstance.__registry__, '#registry alias should be assigned'); } }); + +QUnit.test('customEvents added to the application before setupEventDispatcher', function(assert) { + assert.expect(1); + + run(function() { + appInstance = ApplicationInstance.create({ application: app }); + }); + + app.customEvents = { + awesome: 'sauce' + }; + + var eventDispatcher = appInstance.lookup('event_dispatcher:main'); + eventDispatcher.setup = function(events) { + assert.equal(events.awesome, 'sauce'); + }; + + appInstance.setupEventDispatcher(); +}); diff --git a/packages/ember/tests/application_lifecycle.js b/packages/ember/tests/application_lifecycle_test.js similarity index 64% rename from packages/ember/tests/application_lifecycle.js rename to packages/ember/tests/application_lifecycle_test.js index e264f725837..be460ea4ca9 100644 --- a/packages/ember/tests/application_lifecycle.js +++ b/packages/ember/tests/application_lifecycle_test.js @@ -1,28 +1,38 @@ import 'ember'; import Ember from 'ember-metal/core'; +import isEnabled from 'ember-metal/features'; -var App, container, router; +var compile = Ember.HTMLBars.compile; -QUnit.module('Application Lifecycle', { - setup() { - Ember.run(function() { - App = Ember.Application.create({ - rootElement: '#qunit-fixture' - }); +var ApplicationSubclass, App, container, router; - App.Router = App.Router.extend({ - location: 'none' - }); - - App.deferReadiness(); +function setupApp() { + Ember.run(function() { + App = ApplicationSubclass.create({ + rootElement: '#qunit-fixture' + }); - container = App.__container__; + App.Router = App.Router.extend({ + location: 'none' }); + + App.deferReadiness(); + + container = App.__container__; + }); +} + +QUnit.module('Application Lifecycle', { + setup() { + ApplicationSubclass = Ember.Application.extend(); + + setupApp(); }, teardown() { router = null; Ember.run(App, 'destroy'); + Ember.TEMPLATES = {}; } }); @@ -113,3 +123,46 @@ QUnit.test('Destroying the application resets the router before the container is equal(Ember.controllerFor(container, 'home').get('selectedMenuItem'), null); equal(Ember.controllerFor(container, 'application').get('selectedMenuItem'), null); }); + +QUnit.test('initializers can augment an applications customEvents hash', function(assert) { + assert.expect(1); + + Ember.run(App, 'destroy'); + + if (isEnabled('ember-registry-container-reform')) { + ApplicationSubclass.initializer({ + name: 'customize-things', + initialize(application) { + application.customEvents = { + wowza: 'wowza' + }; + } + }); + } else { + ApplicationSubclass.initializer({ + name: 'customize-things', + initialize(registry, application) { + application.customEvents = { + wowza: 'wowza' + }; + } + }); + } + + setupApp(); + + App.FooBarComponent = Ember.Component.extend({ + wowza() { + assert.ok(true, 'fired the event!'); + } + }); + + Ember.TEMPLATES['application'] = compile(`{{foo-bar}}`); + Ember.TEMPLATES['components/foo-bar'] = compile(`
`); + + Ember.run(App, 'advanceReadiness'); + + Ember.run(function() { + Ember.$('#wowza-thingy').trigger('wowza'); + }); +});