summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStormwind <stormwind@stormwinds-page.de>2012-11-30 19:13:41 +0100
committerStormwind <stormwind@stormwinds-page.de>2012-11-30 19:13:41 +0100
commit6b9f34cb61c1169b75c22ff53dd50f7115120eed (patch)
tree0925f01f2a68d189e27837aad8fa4e0d3a3cb820
parentfacd4f143bb3f0bb44d89b6ff11e61a0b7c36427 (diff)
Optional setting of status code on redirect
-rw-r--r--lib/zero/response.rb4
-rw-r--r--spec/unit/response/response_spec.rb8
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/zero/response.rb b/lib/zero/response.rb
index a3e1651..15fb8c7 100644
--- a/lib/zero/response.rb
+++ b/lib/zero/response.rb
@@ -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
diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb
index 8edc48d..bc5199a 100644
--- a/spec/unit/response/response_spec.rb
+++ b/spec/unit/response/response_spec.rb
@@ -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 \ No newline at end of file