Browse files

Another use of blake's custom options conditions

Can you come up with a better test name/description?
  • Loading branch information...
1 parent b8b9072 commit ecdd24adbe35769ea3aad6f72adc8b6556b984b2 @sr sr committed with rtomayko Apr 7, 2009
Showing with 22 additions and 13 deletions.
  1. +22 −13 test/routing_test.rb
View
35 test/routing_test.rb
@@ -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

0 comments on commit ecdd24a

Please sign in to comment.