mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Sugar added: redirect back
This commit is contained in:
parent
585ea1032b
commit
8019e117f8
2 changed files with 17 additions and 0 deletions
|
@ -194,6 +194,10 @@ module Sinatra
|
||||||
halt 304 if etags.include?(value) || etags.include?('*')
|
halt 304 if etags.include?(value) || etags.include?('*')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## Sugar for redirect (example: redirect back)
|
||||||
|
def back ; request.referer ; end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Templates
|
module Templates
|
||||||
|
|
|
@ -65,4 +65,17 @@ describe 'Sinatra::Base' do
|
||||||
assert response.ok?
|
assert response.ok?
|
||||||
assert_equal 'not foo', response.body
|
assert_equal 'not foo', response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "makes redirecting back pretty" do
|
||||||
|
app = mock_app {
|
||||||
|
get '/foo' do
|
||||||
|
redirect back
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
request = Rack::MockRequest.new(app)
|
||||||
|
response = request.get('/foo', 'HTTP_REFERER' => 'http://github.com')
|
||||||
|
assert response.redirect?
|
||||||
|
assert_equal "http://github.com", response.location
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue