Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
c089 committed Jan 16, 2014
1 parent 24e1149 commit 974d5e8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/server/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function shouldMatchRoute(actual, expected) {
}

describe("server/router", function() {
var router;

beforeEach(function() {
this.router = new Router(config);
router = this.router = new Router(config);
});

describe("route", function() {
Expand Down Expand Up @@ -425,15 +426,21 @@ describe("server/router", function() {
});

describe('redirectTo', function () {
it("should redirect to another page", function () {
var rendrRoute = { controller: 'users', action: 'show' },
res = { redirect: sinon.spy() },
handler;
var rendrRoute, res;

beforeEach(function () {
rendrRoute = { controller: 'users', action: 'show' },
res = { redirect: sinon.spy() };
});

handler = this.router.getHandler(function () {
this.redirectTo('/some_uri');
function createHandler(options) {
return router.getHandler(function () {
this.redirectTo('/some_uri', options);
}, this.pattern, rendrRoute);
}

it("should redirect to another page", function () {
var handler = createHandler();
handler(this.req, res);

res.redirect.should.have.been.calledOnce;
Expand All @@ -442,14 +449,7 @@ describe("server/router", function() {
});

it("should redirect to another page using a specific http status code", function () {
var rendrRoute = { controller: 'users', action: 'show' },
res = { redirect: sinon.spy() },
handler;

handler = this.router.getHandler(function () {
this.redirectTo('/some_uri', {status: 301});
}, this.pattern, rendrRoute);

var handler = createHandler({status: 301});
handler(this.req, res);

res.redirect.should.have.been.calledOnce;
Expand Down

0 comments on commit 974d5e8

Please sign in to comment.