Skip to content
This repository
Browse code

Implement Mime::Type.=~ to match all synonyms against arg [#1573 stat…

…e:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
commit f36dafa492e3de66e624d81d6860f5f0536de6b0 1 parent 7c18518
Seth Fitzsimmons authored December 15, 2008 josh committed December 15, 2008
2  actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -587,7 +587,7 @@ def assert_select_email(&block)
587 587
         def response_from_page_or_rjs()
588 588
           content_type = @response.content_type
589 589
 
590  
-          if content_type && content_type =~ /text\/javascript/
  590
+          if content_type && Mime::JS =~ content_type
591 591
             body = @response.body.dup
592 592
             root = HTML::Node.new(nil)
593 593
 
8  actionpack/lib/action_controller/mime_type.rb
@@ -176,6 +176,14 @@ def ==(mime_type)
176 176
       end
177 177
     end
178 178
 
  179
+    def =~(mime_type)
  180
+      return false if mime_type.blank?
  181
+      regexp = Regexp.new(mime_type.to_s)
  182
+      (@synonyms + [ self ]).any? do |synonym|
  183
+        synonym.to_s =~ regexp
  184
+      end
  185
+    end
  186
+
179 187
     # Returns true if Action Pack should check requests using this Mime Type for possible request forgery.  See
180 188
     # ActionController::RequestForgeryProtection.
181 189
     def verify_request?
8  actionpack/test/controller/mime_type_test.rb
@@ -81,4 +81,12 @@ def test_verifiable_mime_types
81 81
     assert verified.each   { |type| assert  Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
82 82
     assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
83 83
   end
  84
+
  85
+  def test_regexp_matcher
  86
+    assert Mime::JS =~ "text/javascript"
  87
+    assert Mime::JS =~ "application/javascript"
  88
+    assert Mime::JS !~ "text/html"
  89
+    assert !(Mime::JS !~ "text/javascript")
  90
+    assert !(Mime::JS !~ "application/javascript")
  91
+  end
84 92
 end

0 notes on commit f36dafa

Please sign in to comment.
Something went wrong with that request. Please try again.