diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-01-30 11:30:27 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-01-30 11:30:27 -0800 |
commit | 3030bc90c95e335d726f06fd7a61ed96055e9109 (patch) | |
tree | 5b079250b368f0e8af6d2f72a4278fdab3382b26 /actionpack/test | |
parent | ae42163bf5497849e4fcbb736505910c17640459 (diff) | |
parent | 85750f22c90c914a429116fb908990c5a2c68379 (diff) | |
download | rails-3030bc90c95e335d726f06fd7a61ed96055e9109.tar.gz rails-3030bc90c95e335d726f06fd7a61ed96055e9109.tar.bz2 rails-3030bc90c95e335d726f06fd7a61ed96055e9109.zip |
Merge commit 'rails/3-0-unstable'
Conflicts:
actionpack/lib/action_controller/base.rb
actionpack/lib/action_dispatch/http/mime_type.rb
actionpack/lib/action_dispatch/http/request.rb
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/paths.rb
actionpack/test/controller/session/cookie_store_test.rb
actionpack/test/dispatch/rack_test.rb
actionpack/test/dispatch/request_test.rb
Diffstat (limited to 'actionpack/test')
26 files changed, 182 insertions, 143 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 4baebcb4d1..12b60ddf3c 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -20,8 +20,7 @@ rescue LoadError end require 'action_controller' -require 'action_controller/cgi_ext' -require 'action_controller/test_process' +require 'action_controller/testing/process' require 'action_view/test_case' # Show backtraces for deprecated behavior for quicker cleanup. diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 7cd4e71aa1..6b409c9ae2 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -46,7 +46,7 @@ class DispatcherTest < Test::Unit::TestCase def test_failsafe_response Dispatcher.any_instance.expects(:dispatch).raises('b00m') - ActionController::Failsafe.any_instance.expects(:log_failsafe_exception) + ActionDispatch::Failsafe.any_instance.expects(:log_failsafe_exception) assert_nothing_raised do assert_equal [ diff --git a/actionpack/test/controller/header_test.rb b/actionpack/test/controller/header_test.rb deleted file mode 100644 index 33c14a187c..0000000000 --- a/actionpack/test/controller/header_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'abstract_unit' - -class HeaderTest < Test::Unit::TestCase - def setup - @headers = ActionController::Http::Headers.new("HTTP_CONTENT_TYPE"=>"text/plain") - end - - def test_content_type_works - assert_equal "text/plain", @headers["Content-Type"] - assert_equal "text/plain", @headers["content-type"] - assert_equal "text/plain", @headers["CONTENT_TYPE"] - assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"] - end -end diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 2f5e830fba..16c16aa88d 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -55,7 +55,7 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase def test_third_party_template_library_auto_discovers_layout @controller = ThirdPartyTemplateLibraryController.new get :hello - assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout.to_s + assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout(true).to_s assert_equal 'layouts/third_party_template_library', @response.layout assert_response :success assert_equal 'Mab', @response.body @@ -64,14 +64,14 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase def test_namespaced_controllers_auto_detect_layouts @controller = ControllerNameSpace::NestedController.new get :hello - assert_equal 'layouts/controller_name_space/nested', @controller.active_layout.to_s + assert_equal 'layouts/controller_name_space/nested', @controller.active_layout(true).to_s assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body end def test_namespaced_controllers_auto_detect_layouts @controller = MultipleExtensions.new get :hello - assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout.to_s + assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout(true).to_s assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip end end @@ -83,6 +83,14 @@ class HasOwnLayoutController < LayoutTest layout 'item' end +class OnlyLayoutController < LayoutTest + layout 'item', :only => "hello" +end + +class ExceptLayoutController < LayoutTest + layout 'item', :except => "goodbye" +end + class SetsLayoutInRenderController < LayoutTest def hello render :layout => 'third_party_template_library' @@ -107,6 +115,30 @@ class LayoutSetInResponseTest < ActionController::TestCase get :hello assert_equal 'layouts/item', @response.layout end + + def test_layout_only_exception_when_included + @controller = OnlyLayoutController.new + get :hello + assert_equal 'layouts/item', @response.layout + end + + def test_layout_only_exception_when_excepted + @controller = OnlyLayoutController.new + get :goodbye + assert_equal nil, @response.layout + end + + def test_layout_except_exception_when_included + @controller = ExceptLayoutController.new + get :hello + assert_equal 'layouts/item', @response.layout + end + + def test_layout_except_exception_when_excepted + @controller = ExceptLayoutController.new + get :goodbye + assert_equal nil, @response.layout + end def test_layout_set_when_using_render @controller = SetsLayoutInRenderController.new diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index dc59180a68..948e90254d 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -437,7 +437,7 @@ class MimeControllerTest < ActionController::TestCase unless args.empty? @action = args.first[:action] end - response.body = "#{@action} - #{@template.template_format}" + response.body = "#{@action} - #{@template.formats}" end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 584b9277c4..72b33629ff 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -345,7 +345,7 @@ class TestController < ActionController::Base end def accessing_params_in_template_with_layout - render :layout => nil, :inline => "Hello: <%= params[:name] %>" + render :layout => true, :inline => "Hello: <%= params[:name] %>" end def render_with_explicit_template @@ -1231,7 +1231,7 @@ class RenderTest < ActionController::TestCase assert !@response.headers.include?('Content-Length') assert_response :no_content - ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| + ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| get :head_with_symbolic_status, :status => status.to_s assert_equal code, @response.response_code assert_response status @@ -1239,7 +1239,7 @@ class RenderTest < ActionController::TestCase end def test_head_with_integer_status - ActionController::StatusCodes::STATUS_CODES.each do |code, message| + ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message| get :head_with_integer_status, :status => code.to_s assert_equal message, @response.message end @@ -1620,7 +1620,7 @@ class RenderingLoggingTest < ActionController::TestCase @controller.logger = MockLogger.new get :layout_test logged = @controller.logger.logged.find_all {|l| l =~ /render/i } - assert_equal "Rendering template within layouts/standard", logged[0] - assert_equal "Rendering test/hello_world", logged[1] + assert_equal "Rendering test/hello_world", logged[0] + assert_equal "Rendering template within layouts/standard", logged[1] end end diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 9f6b45f065..a2a2a3ee29 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -393,7 +393,7 @@ class RescueControllerTest < ActionController::TestCase def test_rescue_dispatcher_exceptions_without_request_set @request.env['REQUEST_URI'] = '/no_way' response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found")) - assert_kind_of ActionController::Response, response + assert_kind_of ActionDispatch::Response, response assert_equal "no way", response.body end diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 5fc79baa44..b703f340a0 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -155,7 +155,7 @@ class SendFileTest < ActionController::TestCase define_method "test_default_send_#{method}_status" do @controller.options = { :stream => false } assert_nothing_raised { assert_not_nil process(method) } - assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status + assert_equal ActionController::DEFAULT_RENDER_STATUS_CODE, @response.status end end end diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 95d2eb11c4..3a1a9854c3 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -6,7 +6,8 @@ class CookieStoreTest < ActionController::IntegrationTest SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' DispatcherApp = ActionController::Dispatcher.new - CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret) + CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp, + :key => SessionKey, :secret => SessionSecret) Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') @@ -49,41 +50,41 @@ class CookieStoreTest < ActionController::IntegrationTest def test_raises_argument_error_if_missing_session_key assert_raise(ArgumentError, nil.inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => nil, :secret => SessionSecret) } assert_raise(ArgumentError, ''.inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => '', :secret => SessionSecret) } end def test_raises_argument_error_if_missing_secret assert_raise(ArgumentError, nil.inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => SessionKey, :secret => nil) } assert_raise(ArgumentError, ''.inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => SessionKey, :secret => '') } end def test_raises_argument_error_if_secret_is_probably_insecure assert_raise(ArgumentError, "password".inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => SessionKey, :secret => "password") } assert_raise(ArgumentError, "secret".inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => SessionKey, :secret => "secret") } assert_raise(ArgumentError, "12345678901234567890123456789".inspect) { - ActionController::Session::CookieStore.new(nil, + ActionDispatch::Session::CookieStore.new(nil, :key => SessionKey, :secret => "12345678901234567890123456789") } end @@ -117,7 +118,7 @@ class CookieStoreTest < ActionController::IntegrationTest def test_close_raises_when_data_overflows with_test_route_set do - assert_raise(ActionController::Session::CookieStore::CookieOverflow) { + assert_raise(ActionDispatch::Session::CookieStore::CookieOverflow) { get '/raise_data_overflow' } end diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb index eb896a344c..2e2bf79148 100644 --- a/actionpack/test/controller/session/mem_cache_store_test.rb +++ b/actionpack/test/controller/session/mem_cache_store_test.rb @@ -26,7 +26,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest begin DispatcherApp = ActionController::Dispatcher.new - MemCacheStoreApp = ActionController::Session::MemCacheStore.new( + MemCacheStoreApp = ActionDispatch::Session::MemCacheStore.new( DispatcherApp, :key => '_session_id') diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 65c894c2e7..d378188b43 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -635,7 +635,7 @@ class CleanBacktraceTest < ActionController::TestCase end def test_should_clean_assertion_lines_from_backtrace - path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller") + path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller/testing") exception = ActiveSupport::TestCase::Assertion.new('message') exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"] clean_backtrace { raise exception } diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index ac84e2dfcd..1539f8f506 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -29,8 +29,8 @@ class ViewLoadPathsTest < ActionController::TestCase @controller = TestController.new # Following is needed in order to setup @controller.template object properly - @controller.send :initialize_template_class, @response @controller.send :assign_shortcuts, @request, @response + @controller.send :initialize_template_class, @response # Track the last warning. @old_behavior = ActiveSupport::Deprecation.behavior diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb new file mode 100644 index 0000000000..ec6ba494dc --- /dev/null +++ b/actionpack/test/dispatch/header_test.rb @@ -0,0 +1,16 @@ +require 'abstract_unit' + +class HeaderTest < ActiveSupport::TestCase + def setup + @headers = ActionDispatch::Http::Headers.new( + "HTTP_CONTENT_TYPE" => "text/plain" + ) + end + + test "content type" do + assert_equal "text/plain", @headers["Content-Type"] + assert_equal "text/plain", @headers["content-type"] + assert_equal "text/plain", @headers["CONTENT_TYPE"] + assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"] + end +end diff --git a/actionpack/test/controller/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index 2a141697da..e5496c848b 100644 --- a/actionpack/test/controller/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -6,7 +6,7 @@ class MiddlewareStackTest < ActiveSupport::TestCase class BazMiddleware; end def setup - @stack = ActionController::MiddlewareStack.new + @stack = ActionDispatch::MiddlewareStack.new @stack.use FooMiddleware @stack.use BarMiddleware end diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index c7faa621d9..2fdf4819bb 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -1,57 +1,60 @@ require 'abstract_unit' -class MimeTypeTest < Test::Unit::TestCase - Mime::Type.register "image/png", :png - Mime::Type.register "application/pdf", :pdf +class MimeTypeTest < ActiveSupport::TestCase + Mime::Type.register "image/png", :png unless defined? Mime::PNG + Mime::Type.register "application/pdf", :pdf unless defined? Mime::PDF - def test_parse_single + test "parse single" do Mime::LOOKUP.keys.each do |mime_type| assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type) end end - def test_parse_without_q + test "parse without q" do accept = "text/xml,application/xhtml+xml,text/yaml,application/xml,text/html,image/png,text/plain,application/pdf,*/*" expect = [Mime::HTML, Mime::XML, Mime::YAML, Mime::PNG, Mime::TEXT, Mime::PDF, Mime::ALL] assert_equal expect, Mime::Type.parse(accept) end - def test_parse_with_q + test "parse with q" do accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2" expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL] assert_equal expect, Mime::Type.parse(accept) end - + # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) - def test_parse_crappy_broken_acceptlines + test "parse crappy broken acceptlines" do accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL] assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s } end - # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1) - def test_parse_crappy_broken_acceptlines2 + # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 + # (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1) + test "parse crappy broken acceptlines2" do accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*" expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ] assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s } end - - def test_custom_type - Mime::Type.register("image/gif", :gif) - assert_nothing_raised do - Mime::GIF - assert_equal Mime::GIF, Mime::SET.last + + test "custom type" do + begin + Mime::Type.register("image/gif", :gif) + assert_nothing_raised do + Mime::GIF + assert_equal Mime::GIF, Mime::SET.last + end + ensure + Mime.module_eval { remove_const :GIF if const_defined?(:GIF) } end - ensure - Mime.module_eval { remove_const :GIF if const_defined?(:GIF) } end - - def test_type_should_be_equal_to_symbol + + test "type should be equal to symbol" do assert_equal Mime::HTML, 'application/xhtml+xml' assert_equal Mime::HTML, :html end - def test_type_convenience_methods + test "type convenience methods" do # Don't test Mime::ALL, since it Mime::ALL#html? == true types = Mime::SET.to_a.map(&:to_sym).uniq - [:all] @@ -67,12 +70,12 @@ class MimeTypeTest < Test::Unit::TestCase end end - def test_mime_all_is_html + test "mime all is html" do assert Mime::ALL.all?, "Mime::ALL is not all?" assert Mime::ALL.html?, "Mime::ALL is not html?" end - def test_verifiable_mime_types + test "verifiable mime types" do all_types = Mime::SET.to_a.map(&:to_sym) all_types.uniq! # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE @@ -82,7 +85,7 @@ class MimeTypeTest < Test::Unit::TestCase assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" } end - def test_regexp_matcher + test "regexp matcher" do assert Mime::JS =~ "text/javascript" assert Mime::JS =~ "application/javascript" assert Mime::JS !~ "text/html" diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/dispatch/rack_test.rb index e458ab6738..a9a9f815da 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/dispatch/rack_test.rb @@ -1,6 +1,8 @@ require 'abstract_unit' -class BaseRackTest < Test::Unit::TestCase +# TODO: Merge these tests into RequestTest + +class BaseRackTest < ActiveSupport::TestCase def setup @env = { "HTTP_MAX_FORWARDS" => "10", @@ -43,30 +45,27 @@ class BaseRackTest < Test::Unit::TestCase "REDIRECT_STATUS" => "200", "REQUEST_METHOD" => "GET" } - @request = ActionController::Request.new(@env) + @request = ActionDispatch::Request.new(@env) # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. - @alt_cookie_fmt_request = ActionController::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) + @alt_cookie_fmt_request = ActionDispatch::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) end - def default_test; end - private - - def set_content_data(data) - @request.env['REQUEST_METHOD'] = 'POST' - @request.env['CONTENT_LENGTH'] = data.length - @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' - @request.env['rack.input'] = StringIO.new(data) - end + def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['rack.input'] = StringIO.new(data) + end end class RackRequestTest < BaseRackTest - def test_proxy_request - assert_equal 'glu.ttono.us', @request.host_with_port + test "proxy request" do + assert_equal 'glu.ttono.us', @request.host_with_port(true) end - def test_http_host + test "http host" do @env.delete "HTTP_X_FORWARDED_HOST" @env['HTTP_HOST'] = "rubyonrails.org:8080" assert_equal "rubyonrails.org", @request.host @@ -76,19 +75,19 @@ class RackRequestTest < BaseRackTest assert_equal "www.secondhost.org", @request.host end - def test_http_host_with_default_port_overrides_server_port + test "http host with default port overrides server port" do @env.delete "HTTP_X_FORWARDED_HOST" @env['HTTP_HOST'] = "rubyonrails.org" assert_equal "rubyonrails.org", @request.host_with_port end - def test_host_with_port_defaults_to_server_name_if_no_host_headers + test "host with port defaults to server name if no host headers" do @env.delete "HTTP_X_FORWARDED_HOST" @env.delete "HTTP_HOST" assert_equal "glu.ttono.us:8007", @request.host_with_port end - def test_host_with_port_falls_back_to_server_addr_if_necessary + test "host with port falls back to server addr if necessary" do @env.delete "HTTP_X_FORWARDED_HOST" @env.delete "HTTP_HOST" @env.delete "SERVER_NAME" @@ -97,30 +96,30 @@ class RackRequestTest < BaseRackTest assert_equal "207.7.108.53:8007", @request.host_with_port end - def test_host_with_port_if_http_standard_port_is_specified + test "host with port if http standard port is specified" do @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80" assert_equal "glu.ttono.us", @request.host_with_port end - def test_host_with_port_if_https_standard_port_is_specified + test "host with port if https standard port is specified" do @env['HTTP_X_FORWARDED_PROTO'] = "https" @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443" assert_equal "glu.ttono.us", @request.host_with_port end - def test_host_if_ipv6_reference + test "host if ipv6 reference" do @env.delete "HTTP_X_FORWARDED_HOST" @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]" assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host end - def test_host_if_ipv6_reference_with_port + test "host if ipv6 reference with port" do @env.delete "HTTP_X_FORWARDED_HOST" @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008" assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host end - def test_cgi_environment_variables + test "cgi environment variables" do assert_equal "Basic", @request.auth_type assert_equal 0, @request.content_length assert_equal nil, @request.content_type @@ -151,7 +150,7 @@ class RackRequestTest < BaseRackTest assert_equal "lighttpd", @request.server_software end - def test_cookie_syntax_resilience + test "cookie syntax resilience" do cookies = @request.cookies assert_equal "c84ace84796670c052c6ceb2451fb0f2", cookies["_session_id"], cookies.inspect assert_equal "yes", cookies["is_admin"], cookies.inspect @@ -163,39 +162,39 @@ class RackRequestTest < BaseRackTest end class RackRequestParamsParsingTest < BaseRackTest - def test_doesnt_break_when_content_type_has_charset + test "doesnt break when content type has charset" do set_content_data 'flamenco=love' assert_equal({"flamenco"=> "love"}, @request.request_parameters) end - def test_doesnt_interpret_request_uri_as_query_string_when_missing + test "doesnt interpret request uri as query string when missing" do @request.env['REQUEST_URI'] = 'foo' assert_equal({}, @request.query_parameters) end end class RackRequestContentTypeTest < BaseRackTest - def test_html_content_type_verification + test "html content type verification" do @request.env['CONTENT_TYPE'] = Mime::HTML.to_s assert @request.content_type.verify_request? end - def test_xml_content_type_verification + test "xml content type verification" do @request.env['CONTENT_TYPE'] = Mime::XML.to_s assert !@request.content_type.verify_request? end end class RackRequestNeedsRewoundTest < BaseRackTest - def test_body_should_be_rewound + test "body should be rewound" do data = 'foo' @env['rack.input'] = StringIO.new(data) @env['CONTENT_LENGTH'] = data.length @env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' # Read the request body by parsing params. - request = ActionController::Request.new(@env) + request = ActionDispatch::Request.new(@env) request.request_parameters # Should have rewound the body. @@ -206,10 +205,10 @@ end class RackResponseTest < BaseRackTest def setup super - @response = ActionController::Response.new + @response = ActionDispatch::Response.new end - def test_simple_output + test "simple output" do @response.body = "Hello, World!" @response.prepare! @@ -228,7 +227,7 @@ class RackResponseTest < BaseRackTest assert_equal ["Hello, World!"], parts end - def test_streaming_block + test "streaming block" do @response.body = Proc.new do |response, output| 5.times { |n| output.write(n) } end @@ -252,11 +251,11 @@ end class RackResponseHeadersTest < BaseRackTest def setup super - @response = ActionController::Response.new + @response = ActionDispatch::Response.new @response.status = "200 OK" end - def test_content_type + test "content type" do [204, 304].each do |c| @response.status = c.to_s assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" @@ -268,7 +267,7 @@ class RackResponseHeadersTest < BaseRackTest end end - def test_status + test "status" do assert !response_headers.has_key?('Status') end diff --git a/actionpack/test/controller/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index a3dde72c4e..a3dde72c4e 100644 --- a/actionpack/test/controller/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 054519d0d2..5b9728cc42 100644 --- a/actionpack/test/controller/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -215,7 +215,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest def with_muck_middleware original_middleware = ActionController::Dispatcher.middleware middleware = original_middleware.dup - middleware.insert_after ActionController::RewindableInput, MuckMiddleware + middleware.insert_after ActionDispatch::RewindableInput, MuckMiddleware ActionController::Dispatcher.middleware = middleware yield ActionController::Dispatcher.middleware = original_middleware diff --git a/actionpack/test/controller/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb index a31e326ddf..a31e326ddf 100644 --- a/actionpack/test/controller/request/query_string_parsing_test.rb +++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb diff --git a/actionpack/test/controller/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 89239687de..9f0535bbcc 100644 --- a/actionpack/test/controller/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -195,7 +195,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest def with_muck_middleware original_middleware = ActionController::Dispatcher.middleware middleware = original_middleware.dup - middleware.insert_after ActionController::RewindableInput, MuckMiddleware + middleware.insert_after ActionDispatch::RewindableInput, MuckMiddleware ActionController::Dispatcher.middleware = middleware yield ActionController::Dispatcher.middleware = original_middleware diff --git a/actionpack/test/controller/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index ee764e726e..ee764e726e 100644 --- a/actionpack/test/controller/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/dispatch/request_test.rb index efe4f136f5..60f71f03ce 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -10,7 +10,7 @@ class RequestTest < ActiveSupport::TestCase ActionController::Base.relative_url_root = nil end - def test_remote_ip + test "remote ip" do assert_equal '0.0.0.0', @request.remote_ip @request.remote_addr = '1.2.3.4' @@ -82,7 +82,7 @@ class RequestTest < ActiveSupport::TestCase @request.env.delete 'HTTP_X_FORWARDED_FOR' end - def test_domains + test "domains" do @request.host = "www.rubyonrails.org" assert_equal "rubyonrails.org", @request.domain @@ -102,7 +102,7 @@ class RequestTest < ActiveSupport::TestCase assert_nil @request.domain end - def test_subdomains + test "subdomains" do @request.host = "www.rubyonrails.org" assert_equal %w( www ), @request.subdomains @@ -128,7 +128,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal [], @request.subdomains end - def test_port_string + test "port string" do @request.port = 80 assert_equal "", @request.port_string @@ -136,7 +136,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal ":8080", @request.port_string end - def test_request_uri + test "request uri" do @request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432' @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1" @@ -242,20 +242,20 @@ class RequestTest < ActiveSupport::TestCase assert_equal "/some/path", @request.path end - def test_host_with_default_port + test "host with default port" do @request.host = "rubyonrails.org" @request.port = 80 assert_equal "rubyonrails.org", @request.host_with_port end - def test_host_with_non_default_port + test "host with non default port" do @request.host = "rubyonrails.org" @request.port = 81 assert_equal "rubyonrails.org:81", @request.host_with_port end - def test_server_software - assert_equal nil, @request.server_software + test "server software" do + assert_equal nil, @request.server_software(true) @request.env['SERVER_SOFTWARE'] = 'Apache3.422' assert_equal 'apache', @request.server_software @@ -264,7 +264,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal 'lighttpd', @request.server_software end - def test_xml_http_request + test "xml http request" do assert !@request.xml_http_request? assert !@request.xhr? @@ -277,47 +277,47 @@ class RequestTest < ActiveSupport::TestCase assert @request.xhr? end - def test_reports_ssl + test "reports ssl" do assert !@request.ssl? @request.env['HTTPS'] = 'on' assert @request.ssl? end - def test_reports_ssl_when_proxied_via_lighttpd + test "reports ssl when proxied via lighttpd" do assert !@request.ssl? @request.env['HTTP_X_FORWARDED_PROTO'] = 'https' assert @request.ssl? end - def test_symbolized_request_methods + test "symbolized request methods" do [:get, :post, :put, :delete].each do |method| self.request_method = method assert_equal method, @request.method end end - def test_invalid_http_method_raises_exception + test "invalid http method raises exception" do assert_raises(ActionController::UnknownHttpMethod) do self.request_method = :random_method @request.request_method end end - def test_allow_method_hacking_on_post + test "allow method hacking on post" do [:get, :head, :options, :put, :post, :delete].each do |method| self.request_method = method assert_equal(method == :head ? :get : method, @request.method) end end - def test_invalid_method_hacking_on_post_raises_exception + test "invalid method hacking on post raises exception" do assert_raises(ActionController::UnknownHttpMethod) do self.request_method = :_random_method @request.request_method end end - def test_restrict_method_hacking + test "restrict method hacking" do @request.instance_eval { @parameters = { :_method => 'put' } } [:get, :put, :delete].each do |method| self.request_method = method @@ -325,72 +325,74 @@ class RequestTest < ActiveSupport::TestCase end end - def test_head_masquerading_as_get + test "head masquerading as get" do self.request_method = :head assert_equal :get, @request.method assert @request.get? assert @request.head? end - def test_xml_format + test "xml format" do @request.instance_eval { @parameters = { :format => 'xml' } } assert_equal Mime::XML, @request.format end - def test_xhtml_format + test "xhtml format" do @request.instance_eval { @parameters = { :format => 'xhtml' } } assert_equal Mime::HTML, @request.format end - def test_txt_format + test "txt format" do @request.instance_eval { @parameters = { :format => 'txt' } } assert_equal Mime::TEXT, @request.format end - def test_nil_format - ActionController::Base.use_accept_header, old = - false, ActionController::Base.use_accept_header + test "nil format" do + begin + ActionController::Base.use_accept_header, old = + false, ActionController::Base.use_accept_header - @request.instance_eval { @parameters = {} } - @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" - assert @request.xhr? - assert_equal Mime::JS, @request.format + @request.instance_eval { @parameters = {} } + @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" + assert @request.xhr? + assert_equal Mime::JS, @request.format - ensure - ActionController::Base.use_accept_header = old + ensure + ActionController::Base.use_accept_header = old + end end - def test_content_type + test "content type" do @request.env["CONTENT_TYPE"] = "text/html" assert_equal Mime::HTML, @request.content_type end - def test_format_assignment_should_set_format + test "format assignment should set format" do @request.instance_eval { self.format = :txt } assert !@request.format.xml? @request.instance_eval { self.format = :xml } assert @request.format.xml? end - def test_content_no_type + test "content no type" do assert_equal nil, @request.content_type end - def test_content_type_xml + test "content type xml" do @request.env["CONTENT_TYPE"] = "application/xml" assert_equal Mime::XML, @request.content_type end - def test_content_type_with_charset + test "content type with charset" do @request.env["CONTENT_TYPE"] = "application/xml; charset=UTF-8" assert_equal Mime::XML, @request.content_type end - def test_user_agent + test "user agent" do assert_not_nil @request.user_agent end - def test_parameters + test "parameters" do @request.stubs(:request_parameters).returns({ "foo" => 1 }) @request.stubs(:query_parameters).returns({ "bar" => 2 }) diff --git a/actionpack/test/fixtures/layout_tests/views/goodbye.rhtml b/actionpack/test/fixtures/layout_tests/views/goodbye.rhtml new file mode 100644 index 0000000000..bbccf0913e --- /dev/null +++ b/actionpack/test/fixtures/layout_tests/views/goodbye.rhtml @@ -0,0 +1 @@ +hello.rhtml
\ No newline at end of file diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index d41111127b..d814f84752 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -3,7 +3,7 @@ require 'abstract_unit' class JavaScriptHelperTest < ActionView::TestCase tests ActionView::Helpers::JavaScriptHelper - attr_accessor :template_format, :output_buffer + attr_accessor :formats, :output_buffer def setup @template = self diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index d6b86a3964..8ff29412bf 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -25,7 +25,7 @@ class Author::Nested < Author; end class PrototypeHelperBaseTest < ActionView::TestCase - attr_accessor :template_format, :output_buffer + attr_accessor :formats, :output_buffer def setup @template = self diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c226e212b5..83de0815f4 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -153,7 +153,7 @@ module RenderTestCases # TODO: The reason for this test is unclear, improve documentation def test_render_missing_xml_partial_and_raise_missing_template - @view.template_format = :xml + @view.formats = [:xml] assert_raise(ActionView::MissingTemplate) { @view.render(:partial => "test/layout_for_partial") } end |