mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
test and fix #call example
This commit is contained in:
parent
97620ef4ff
commit
039675f4b4
7 changed files with 23 additions and 6 deletions
|
@ -909,7 +909,7 @@ anderen Route gefordert wird. Um das zu erreichen, lässt sich +call+ nutzen:
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -884,7 +884,7 @@ servir. Para lograr esto, podés usar +call+:
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -912,7 +912,7 @@ simplement +call+ :
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -864,7 +864,7 @@ of calling another route. Simply use +call+ to achieve this:
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -859,7 +859,7 @@ Thin - это более производительный и функциона
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -844,7 +844,7 @@ Session被用来在请求之间保持状态。如果被激活,每一个用户
|
||||||
|
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
[status, body.upcase]
|
[status, headers, body.map(&:upcase)]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bar' do
|
get '/bar' do
|
||||||
|
|
|
@ -1043,6 +1043,23 @@ class RoutingTest < Test::Unit::TestCase
|
||||||
assert not_found?
|
assert not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows using call to fire another request internally' do
|
||||||
|
mock_app do
|
||||||
|
get '/foo' do
|
||||||
|
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
||||||
|
[status, headers, body.map(&:upcase)]
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/bar' do
|
||||||
|
"bar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/foo'
|
||||||
|
assert ok?
|
||||||
|
assert_body "BAR"
|
||||||
|
end
|
||||||
|
|
||||||
it 'plays well with other routing middleware' do
|
it 'plays well with other routing middleware' do
|
||||||
middleware = Sinatra.new
|
middleware = Sinatra.new
|
||||||
inner_app = Sinatra.new { get('/foo') { 'hello' } }
|
inner_app = Sinatra.new { get('/foo') { 'hello' } }
|
||||||
|
|
Loading…
Reference in a new issue