Set the response content type to that of found template if not explicitly set elsewhere [#444 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
d2ccb852d4
commit
c3d1fda555
@ -379,6 +379,12 @@ def assign_variables_from_controller
|
|||||||
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_controller_content_type(content_type)
|
||||||
|
if controller.respond_to?(:response)
|
||||||
|
controller.response.content_type ||= content_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def execute(method, local_assigns = {})
|
def execute(method, local_assigns = {})
|
||||||
send(method, local_assigns) do |*names|
|
send(method, local_assigns) do |*names|
|
||||||
instance_variable_get "@content_for_#{names.first || 'layout'}"
|
instance_variable_get "@content_for_#{names.first || 'layout'}"
|
||||||
|
@ -24,10 +24,13 @@ def compiled_source
|
|||||||
memoize :compiled_source
|
memoize :compiled_source
|
||||||
|
|
||||||
def render(view, local_assigns = {})
|
def render(view, local_assigns = {})
|
||||||
|
compile(local_assigns)
|
||||||
|
|
||||||
view._first_render ||= self
|
view._first_render ||= self
|
||||||
view._last_render = self
|
view._last_render = self
|
||||||
|
|
||||||
view.send(:evaluate_assigns)
|
view.send(:evaluate_assigns)
|
||||||
compile(local_assigns)
|
view.send(:set_controller_content_type, mime_type) if respond_to?(:mime_type)
|
||||||
view.send(:execute, method(local_assigns), local_assigns)
|
view.send(:execute, method(local_assigns), local_assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ def format_and_extension
|
|||||||
end
|
end
|
||||||
memoize :format_and_extension
|
memoize :format_and_extension
|
||||||
|
|
||||||
|
def mime_type
|
||||||
|
Mime::Type.lookup_by_extension(format) if format
|
||||||
|
end
|
||||||
|
memoize :mime_type
|
||||||
|
|
||||||
def path
|
def path
|
||||||
[base_path, [name, format, extension].compact.join('.')].compact.join('/')
|
[base_path, [name, format, extension].compact.join('.')].compact.join('/')
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,7 @@ class Builder < TemplateHandler
|
|||||||
include Compilable
|
include Compilable
|
||||||
|
|
||||||
def compile(template)
|
def compile(template)
|
||||||
# ActionMailer does not have a response
|
"set_controller_content_type(Mime::XML);" +
|
||||||
"controller.respond_to?(:response) && controller.response.content_type ||= Mime::XML;" +
|
|
||||||
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
|
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
|
||||||
"self.output_buffer = xml.target!;" +
|
"self.output_buffer = xml.target!;" +
|
||||||
template.source +
|
template.source +
|
||||||
|
@ -197,11 +197,11 @@ def default_render
|
|||||||
|
|
||||||
def render_alternate_default
|
def render_alternate_default
|
||||||
# For this test, the method "default_render" is overridden:
|
# For this test, the method "default_render" is overridden:
|
||||||
@alternate_default_render = lambda {
|
@alternate_default_render = lambda do
|
||||||
render :update do |page|
|
render :update do |page|
|
||||||
page.replace :foo, :partial => 'partial'
|
page.replace :foo, :partial => 'partial'
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue_action(e) raise end
|
def rescue_action(e) raise end
|
||||||
@ -467,6 +467,11 @@ def test_should_render_xml_but_keep_custom_content_type
|
|||||||
get :render_xml_with_custom_content_type
|
get :render_xml_with_custom_content_type
|
||||||
assert_equal "application/atomsvc+xml", @response.content_type
|
assert_equal "application/atomsvc+xml", @response.content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_use_implicit_content_type
|
||||||
|
get :implicit_content_type, :format => 'atom'
|
||||||
|
assert_equal Mime::ATOM, @response.content_type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class EtagRenderTest < Test::Unit::TestCase
|
class EtagRenderTest < Test::Unit::TestCase
|
||||||
|
2
actionpack/test/fixtures/test/implicit_content_type.atom.builder
vendored
Normal file
2
actionpack/test/fixtures/test/implicit_content_type.atom.builder
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
xml.atom do
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user