mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
stop calling deprecated methods
We should be asking the mime type method for the mime objects rather than via const lookup
This commit is contained in:
parent
efc6dd550e
commit
e4ba720c17
22 changed files with 93 additions and 93 deletions
|
@ -7,7 +7,7 @@ module AbstractController
|
|||
const = sym.upcase
|
||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
def #{sym}(*args, &block) # def html(*args, &block)
|
||||
custom(Mime::#{const}, *args, &block) # custom(Mime::HTML, *args, &block)
|
||||
custom(Mime::Type[:#{const}], *args, &block) # custom(Mime::Type[:HTML], *args, &block)
|
||||
end # end
|
||||
RUBY
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module AbstractController
|
|||
def method_missing(symbol, &block)
|
||||
const_name = symbol.upcase
|
||||
|
||||
unless Mime.const_defined?(const_name)
|
||||
unless Mime::Type.registered?(const_name)
|
||||
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
|
||||
"http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
|
||||
"If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
|
||||
|
@ -33,7 +33,7 @@ module AbstractController
|
|||
"format.html { |html| html.tablet { ... } }"
|
||||
end
|
||||
|
||||
mime_constant = Mime.const_get(const_name)
|
||||
mime_constant = Mime::Type[const_name]
|
||||
|
||||
if Mime::SET.include?(mime_constant)
|
||||
AbstractController::Collector.generate_method_for_mime(mime_constant)
|
||||
|
|
|
@ -55,7 +55,7 @@ module AbstractController
|
|||
# Returns Content-Type of rendered content
|
||||
# :api: public
|
||||
def rendered_format
|
||||
Mime::TEXT
|
||||
Mime::Type[:TEXT]
|
||||
end
|
||||
|
||||
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
|
||||
|
|
|
@ -229,14 +229,14 @@ module ActionController #:nodoc:
|
|||
@responses = {}
|
||||
@variant = variant
|
||||
|
||||
mimes.each { |mime| @responses["Mime::#{mime.upcase}".constantize] = nil }
|
||||
mimes.each { |mime| @responses[Mime::Type[mime.to_sym.upcase]] = nil }
|
||||
end
|
||||
|
||||
def any(*args, &block)
|
||||
if args.any?
|
||||
args.each { |type| send(type, &block) }
|
||||
else
|
||||
custom(Mime::ALL, &block)
|
||||
custom(Mime::Type[:ALL], &block)
|
||||
end
|
||||
end
|
||||
alias :all :any
|
||||
|
@ -251,7 +251,7 @@ module ActionController #:nodoc:
|
|||
end
|
||||
|
||||
def response
|
||||
response = @responses.fetch(format, @responses[Mime::ALL])
|
||||
response = @responses.fetch(format, @responses[Mime::Type[:ALL]])
|
||||
if response.is_a?(VariantCollector) # `format.html.phone` - variant inline syntax
|
||||
response.variant
|
||||
elsif response.nil? || response.arity == 0 # `format.html` - just a format, call its block
|
||||
|
|
|
@ -68,11 +68,11 @@ module ActionController
|
|||
# ActionController::Renderers.add :csv do |obj, options|
|
||||
# filename = options[:filename] || 'data'
|
||||
# str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
|
||||
# send_data str, type: Mime::CSV,
|
||||
# send_data str, type: Mime::Type[:CSV],
|
||||
# disposition: "attachment; filename=#{filename}.csv"
|
||||
# end
|
||||
#
|
||||
# Note that we used Mime::CSV for the csv mime type as it comes with Rails.
|
||||
# Note that we used Mime::Type[:CSV] for the csv mime type as it comes with Rails.
|
||||
# For a custom renderer, you'll need to register a mime type with
|
||||
# <tt>Mime::Type.register</tt>.
|
||||
#
|
||||
|
@ -116,24 +116,24 @@ module ActionController
|
|||
json = json.to_json(options) unless json.kind_of?(String)
|
||||
|
||||
if options[:callback].present?
|
||||
if content_type.nil? || content_type == Mime::JSON
|
||||
self.content_type = Mime::JS
|
||||
if content_type.nil? || content_type == Mime::Type[:JSON]
|
||||
self.content_type = Mime::Type[:JS]
|
||||
end
|
||||
|
||||
"/**/#{options[:callback]}(#{json})"
|
||||
else
|
||||
self.content_type ||= Mime::JSON
|
||||
self.content_type ||= Mime::Type[:JSON]
|
||||
json
|
||||
end
|
||||
end
|
||||
|
||||
add :js do |js, options|
|
||||
self.content_type ||= Mime::JS
|
||||
self.content_type ||= Mime::Type[:JS]
|
||||
js.respond_to?(:to_js) ? js.to_js(options) : js
|
||||
end
|
||||
|
||||
add :xml do |xml, options|
|
||||
self.content_type ||= Mime::XML
|
||||
self.content_type ||= Mime::Type[:XML]
|
||||
xml.respond_to?(:to_xml) ? xml.to_xml(options) : xml
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ module ActionController
|
|||
end
|
||||
|
||||
def _set_html_content_type
|
||||
self.content_type = Mime::HTML.to_s
|
||||
self.content_type = Mime::Type[:HTML].to_s
|
||||
end
|
||||
|
||||
def _set_rendered_content_type(format)
|
||||
|
|
|
@ -34,7 +34,7 @@ module ActionController
|
|||
self.session = session
|
||||
self.session_options = TestSession::DEFAULT_OPTIONS
|
||||
@custom_param_parsers = {
|
||||
Mime::XML => lambda { |raw_post| Hash.from_xml(raw_post)['hash'] }
|
||||
Mime::Type[:XML] => lambda { |raw_post| Hash.from_xml(raw_post)['hash'] }
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -402,7 +402,7 @@ module ActionController
|
|||
MSG
|
||||
|
||||
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||
@request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
@request.env['HTTP_ACCEPT'] ||= [Mime::Type[:JS], Mime::Type[:HTML], Mime::Type[:XML], 'text/xml', Mime::Type[:ALL]].join(', ')
|
||||
__send__(*args).tap do
|
||||
@request.env.delete 'HTTP_X_REQUESTED_WITH'
|
||||
@request.env.delete 'HTTP_ACCEPT'
|
||||
|
@ -505,7 +505,7 @@ module ActionController
|
|||
if xhr
|
||||
@request.set_header 'HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'
|
||||
@request.fetch_header('HTTP_ACCEPT') do |k|
|
||||
@request.set_header k, [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
@request.set_header k, [Mime::Type[:JS], Mime::Type[:HTML], Mime::Type[:XML], 'text/xml', Mime::Type[:ALL]].join(', ')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ module ActionDispatch
|
|||
elsif use_accept_header && valid_accept_header
|
||||
accepts
|
||||
elsif xhr?
|
||||
[Mime::JS]
|
||||
[Mime::Type[:JS]]
|
||||
else
|
||||
[Mime::HTML]
|
||||
[Mime::Type[:HTML]]
|
||||
end
|
||||
set_header k, v
|
||||
end
|
||||
|
@ -134,14 +134,14 @@ module ActionDispatch
|
|||
#
|
||||
def negotiate_mime(order)
|
||||
formats.each do |priority|
|
||||
if priority == Mime::ALL
|
||||
if priority == Mime::Type[:ALL]
|
||||
return order.first
|
||||
elsif order.include?(priority)
|
||||
return priority
|
||||
end
|
||||
end
|
||||
|
||||
order.include?(Mime::ALL) ? format : nil
|
||||
order.include?(Mime::Type[:ALL]) ? format : nil
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -59,11 +59,11 @@ to:
|
|||
ActiveSupport::Deprecation.warn <<-eow
|
||||
Accessing mime types via constants is deprecated. Please change:
|
||||
|
||||
`Mime::#{sym}`
|
||||
`Mime.const_defined?(#{sym})`
|
||||
|
||||
to:
|
||||
|
||||
`Mime::Type[:#{sym}]`
|
||||
`Mime::Type.registered?(:#{sym})`
|
||||
eow
|
||||
true
|
||||
else
|
||||
|
|
|
@ -361,7 +361,7 @@ module ActionDispatch # :nodoc:
|
|||
return if content_type
|
||||
|
||||
ct = parse_content_type
|
||||
set_content_type(ct.mime_type || Mime::HTML.to_s,
|
||||
set_content_type(ct.mime_type || Mime::Type[:HTML].to_s,
|
||||
ct.charset || self.class.default_charset)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module ActionDispatch
|
|||
include Rails::Dom::Testing::Assertions
|
||||
|
||||
def html_document
|
||||
@html_document ||= if @response.content_type === Mime::XML
|
||||
@html_document ||= if @response.content_type === Mime::Type[:XML]
|
||||
Nokogiri::XML::Document.parse(@response.body)
|
||||
else
|
||||
Nokogiri::HTML::Document.parse(@response.body)
|
||||
|
|
|
@ -354,7 +354,7 @@ module ActionDispatch
|
|||
if xhr
|
||||
headers ||= {}
|
||||
headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||
headers['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
headers['HTTP_ACCEPT'] ||= [Mime::Type[:JS], Mime::Type[:HTML], Mime::Type[:XML], 'text/xml', Mime::Type[:ALL]].join(', ')
|
||||
end
|
||||
|
||||
# this modifies the passed request_env directly
|
||||
|
|
|
@ -53,9 +53,9 @@ module AbstractController
|
|||
collector.html
|
||||
collector.text(:foo)
|
||||
collector.js(:bar) { :baz }
|
||||
assert_equal [Mime::HTML, [], nil], collector.responses[0]
|
||||
assert_equal [Mime::TEXT, [:foo], nil], collector.responses[1]
|
||||
assert_equal [Mime::JS, [:bar]], collector.responses[2][0,2]
|
||||
assert_equal [Mime::Type[:HTML], [], nil], collector.responses[0]
|
||||
assert_equal [Mime::Type[:TEXT], [:foo], nil], collector.responses[1]
|
||||
assert_equal [Mime::Type[:JS], [:bar]], collector.responses[2][0,2]
|
||||
assert_equal :baz, collector.responses[2][2].call
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,7 +65,7 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
end
|
||||
|
||||
def render_text_with_custom_content_type
|
||||
render body: "Hello!", content_type: Mime::RSS
|
||||
render body: "Hello!", content_type: Mime::Type[:RSS]
|
||||
end
|
||||
|
||||
def session_stuffing
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'abstract_unit'
|
|||
class OldContentTypeController < ActionController::Base
|
||||
# :ported:
|
||||
def render_content_type_from_body
|
||||
response.content_type = Mime::RSS
|
||||
response.content_type = Mime::Type[:RSS]
|
||||
render body: "hello world!"
|
||||
end
|
||||
|
||||
|
@ -14,7 +14,7 @@ class OldContentTypeController < ActionController::Base
|
|||
|
||||
# :ported:
|
||||
def render_content_type_from_render
|
||||
render body: "hello world!", :content_type => Mime::RSS
|
||||
render body: "hello world!", :content_type => Mime::Type[:RSS]
|
||||
end
|
||||
|
||||
# :ported:
|
||||
|
@ -36,7 +36,7 @@ class OldContentTypeController < ActionController::Base
|
|||
end
|
||||
|
||||
def render_change_for_builder
|
||||
response.content_type = Mime::HTML
|
||||
response.content_type = Mime::Type[:HTML]
|
||||
render :action => "render_default_for_builder"
|
||||
end
|
||||
|
||||
|
@ -45,7 +45,7 @@ class OldContentTypeController < ActionController::Base
|
|||
format.html { render body: "hello world!" }
|
||||
format.xml { render action: "render_default_content_types_for_respond_to" }
|
||||
format.js { render body: "hello world!" }
|
||||
format.rss { render body: "hello world!", content_type: Mime::XML }
|
||||
format.rss { render body: "hello world!", content_type: Mime::Type[:XML] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -64,68 +64,68 @@ class ContentTypeTest < ActionController::TestCase
|
|||
def test_render_defaults
|
||||
get :render_defaults
|
||||
assert_equal "utf-8", @response.charset
|
||||
assert_equal Mime::TEXT, @response.content_type
|
||||
assert_equal Mime::Type[:TEXT], @response.content_type
|
||||
end
|
||||
|
||||
def test_render_changed_charset_default
|
||||
with_default_charset "utf-16" do
|
||||
get :render_defaults
|
||||
assert_equal "utf-16", @response.charset
|
||||
assert_equal Mime::TEXT, @response.content_type
|
||||
assert_equal Mime::Type[:TEXT], @response.content_type
|
||||
end
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def test_content_type_from_body
|
||||
get :render_content_type_from_body
|
||||
assert_equal Mime::RSS, @response.content_type
|
||||
assert_equal Mime::Type[:RSS], @response.content_type
|
||||
assert_equal "utf-8", @response.charset
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def test_content_type_from_render
|
||||
get :render_content_type_from_render
|
||||
assert_equal Mime::RSS, @response.content_type
|
||||
assert_equal Mime::Type[:RSS], @response.content_type
|
||||
assert_equal "utf-8", @response.charset
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def test_charset_from_body
|
||||
get :render_charset_from_body
|
||||
assert_equal Mime::TEXT, @response.content_type
|
||||
assert_equal Mime::Type[:TEXT], @response.content_type
|
||||
assert_equal "utf-16", @response.charset
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def test_nil_charset_from_body
|
||||
get :render_nil_charset_from_body
|
||||
assert_equal Mime::TEXT, @response.content_type
|
||||
assert_equal Mime::Type[:TEXT], @response.content_type
|
||||
assert_equal "utf-8", @response.charset, @response.headers.inspect
|
||||
end
|
||||
|
||||
def test_nil_default_for_erb
|
||||
with_default_charset nil do
|
||||
get :render_default_for_erb
|
||||
assert_equal Mime::HTML, @response.content_type
|
||||
assert_equal Mime::Type[:HTML], @response.content_type
|
||||
assert_nil @response.charset, @response.headers.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def test_default_for_erb
|
||||
get :render_default_for_erb
|
||||
assert_equal Mime::HTML, @response.content_type
|
||||
assert_equal Mime::Type[:HTML], @response.content_type
|
||||
assert_equal "utf-8", @response.charset
|
||||
end
|
||||
|
||||
def test_default_for_builder
|
||||
get :render_default_for_builder
|
||||
assert_equal Mime::XML, @response.content_type
|
||||
assert_equal Mime::Type[:XML], @response.content_type
|
||||
assert_equal "utf-8", @response.charset
|
||||
end
|
||||
|
||||
def test_change_for_builder
|
||||
get :render_change_for_builder
|
||||
assert_equal Mime::HTML, @response.content_type
|
||||
assert_equal Mime::Type[:HTML], @response.content_type
|
||||
assert_equal "utf-8", @response.charset
|
||||
end
|
||||
|
||||
|
@ -144,24 +144,24 @@ class AcceptBasedContentTypeTest < ActionController::TestCase
|
|||
tests OldContentTypeController
|
||||
|
||||
def test_render_default_content_types_for_respond_to
|
||||
@request.accept = Mime::HTML.to_s
|
||||
@request.accept = Mime::Type[:HTML].to_s
|
||||
get :render_default_content_types_for_respond_to
|
||||
assert_equal Mime::HTML, @response.content_type
|
||||
assert_equal Mime::Type[:HTML], @response.content_type
|
||||
|
||||
@request.accept = Mime::JS.to_s
|
||||
@request.accept = Mime::Type[:JS].to_s
|
||||
get :render_default_content_types_for_respond_to
|
||||
assert_equal Mime::JS, @response.content_type
|
||||
assert_equal Mime::Type[:JS], @response.content_type
|
||||
end
|
||||
|
||||
def test_render_default_content_types_for_respond_to_with_template
|
||||
@request.accept = Mime::XML.to_s
|
||||
@request.accept = Mime::Type[:XML].to_s
|
||||
get :render_default_content_types_for_respond_to
|
||||
assert_equal Mime::XML, @response.content_type
|
||||
assert_equal Mime::Type[:XML], @response.content_type
|
||||
end
|
||||
|
||||
def test_render_default_content_types_for_respond_to_with_overwrite
|
||||
@request.accept = Mime::RSS.to_s
|
||||
@request.accept = Mime::Type[:RSS].to_s
|
||||
get :render_default_content_types_for_respond_to
|
||||
assert_equal Mime::XML, @response.content_type
|
||||
assert_equal Mime::Type[:XML], @response.content_type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,12 +7,12 @@ module ContentType
|
|||
end
|
||||
|
||||
def set_on_response_obj
|
||||
response.content_type = Mime::RSS
|
||||
response.content_type = Mime::Type[:RSS]
|
||||
render body: "Hello world!"
|
||||
end
|
||||
|
||||
def set_on_render
|
||||
render body: "Hello world!", content_type: Mime::RSS
|
||||
render body: "Hello world!", content_type: Mime::Type[:RSS]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class RenderOtherTest < ActionController::TestCase
|
|||
|
||||
def test_using_custom_render_option
|
||||
ActionController.add_renderer :simon do |says, options|
|
||||
self.content_type = Mime::TEXT
|
||||
self.content_type = Mime::Type[:TEXT]
|
||||
self.response_body = "Simon says: #{says}"
|
||||
end
|
||||
|
||||
|
|
|
@ -92,6 +92,6 @@ class RenderXmlTest < ActionController::TestCase
|
|||
|
||||
def test_should_use_implicit_content_type
|
||||
get :implicit_content_type, format: 'atom'
|
||||
assert_equal Mime::ATOM, @response.content_type
|
||||
assert_equal Mime::Type[:ATOM], @response.content_type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,7 +89,7 @@ class SendFileTest < ActionController::TestCase
|
|||
# Test that send_file_headers! is setting the correct HTTP headers.
|
||||
def test_send_file_headers_bang
|
||||
options = {
|
||||
:type => Mime::PNG,
|
||||
:type => Mime::Type[:PNG],
|
||||
:disposition => 'disposition',
|
||||
:filename => 'filename'
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class SendFileTest < ActionController::TestCase
|
|||
|
||||
def test_send_file_headers_with_disposition_as_a_symbol
|
||||
options = {
|
||||
:type => Mime::PNG,
|
||||
:type => Mime::Type[:PNG],
|
||||
:disposition => :disposition,
|
||||
:filename => 'filename'
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
|
|||
|
||||
def test_register_and_use_json_simple
|
||||
with_test_route_set do
|
||||
with_params_parsers Mime::JSON => Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do
|
||||
with_params_parsers Mime::Type[:JSON] => Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do
|
||||
post "/",
|
||||
params: '{"request":{"summary":"content...","title":"JSON"}}',
|
||||
headers: { 'CONTENT_TYPE' => 'application/json' }
|
||||
|
@ -99,7 +99,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
|
|||
def test_parsing_json_doesnot_rescue_exception
|
||||
req = Class.new(ActionDispatch::Request) do
|
||||
def params_parsers
|
||||
{ Mime::JSON => Proc.new { |data| raise Interrupt } }
|
||||
{ Mime::Type[:JSON] => Proc.new { |data| raise Interrupt } }
|
||||
end
|
||||
|
||||
def content_length; get_header('rack.input').length; end
|
||||
|
|
|
@ -13,7 +13,7 @@ class MimeTypeTest < ActiveSupport::TestCase
|
|||
test "unregister" do
|
||||
begin
|
||||
Mime::Type.register("text/x-mobile", :mobile)
|
||||
assert Mime.const_defined?(:MOBILE)
|
||||
assert Mime::Type.registered?(:MOBILE)
|
||||
assert_equal Mime::Type[:MOBILE], Mime::LOOKUP['text/x-mobile']
|
||||
assert_equal Mime::Type[:MOBILE], Mime::EXTENSION_LOOKUP['mobile']
|
||||
|
||||
|
@ -157,7 +157,7 @@ class MimeTypeTest < ActiveSupport::TestCase
|
|||
types = Mime::SET.symbols.uniq - [:all, :iphone]
|
||||
|
||||
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
||||
types.delete_if { |type| !Mime.const_defined?(type.upcase) }
|
||||
types.delete_if { |type| !Mime::Type.registered?(type.upcase) }
|
||||
|
||||
types.each do |type|
|
||||
mime = Mime::Type[type.upcase]
|
||||
|
@ -184,7 +184,7 @@ class MimeTypeTest < ActiveSupport::TestCase
|
|||
all_types = Mime::SET.symbols
|
||||
all_types.uniq!
|
||||
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
||||
all_types.delete_if { |type| !Mime.const_defined?(type.upcase) }
|
||||
all_types.delete_if { |type| !Mime::Type.registered?(type.upcase) }
|
||||
end
|
||||
|
||||
test "references gives preference to symbols before strings" do
|
||||
|
|
|
@ -750,33 +750,33 @@ class RequestFormat < BaseRequestTest
|
|||
test "xml format" do
|
||||
request = stub_request
|
||||
assert_called(request, :parameters, times: 2, returns: {format: :xml}) do
|
||||
assert_equal Mime::XML, request.format
|
||||
assert_equal Mime::Type[:XML], request.format
|
||||
end
|
||||
end
|
||||
|
||||
test "xhtml format" do
|
||||
request = stub_request
|
||||
assert_called(request, :parameters, times: 2, returns: {format: :xhtml}) do
|
||||
assert_equal Mime::HTML, request.format
|
||||
assert_equal Mime::Type[:HTML], request.format
|
||||
end
|
||||
end
|
||||
|
||||
test "txt format" do
|
||||
request = stub_request
|
||||
assert_called(request, :parameters, times: 2, returns: {format: :txt}) do
|
||||
assert_equal Mime::TEXT, request.format
|
||||
assert_equal Mime::Type[:TEXT], request.format
|
||||
end
|
||||
end
|
||||
|
||||
test "XMLHttpRequest" do
|
||||
request = stub_request(
|
||||
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
|
||||
'HTTP_ACCEPT' => [Mime::JS, Mime::HTML, Mime::XML, "text/xml", Mime::ALL].join(",")
|
||||
'HTTP_ACCEPT' => [Mime::Type[:JS], Mime::Type[:HTML], Mime::Type[:XML], "text/xml", Mime::Type[:ALL]].join(",")
|
||||
)
|
||||
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert request.xhr?
|
||||
assert_equal Mime::JS, request.format
|
||||
assert_equal Mime::Type[:JS], request.format
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -796,29 +796,29 @@ class RequestFormat < BaseRequestTest
|
|||
|
||||
test "formats text/html with accept header" do
|
||||
request = stub_request 'HTTP_ACCEPT' => 'text/html'
|
||||
assert_equal [Mime::HTML], request.formats
|
||||
assert_equal [Mime::Type[:HTML]], request.formats
|
||||
end
|
||||
|
||||
test "formats blank with accept header" do
|
||||
request = stub_request 'HTTP_ACCEPT' => ''
|
||||
assert_equal [Mime::HTML], request.formats
|
||||
assert_equal [Mime::Type[:HTML]], request.formats
|
||||
end
|
||||
|
||||
test "formats XMLHttpRequest with accept header" do
|
||||
request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
assert_equal [Mime::JS], request.formats
|
||||
assert_equal [Mime::Type[:JS]], request.formats
|
||||
end
|
||||
|
||||
test "formats application/xml with accept header" do
|
||||
request = stub_request('CONTENT_TYPE' => 'application/xml; charset=UTF-8',
|
||||
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest")
|
||||
assert_equal [Mime::XML], request.formats
|
||||
assert_equal [Mime::Type[:XML]], request.formats
|
||||
end
|
||||
|
||||
test "formats format:text with accept header" do
|
||||
request = stub_request
|
||||
assert_called(request, :parameters, times: 2, returns: {format: :txt}) do
|
||||
assert_equal [Mime::TEXT], request.formats
|
||||
assert_equal [Mime::Type[:TEXT]], request.formats
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -848,7 +848,7 @@ class RequestFormat < BaseRequestTest
|
|||
test "formats with xhr request" do
|
||||
request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [Mime::JS], request.formats
|
||||
assert_equal [Mime::Type[:JS]], request.formats
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -859,35 +859,35 @@ class RequestFormat < BaseRequestTest
|
|||
begin
|
||||
request = stub_request 'HTTP_ACCEPT' => 'application/xml'
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [ Mime::HTML ], request.formats
|
||||
assert_equal [ Mime::Type[:HTML] ], request.formats
|
||||
end
|
||||
|
||||
request = stub_request 'HTTP_ACCEPT' => 'koz-asked/something-crazy'
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [ Mime::HTML ], request.formats
|
||||
assert_equal [ Mime::Type[:HTML] ], request.formats
|
||||
end
|
||||
|
||||
request = stub_request 'HTTP_ACCEPT' => '*/*;q=0.1'
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [ Mime::HTML ], request.formats
|
||||
assert_equal [ Mime::Type[:HTML] ], request.formats
|
||||
end
|
||||
|
||||
request = stub_request 'HTTP_ACCEPT' => 'application/jxw'
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [ Mime::HTML ], request.formats
|
||||
assert_equal [ Mime::Type[:HTML] ], request.formats
|
||||
end
|
||||
|
||||
request = stub_request 'HTTP_ACCEPT' => 'application/xml',
|
||||
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
|
||||
assert_called(request, :parameters, times: 1, returns: {}) do
|
||||
assert_equal [ Mime::JS ], request.formats
|
||||
assert_equal [ Mime::Type[:JS] ], request.formats
|
||||
end
|
||||
|
||||
request = stub_request 'HTTP_ACCEPT' => 'application/xml',
|
||||
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
assert_called(request, :parameters, times: 2, returns: {format: :json}) do
|
||||
assert_equal [ Mime::JSON ], request.formats
|
||||
assert_equal [ Mime::Type[:JSON] ], request.formats
|
||||
end
|
||||
ensure
|
||||
ActionDispatch::Request.ignore_accept_header = old_ignore_accept_header
|
||||
|
@ -897,7 +897,7 @@ end
|
|||
|
||||
class RequestMimeType < BaseRequestTest
|
||||
test "content type" do
|
||||
assert_equal Mime::HTML, stub_request('CONTENT_TYPE' => 'text/html').content_mime_type
|
||||
assert_equal Mime::Type[:HTML], stub_request('CONTENT_TYPE' => 'text/html').content_mime_type
|
||||
end
|
||||
|
||||
test "no content type" do
|
||||
|
@ -905,11 +905,11 @@ class RequestMimeType < BaseRequestTest
|
|||
end
|
||||
|
||||
test "content type is XML" do
|
||||
assert_equal Mime::XML, stub_request('CONTENT_TYPE' => 'application/xml').content_mime_type
|
||||
assert_equal Mime::Type[:XML], stub_request('CONTENT_TYPE' => 'application/xml').content_mime_type
|
||||
end
|
||||
|
||||
test "content type with charset" do
|
||||
assert_equal Mime::XML, stub_request('CONTENT_TYPE' => 'application/xml; charset=UTF-8').content_mime_type
|
||||
assert_equal Mime::Type[:XML], stub_request('CONTENT_TYPE' => 'application/xml; charset=UTF-8').content_mime_type
|
||||
end
|
||||
|
||||
test "user agent" do
|
||||
|
@ -922,9 +922,9 @@ class RequestMimeType < BaseRequestTest
|
|||
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
)
|
||||
|
||||
assert_equal nil, request.negotiate_mime([Mime::XML, Mime::JSON])
|
||||
assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::HTML])
|
||||
assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::ALL])
|
||||
assert_equal nil, request.negotiate_mime([Mime::Type[:XML], Mime::Type[:JSON]])
|
||||
assert_equal Mime::Type[:HTML], request.negotiate_mime([Mime::Type[:XML], Mime::Type[:HTML]])
|
||||
assert_equal Mime::Type[:HTML], request.negotiate_mime([Mime::Type[:XML], Mime::Type[:ALL]])
|
||||
end
|
||||
|
||||
test "negotiate_mime with content_type" do
|
||||
|
@ -933,7 +933,7 @@ class RequestMimeType < BaseRequestTest
|
|||
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
|
||||
)
|
||||
|
||||
assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
|
||||
assert_equal Mime::Type[:XML], request.negotiate_mime([Mime::Type[:XML], Mime::Type[:CSV]])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -178,13 +178,13 @@ class ResponseTest < ActiveSupport::TestCase
|
|||
test "read charset and content type" do
|
||||
resp = ActionDispatch::Response.new.tap { |response|
|
||||
response.charset = 'utf-16'
|
||||
response.content_type = Mime::XML
|
||||
response.content_type = Mime::Type[:XML]
|
||||
response.body = 'Hello'
|
||||
}
|
||||
resp.to_a
|
||||
|
||||
assert_equal('utf-16', resp.charset)
|
||||
assert_equal(Mime::XML, resp.content_type)
|
||||
assert_equal(Mime::Type[:XML], resp.content_type)
|
||||
|
||||
assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type'])
|
||||
end
|
||||
|
@ -317,7 +317,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest
|
|||
@app = lambda { |env|
|
||||
ActionDispatch::Response.new.tap { |resp|
|
||||
resp.charset = 'utf-16'
|
||||
resp.content_type = Mime::XML
|
||||
resp.content_type = Mime::Type[:XML]
|
||||
resp.body = 'Hello'
|
||||
}.to_a
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest
|
|||
assert_response :success
|
||||
|
||||
assert_equal('utf-16', @response.charset)
|
||||
assert_equal(Mime::XML, @response.content_type)
|
||||
assert_equal(Mime::Type[:XML], @response.content_type)
|
||||
|
||||
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
|
||||
end
|
||||
|
@ -342,7 +342,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest
|
|||
assert_response :success
|
||||
|
||||
assert_equal('utf-16', @response.charset)
|
||||
assert_equal(Mime::XML, @response.content_type)
|
||||
assert_equal(Mime::Type[:XML], @response.content_type)
|
||||
|
||||
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue