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

Calling router.map now appends the routes instead of replacing them #2892

Merged
merged 2 commits into from
Jun 26, 2013
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,26 @@ function transitionCompleted(router) {

Ember.Router.reopenClass({
map: function(callback) {
var router = this.router = new Router();
var router = this.router;
if (!router){
router = this.router = new Router();
router.callbacks = [];
}

if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
router.log = Ember.Logger.debug;
}

var dsl = Ember.RouterDSL.map(function() {
this.resource('application', { path: "/" }, function() {
for (var i=0; i < router.callbacks.length; i++){
router.callbacks[i].call(this);
}
callback.call(this);
});
});

router.callbacks.push(callback);
router.map(dsl.generate());
return router;
}
Expand Down
48 changes: 48 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module("Basic Routing", {
Ember.TEMPLATES.application = compile("{{outlet}}");
Ember.TEMPLATES.home = compile("<h3>Hours</h3>");
Ember.TEMPLATES.homepage = compile("<h3>Megatroll</h3><p>{{home}}</p>");
Ember.TEMPLATES.camelot = compile('<section><h3>Is a silly place</h3></section>');
});
},

Expand Down Expand Up @@ -74,6 +75,53 @@ test("The Homepage", function() {
equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
});

test("The Home page and the Camelot page with multiple Router.map calls", function() {
Router.map(function() {
this.route("home", { path: "/" });
});

Router.map(function() {
this.route("camelot", {path: "/camelot"});
});

App.HomeRoute = Ember.Route.extend({
});

App.CamelotRoute = Ember.Route.extend({
});

var currentPath;

App.ApplicationController = Ember.Controller.extend({
currentPathDidChange: Ember.observer(function() {
currentPath = get(this, 'currentPath');
}, 'currentPath')
});

App.CamelotController = Ember.Controller.extend({
currentPathDidChange: Ember.observer(function() {
currentPath = get(this, 'currentPath');
}, 'currentPath')
});

bootApplication();

Ember.run(function() {
router.handleURL("/camelot");
});

equal(currentPath, 'camelot');
equal(Ember.$('h3:contains(silly)', '#qunit-fixture').length, 1, "The camelot template was rendered");


Ember.run(function() {
router.handleURL("/");
});

equal(currentPath, 'home');
equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
});

test("The Homepage register as activeView", function() {
Router.map(function() {
this.route("home", { path: "/" });
Expand Down