diff options
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 27 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 6 |
2 files changed, 29 insertions, 4 deletions
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 4c2b95550c..43123e68b2 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -6,10 +6,34 @@ class MimeTypeTest < ActiveSupport::TestCase test "parse single" do Mime::LOOKUP.keys.each do |mime_type| - assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type) + unless mime_type == 'image/*' + assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type) + end end end + test "parse text with trailing star" do + accept = "text/*" + expect = [Mime::JSON, Mime::XML, Mime::ICS, Mime::HTML, Mime::CSS, Mime::CSV, Mime::JS, Mime::YAML, Mime::TEXT].sort_by(&:to_s) + parsed = Mime::Type.parse(accept) + assert_equal 9, parsed.size + assert_equal expect, parsed.sort_by(&:to_s) + end + + test "parse application with trailing star" do + accept = "application/*" + expect = [Mime::HTML, Mime::JS, Mime::XML, Mime::YAML, Mime::ATOM, Mime::JSON, Mime::RSS, Mime::PDF, Mime::URL_ENCODED_FORM].sort_by(&:to_s) + parsed = Mime::Type.parse(accept) + assert_equal 9, parsed.size + assert_equal expect, parsed.sort_by(&:to_s) + end + + test "parse image with trailing star" do + accept = "image/*" + parsed = Mime::Type.parse(accept) + assert parsed.include?(Mime::PNG) + end + 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] @@ -45,6 +69,7 @@ class MimeTypeTest < ActiveSupport::TestCase end ensure Mime.module_eval { remove_const :GIF if const_defined?(:GIF) } + Mime::LOOKUP.reject!{|key,_| key == 'image/gif'} end end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 4764a8c2a8..d140ea8358 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -164,12 +164,12 @@ class RequestTest < ActiveSupport::TestCase assert !request.standard_port? end - test "port string" do + test "optional port" do request = stub_request 'HTTP_HOST' => 'www.example.org:80' - assert_equal "", request.port_string + assert_equal nil, request.optional_port request = stub_request 'HTTP_HOST' => 'www.example.org:8080' - assert_equal ":8080", request.port_string + assert_equal 8080, request.optional_port end test "full path" do |