Another use of blake's custom options conditions

Can you come up with a better test name/description?
This commit is contained in:
Simon Rozet 2009-04-07 02:57:52 +02:00 committed by Ryan Tomayko
parent b8b9072a1a
commit ecdd24adbe
1 changed files with 22 additions and 13 deletions

View File

@ -693,29 +693,38 @@ class RoutingTest < Test::Unit::TestCase
assert_equal 'ab', body
end
it 'allows for condition helper sugar' do
condition_helpers = Module.new {
def custom_condition_fu(one, two)
condition { one == 1 && two == 2 }
it 'allows custom route-conditions to be set via route options' do
protector = Module.new {
def protect(*args)
condition {
unless authorize(params["user"], params["password"])
halt 403, "go away"
end
}
end
}
Sinatra::Base.register(condition_helpers)
mock_app {
get '/notit', :custom_condition_fu => [0, 0] do
'notit'
register protector
helpers do
def authorize(username, password)
username == "foo" && password == "bar"
end
end
get '/it', :custom_condition_fu => [1, 2] do
'it'
get "/", :protect => true do
"hey"
end
}
get '/notit'
assert not_found?
get "/"
assert forbidden?
assert_equal "go away", body
get '/it'
get "/", :user => "foo", :password => "bar"
assert ok?
assert_equal "hey", body
end
# NOTE Block params behaves differently under 1.8 and 1.9. Under 1.8, block