0
0
Fork 0

Optional setting of status code on redirect

This commit is contained in:
Stormwind 2012-11-30 19:13:41 +01:00
parent facd4f143b
commit 6b9f34cb61
2 changed files with 10 additions and 2 deletions

View File

@ -71,8 +71,8 @@ module Zero
#
# @param [String] location Redirect URL
#
def redirect(location)
self.status = 302
def redirect(location, status = 302)
self.status = status
self.header['Location'] = location
end

View File

@ -133,6 +133,14 @@ describe Zero::Response do
value[0].should eq(302)
value[1]['Location'].should eq('http://foo.bar/relocated/thingy')
end
it "sets the given status code and the given Location" do
subject.redirect('http://foo.bar/relocated/other_thingy', 307)
value = subject.to_a
value[0].should eq(307)
value[1]['Location'].should eq('http://foo.bar/relocated/other_thingy')
end
end
end