diff options
-rw-r--r-- | actionpack/Rakefile | 2 | ||||
-rw-r--r-- | actionpack/test/controller/header_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/dispatch/header_test.rb | 16 | ||||
-rw-r--r-- | actionpack/test/dispatch/middleware_stack_test.rb (renamed from actionpack/test/controller/middleware_stack_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb (renamed from actionpack/test/controller/mime_type_test.rb) | 51 | ||||
-rw-r--r-- | actionpack/test/dispatch/rack_test.rb (renamed from actionpack/test/controller/rack_test.rb) | 59 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/json_params_parsing_test.rb (renamed from actionpack/test/controller/request/json_params_parsing_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/multipart_params_parsing_test.rb (renamed from actionpack/test/controller/request/multipart_params_parsing_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/query_string_parsing_test.rb (renamed from actionpack/test/controller/request/query_string_parsing_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb (renamed from actionpack/test/controller/request/url_encoded_params_parsing_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/xml_params_parsing_test.rb (renamed from actionpack/test/controller/request/xml_params_parsing_test.rb) | 0 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb (renamed from actionpack/test/controller/request_test.rb) | 74 |
12 files changed, 111 insertions, 105 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile index c389e5a8d6..230a78c069 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -30,7 +30,7 @@ Rake::TestTask.new(:test_action_pack) do |t| # make sure we include the tests in alphabetical order as on some systems # this will not happen automatically and the tests (as a whole) will error - t.test_files = Dir.glob( "test/[cft]*/**/*_test.rb" ).sort + t.test_files = Dir.glob( "test/[cdft]*/**/*_test.rb" ).sort t.verbose = true #t.warning = true diff --git a/actionpack/test/controller/header_test.rb b/actionpack/test/controller/header_test.rb deleted file mode 100644 index 4f13ea00be..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 = ActionDispatch::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/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 e5496c848b..e5496c848b 100644 --- a/actionpack/test/controller/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb 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 c29902c722..df465eba91 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", @@ -49,24 +51,21 @@ class BaseRackTest < Test::Unit::TestCase @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 + 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(true) @@ -76,19 +75,19 @@ class RackRequestTest < BaseRackTest assert_equal "www.secondhost.org", @request.host(true) 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(true) 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(true) 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(true) 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(true) 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(true) 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(true) 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(true) 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,32 +162,32 @@ 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 @@ -209,7 +208,7 @@ class RackResponseTest < BaseRackTest @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 @@ -256,7 +255,7 @@ class RackResponseHeadersTest < BaseRackTest @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 5b9728cc42..5b9728cc42 100644 --- a/actionpack/test/controller/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb 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 9f0535bbcc..9f0535bbcc 100644 --- a/actionpack/test/controller/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb 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 7097d08076..6262763b81 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,19 +242,19 @@ class RequestTest < ActiveSupport::TestCase assert_equal "/some/path", @request.path(true) 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 + test "server software" do assert_equal nil, @request.server_software(true) @request.env['SERVER_SOFTWARE'] = 'Apache3.422' @@ -264,7 +264,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal 'lighttpd', @request.server_software(true) end - def test_xml_http_request + test "xml http request" do assert !@request.xml_http_request? assert !@request.xhr? @@ -277,32 +277,32 @@ 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 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 @request.request_method(true) @@ -310,14 +310,14 @@ class RequestTest < ActiveSupport::TestCase 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(true) 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 }) |