aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb15
-rw-r--r--actionpack/test/controller/mime_responds_test.rb16
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb9
-rw-r--r--actionpack/test/lib/controller/fake_models.rb2
4 files changed, 23 insertions, 19 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 3e3478a44e..c1503c7eeb 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -190,12 +190,15 @@ module Mime
#
# Usage:
#
- # Mime::Type.unregister("text/x-mobile", :mobile)
- def unregister(string, symbol)
- EXTENSION_LOOKUP.delete(symbol.to_s)
- LOOKUP.delete(string)
- symbol = symbol.to_s.upcase.intern
- Mime.module_eval { remove_const(symbol) if const_defined?(symbol) }
+ # Mime::Type.unregister(:mobile)
+ def unregister(symbol)
+ symbol = symbol.to_s.upcase
+ mime = Mime.const_get(symbol)
+ Mime.instance_eval { remove_const(symbol) }
+
+ SET.delete_if { |v| v.eql?(mime) }
+ LOOKUP.delete_if { |k,v| v.eql?(mime) }
+ EXTENSION_LOOKUP.delete_if { |k,v| v.eql?(mime) }
end
end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 82969b2979..98c9d43b93 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -201,8 +201,8 @@ class RespondToControllerTest < ActionController::TestCase
def teardown
super
- Mime::Type.unregister('text/x-mobile', :iphone)
- Mime::Type.unregister('text/iphone', :mobile)
+ Mime::Type.unregister(:iphone)
+ Mime::Type.unregister(:mobile)
end
def test_html
@@ -622,12 +622,14 @@ class RespondWithControllerTest < ActionController::TestCase
def setup
super
@request.host = "www.example.com"
+ Mime::Type.register_alias('text/html', :iphone)
+ Mime::Type.register('text/x-mobile', :mobile)
end
def teardown
super
- Mime::Type.unregister('text/x-mobile', :iphone)
- Mime::Type.unregister('text/iphone', :mobile)
+ Mime::Type.unregister(:iphone)
+ Mime::Type.unregister(:mobile)
end
def test_using_resource
@@ -929,7 +931,8 @@ class RespondWithControllerTest < ActionController::TestCase
@controller = RenderJsonRespondWithController.new
@request.accept = "application/json"
get :index, :format => :json
- assert_equal %Q{{"message":"boom","error":"RenderJsonTestException"}}, @response.body
+ assert_match(/"message":"boom"/, @response.body)
+ assert_match(/"error":"RenderJsonTestException"/, @response.body)
end
def test_no_double_render_is_raised
@@ -1020,8 +1023,7 @@ class MimeControllerLayoutsTest < ActionController::TestCase
def teardown
super
- Mime::Type.unregister('text/x-mobile', :iphone)
- Mime::Type.unregister('text/iphone', :mobile)
+ Mime::Type.unregister(:iphone)
end
def test_missing_layout_renders_properly
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index e80d339472..9782f328fc 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -19,7 +19,7 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_equal Mime::MOBILE, Mime::LOOKUP['text/x-mobile']
assert_equal Mime::MOBILE, Mime::EXTENSION_LOOKUP['mobile']
- Mime::Type.unregister("text/x-mobile", :mobile)
+ Mime::Type.unregister(:mobile)
assert !defined?(Mime::MOBILE), "Mime::MOBILE should not be defined"
assert !Mime::LOOKUP.has_key?('text/x-mobile'), "Mime::LOOKUP should not have key ['text/x-mobile]"
assert !Mime::EXTENSION_LOOKUP.has_key?('mobile'), "Mime::EXTENSION_LOOKUP should not have key ['mobile]"
@@ -52,10 +52,9 @@ class MimeTypeTest < ActiveSupport::TestCase
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)
+ expect = [Mime::HTML, Mime::JS, Mime::XML, Mime::RSS, Mime::ATOM, Mime::YAML, Mime::URL_ENCODED_FORM, Mime::JSON, Mime::PDF]
parsed = Mime::Type.parse(accept)
- assert_equal 9, parsed.size
- assert_equal expect, parsed.sort_by(&:to_s)
+ assert_equal expect, parsed
end
test "parse without q" do
@@ -92,7 +91,7 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_equal Mime::GIF, Mime::SET.last
end
ensure
- Mime::Type.unregister('image/gif', :gif)
+ Mime::Type.unregister(:gif)
end
end
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index bd18cdc1b8..67baf369e2 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -197,6 +197,6 @@ end
class RenderJsonTestException < Exception
def to_json(options = nil)
- return { :error => self.class.name, :message => self.to_str }.to_json
+ return { :error => self.class.name, :message => self.to_s }.to_json
end
end