Skip to content

Commit

Permalink
Merge pull request #4290 from jandet/willDestroy_reset_router
Browse files Browse the repository at this point in the history
[Bugfix BETA] App.destroy resets routes before destroying the container.
  • Loading branch information
stefanpenner committed Feb 2, 2014
2 parents bcc95df + 6d7c4d3 commit 461225c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ var Application = Ember.Application = Ember.Namespace.extend(Ember.DeferredMixin

willDestroy: function() {
Ember.BOOTED = false;
// Ensure deactivation of routes before objects are destroyed
this.__container__.lookup('router:main').reset();

this.__container__.destroy();
},
Expand Down
37 changes: 37 additions & 0 deletions packages/ember/tests/application_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,40 @@ test("Resetting the application allows controller properties to be set when a ro
equal(Ember.controllerFor(container, 'home').get('selectedMenuItem'), null);
equal(Ember.controllerFor(container, 'application').get('selectedMenuItem'), null);
});

test("Destroying the application resets the router before the container is destroyed", function() {
App.Router.map(function() {
this.route('home', { path: '/' });
});

App.HomeRoute = Ember.Route.extend({
setupController: function() {
this.controllerFor('home').set('selectedMenuItem', 'home');
},
deactivate: function() {
this.controllerFor('home').set('selectedMenuItem', null);
}
});
App.ApplicationRoute = Ember.Route.extend({
setupController: function() {
this.controllerFor('application').set('selectedMenuItem', 'home');
},
deactivate: function() {
this.controllerFor('application').set('selectedMenuItem', null);
}
});

var router = container.lookup('router:main');

Ember.run(App, 'advanceReadiness');

handleURL('/');

equal(Ember.controllerFor(container, 'home').get('selectedMenuItem'), 'home');
equal(Ember.controllerFor(container, 'application').get('selectedMenuItem'), 'home');

Ember.run(App, 'destroy');

equal(Ember.controllerFor(container, 'home').get('selectedMenuItem'), null);
equal(Ember.controllerFor(container, 'application').get('selectedMenuItem'), null);
});

0 comments on commit 461225c

Please sign in to comment.