diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract/layouts_test.rb | 26 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 51 | ||||
-rw-r--r-- | actionpack/test/dispatch/mount_test.rb | 2 |
4 files changed, 73 insertions, 17 deletions
diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index de6f42d826..61d35756b1 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -14,7 +14,10 @@ module AbstractControllerTests "layouts/overwrite.erb" => "Overwrite <%= yield %>", "layouts/with_false_layout.erb" => "False Layout <%= yield %>", "abstract_controller_tests/layouts/with_string_implied_child.erb" => - "With Implied <%= yield %>" + "With Implied <%= yield %>", + "abstract_controller_tests/layouts/with_grand_child_of_implied.erb" => + "With Grand Child <%= yield %>" + )] end @@ -57,16 +60,16 @@ module AbstractControllerTests layout "hello_override" end - class WithNilChild < WithString - layout nil - end - class WithStringImpliedChild < WithString end class WithChildOfImplied < WithStringImpliedChild end + class WithGrandChildOfImplied < WithStringImpliedChild + layout nil + end + class WithProc < Base layout proc { |c| "overwrite" } @@ -262,12 +265,6 @@ module AbstractControllerTests assert_equal "With Implied Hello string!", controller.response_body end - test "when a child controller specifies layout nil, do not use the parent layout" do - controller = WithNilChild.new - controller.process(:index) - assert_equal "Hello string!", controller.response_body - end - test "when a grandchild has no layout specified, the child has an implied layout, and the " \ "parent has specified a layout, use the child controller layout" do controller = WithChildOfImplied.new @@ -275,6 +272,13 @@ module AbstractControllerTests assert_equal "With Implied Hello string!", controller.response_body end + test "when a grandchild has nil layout specified, the child has an implied layout, and the " \ + "parent has specified a layout, use the child controller layout" do + controller = WithGrandChildOfImplied.new + controller.process(:index) + assert_equal "With Grand Child Hello string!", controller.response_body + end + test "raises an exception when specifying layout true" do assert_raises ArgumentError do Object.class_eval do diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 243bad8749..f42a04d670 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -25,6 +25,8 @@ end class TestController < ActionController::Base protect_from_forgery + before_filter :set_variable_for_layout + class LabellingFormBuilder < ActionView::Helpers::FormBuilder end @@ -364,17 +366,14 @@ class TestController < ActionController::Base end def layout_test_with_different_layout - @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_string_action - @variable_for_layout = nil render "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_symbol_action - @variable_for_layout = nil render :hello_world, :layout => "standard" end @@ -383,7 +382,6 @@ class TestController < ActionController::Base end def layout_overriding_layout - @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end @@ -666,8 +664,11 @@ class TestController < ActionController::Base private + def set_variable_for_layout + @variable_for_layout = nil + end + def determine_layout - @variable_for_layout ||= nil case action_name when "hello_world", "layout_test", "rendering_without_layout", "rendering_nothing_on_layout", "render_text_hello_world", diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 062fc1f94e..f40d663ae8 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -85,6 +85,57 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs.clear! end + def test_class_and_lambda_constraints + subdomain = Class.new { + def matches? request + request.subdomain.present? and request.subdomain != 'clients' + end + } + + @rs.draw do + match '/', :constraints => subdomain.new, + :to => lambda { |env| [200, {}, 'default'] } + match '/', :constraints => { :subdomain => 'clients' }, + :to => lambda { |env| [200, {}, 'clients'] } + end + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'default', body + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'clients', body + end + + def test_lambda_constraints + @rs.draw do + match '/', :constraints => lambda { |req| + req.subdomain.present? and req.subdomain != "clients" }, + :to => lambda { |env| [200, {}, 'default'] } + + match '/', :constraints => lambda { |req| + req.subdomain.present? && req.subdomain == "clients" }, + :to => lambda { |env| [200, {}, 'clients'] } + end + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'default', body + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'clients', body + end + def test_draw_with_block_arity_one_raises assert_raise(RuntimeError) do @rs.draw { |map| map.match '/:controller(/:action(/:id))' } diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index 1a032539b9..f7a746120e 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -51,4 +51,4 @@ class TestRoutingMount < ActionDispatch::IntegrationTest get "/fakeengine" assert_equal "OK", response.body end -end
\ No newline at end of file +end |