Skip to content

Commit

Permalink
Add missing before/after tests with route name
Browse files Browse the repository at this point in the history
  • Loading branch information
namusyaka authored and Ortuna committed Jan 17, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 379ab3e commit 7e2702c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions padrino-core/test/test_routing.rb
Original file line number Diff line number Diff line change
@@ -1488,6 +1488,51 @@ def authorize(username, password)
assert_equal '{"test"=>"what"}', body
end

should "work only for the given controller and route when using before-filter with route's name" do
mock_app do
controller :foo do
before(:index) { @a = "only to :index" }
get(:index) { @a }
get(:main) { @a }
end
end
get '/foo/'
assert_equal 'only to :index', body
get '/foo/main'
assert_equal '', body
end

should "work only for the given controller and route when using after-filter with route's name" do
mock_app do
controller :after_controller do
global = "global variable"
get(:index) { global }
get(:main) { global }
after(:index) { global = nil }
end
end
get '/after_controller'
assert_equal 'global variable', body
get '/after_controller'
assert_equal '', body
end

should "execute the before/after filters when they are inserted after the target route" do
mock_app do
controller :after_test do
global = "global variable"
get(:index) { global }
get(:foo) { global }
before(:index) { global.delete!(" ") }
after(:index) { global = "after" }
end
end
get '/after_test'
assert_equal 'globalvariable', body
get '/after_test/foo'
assert_equal 'after', body
end

should 'work with controller and arbitrary params' do
mock_app do
get(:testing) { params[:foo] }

0 comments on commit 7e2702c

Please sign in to comment.