From 7e2702cddc8738e04ae7bbe44111bade6f6af9f5 Mon Sep 17 00:00:00 2001 From: namusyaka Date: Wed, 15 Jan 2014 17:54:42 +0900 Subject: [PATCH] Add missing before/after tests with route name --- padrino-core/test/test_routing.rb | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb index af351578a..31e6c734b 100644 --- a/padrino-core/test/test_routing.rb +++ b/padrino-core/test/test_routing.rb @@ -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] }