Permalink
Browse files

Add redirectsTo in routes

  • Loading branch information...
tomhuda
tomhuda committed May 24, 2012
1 parent 690e840 commit 91a8975b8d3a0b873b421f1dbc4ea41f92c92bc2
Showing with 64 additions and 0 deletions.
  1. +11 −0 packages/ember-states/lib/routable.js
  2. +53 −0 packages/ember-states/tests/routable_test.js
@@ -19,9 +19,20 @@ var paramForClass = function(classObject) {
Ember.Routable = Ember.Mixin.create({
init: function() {
var redirection;
this.on('connectOutlets', this, this.stashContext);
if (redirection = get(this, 'redirectsTo')) {
Ember.assert("You cannot use `redirectsTo` if you already have a `connectOutlets` method", this.connectOutlets === Ember.K);
this.connectOutlets = function(router) {
router.transitionTo(redirection);
};
}
this._super();
Ember.assert("You cannot use `redirectsTo` on a state that has child states", !redirection || (!!redirection && !!get(this, 'isLeaf')));
},
stashContext: function(manager, context) {
@@ -405,3 +405,56 @@ test("should use a specified String `modelType` in the default `deserialize`", f
router.route("/posts/1");
});
module("redirectsTo");
test("if a leaf state has a redirectsTo, it automatically transitions into that state", function() {
var router = Ember.Router.create({
initialState: 'root',
root: Ember.State.create({
index: Ember.State.create({
route: '/',
redirectsTo: 'someOtherState'
}),
someOtherState: Ember.State.create({
route: '/other'
})
})
});
Ember.run(function() {
router.route("/");
});
equal(router.getPath('currentState.path'), "root.someOtherState");
});
test("you cannot define connectOutlets AND redirectsTo", function() {
raises(function() {
Ember.Router.create({
initialState: 'root',
root: Ember.State.create({
index: Ember.State.create({
route: '/',
redirectsTo: 'someOtherState',
connectOutlets: function() {}
})
})
});
});
});
test("you cannot have a redirectsTo in a non-leaf state", function () {
raises(function() {
Ember.Router.create({
initialState: 'root',
root: Ember.State.create({
redirectsTo: 'someOtherState',
index: Ember.State.create()
})
});
});
});

0 comments on commit 91a8975

Please sign in to comment.