diff options
Diffstat (limited to 'actionpack/test/dispatch/mime_type_test.rb')
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 149e37bf3d..e558efb88d 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' +require "abstract_unit" class MimeTypeTest < ActiveSupport::TestCase test "parse single" do Mime::LOOKUP.each_key do |mime_type| - unless mime_type == 'image/*' + unless mime_type == "image/*" assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type) end end @@ -15,7 +15,7 @@ class MimeTypeTest < ActiveSupport::TestCase begin mime = Mime::Type.register("text/x-mobile", :mobile) assert_equal mime, Mime[:mobile] - assert_equal mime, Mime::Type.lookup('text/x-mobile') + assert_equal mime, Mime::Type.lookup("text/x-mobile") assert_equal mime, Mime::Type.lookup_by_extension(:mobile) Mime::Type.unregister(:mobile) @@ -44,25 +44,25 @@ class MimeTypeTest < ActiveSupport::TestCase accept = "text/*" expect = [Mime[:html], Mime[:text], Mime[:js], Mime[:css], Mime[:ics], Mime[:csv], Mime[:vcf], Mime[:xml], Mime[:yaml], Mime[:json]] parsed = Mime::Type.parse(accept) - assert_equal expect, parsed + assert_equal expect.map(&:to_s).sort!, parsed.map(&:to_s).sort! end test "parse application with trailing star" do accept = "application/*" - expect = [Mime[:html], Mime[:js], Mime[:xml], Mime[:rss], Mime[:atom], Mime[:yaml], Mime[:url_encoded_form], Mime[:json], Mime[:pdf], Mime[:zip]] + expect = [Mime[:html], Mime[:js], Mime[:xml], Mime[:rss], Mime[:atom], Mime[:yaml], Mime[:url_encoded_form], Mime[:json], Mime[:pdf], Mime[:zip], Mime[:gzip]] parsed = Mime::Type.parse(accept) - assert_equal expect, parsed + assert_equal expect.map(&:to_s).sort!, parsed.map(&:to_s).sort! 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], '*/*'] + expect = [Mime[:html], Mime[:xml], Mime[:yaml], Mime[:png], Mime[:text], Mime[:pdf], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end 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], '*/*'] + expect = [Mime[:html], Mime[:xml], Mime[:png], Mime[:pdf], Mime[:text], Mime[:yaml], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -81,7 +81,7 @@ class MimeTypeTest < ActiveSupport::TestCase # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) test "parse 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], '*/*'] + expect = [Mime[:html], Mime[:xml], "image/*", Mime[:text], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -89,7 +89,7 @@ class MimeTypeTest < ActiveSupport::TestCase # (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1) test "parse other broken acceptlines" 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', '*/*'] + 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", "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -141,14 +141,14 @@ class MimeTypeTest < ActiveSupport::TestCase test "register alias" do begin Mime::Type.register_alias "application/xhtml+xml", :foobar - assert_equal Mime[:html], Mime::EXTENSION_LOOKUP['foobar'] + assert_equal Mime[:html], Mime::EXTENSION_LOOKUP["foobar"] ensure Mime::Type.unregister(:foobar) end end test "type should be equal to symbol" do - assert_equal Mime[:html], 'application/xhtml+xml' + assert_equal Mime[:html], "application/xhtml+xml" assert_equal Mime[:html], :html end @@ -167,18 +167,6 @@ class MimeTypeTest < ActiveSupport::TestCase end end - test "deprecated lookup" do - assert_deprecated do - Mime::HTML - end - end - - test "deprecated const_defined?" do - assert_deprecated do - Mime.const_defined? :HTML - end - end - test "references gives preference to symbols before strings" do assert_equal :html, Mime[:html].ref another = Mime::Type.lookup("foo/bar") @@ -192,6 +180,6 @@ class MimeTypeTest < ActiveSupport::TestCase assert Mime[:js] !~ "text/html" assert !(Mime[:js] !~ "text/javascript") assert !(Mime[:js] !~ "application/javascript") - assert Mime[:html] =~ 'application/xhtml+xml' + assert Mime[:html] =~ "application/xhtml+xml" end end |