Removed XML argument style for respond_to, so type.xml(object.to_xml) no...

Removed XML argument style for respond_to, so type.xml(object.to_xml) no longer works -- it wasnt worth the exception

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3944 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 3257a4b9
...@@ -18,8 +18,7 @@ class Responder #:nodoc: ...@@ -18,8 +18,7 @@ class Responder #:nodoc:
DEFAULT_BLOCKS = { DEFAULT_BLOCKS = {
:html => 'Proc.new { render }', :html => 'Proc.new { render }',
:js => 'Proc.new { render :action => "#{action_name}.rjs" }', :js => 'Proc.new { render :action => "#{action_name}.rjs" }',
:xml => 'Proc.new { render :action => "#{action_name}.rxml" }', :xml => 'Proc.new { render :action => "#{action_name}.rxml" }'
:xml_arg => 'Proc.new { render :xml => __mime_responder_arg__ }'
} }
def initialize(block_binding) def initialize(block_binding)
...@@ -29,7 +28,7 @@ def initialize(block_binding) ...@@ -29,7 +28,7 @@ def initialize(block_binding)
@responses = {} @responses = {}
end end
def custom(mime_type, *args, &block) def custom(mime_type, &block)
mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s) mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s)
@order << mime_type @order << mime_type
...@@ -37,19 +36,14 @@ def custom(mime_type, *args, &block) ...@@ -37,19 +36,14 @@ def custom(mime_type, *args, &block)
if block_given? if block_given?
@responses[mime_type] = block @responses[mime_type] = block
else else
if argument = args.first @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding)
eval("__mime_responder_arg__ = #{argument.is_a?(String) ? argument.inspect : argument}", @block_binding)
@responses[mime_type] = eval(DEFAULT_BLOCKS[(mime_type.to_sym.to_s + "_arg").to_sym], @block_binding)
else
@responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding)
end
end end
end end
for mime_type in %w( all html js xml rss atom yaml ) for mime_type in %w( all html js xml rss atom yaml )
eval <<-EOT eval <<-EOT
def #{mime_type}(argument = nil, &block) def #{mime_type}(&block)
custom(Mime::#{mime_type.upcase}, argument, &block) custom(Mime::#{mime_type.upcase}, &block)
end end
EOT EOT
end end
......
...@@ -218,7 +218,7 @@ def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil) ...@@ -218,7 +218,7 @@ def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil)
# it's relative to the template_root, otherwise it's absolute. The hash in <tt>local_assigns</tt> # it's relative to the template_root, otherwise it's absolute. The hash in <tt>local_assigns</tt>
# is made available as local variables. # is made available as local variables.
def render_file(template_path, use_full_path = true, local_assigns = {}) def render_file(template_path, use_full_path = true, local_assigns = {})
@first_render = template_path if @first_render.nil? @first_render = template_path if @first_render.nil?
if use_full_path if use_full_path
template_path_without_extension, template_extension = path_and_extension(template_path) template_path_without_extension, template_extension = path_and_extension(template_path)
......
...@@ -70,5 +70,4 @@ def test_namespaced_controllers_auto_detect_layouts ...@@ -70,5 +70,4 @@ def test_namespaced_controllers_auto_detect_layouts
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
end end
end end
\ No newline at end of file
require File.dirname(__FILE__) + '/../abstract_unit' require File.dirname(__FILE__) + '/../abstract_unit'
class RespondToController < ActionController::Base class RespondToController < ActionController::Base
layout :set_layout
def html_xml_or_rss def html_xml_or_rss
respond_to do |type| respond_to do |type|
type.html { render :text => "HTML" } type.html { render :text => "HTML" }
...@@ -44,14 +46,6 @@ def using_defaults_with_type_list ...@@ -44,14 +46,6 @@ def using_defaults_with_type_list
respond_to(:html, :js, :xml) respond_to(:html, :js, :xml)
end end
def using_argument_defaults
person_in_xml = { :name => "David" }.to_xml(:root => "person")
respond_to do |type|
type.html
type.xml(person_in_xml)
end
end
def made_for_content_type def made_for_content_type
respond_to do |type| respond_to do |type|
type.rss { render :text => "RSS" } type.rss { render :text => "RSS" }
...@@ -75,9 +69,23 @@ def handle_any ...@@ -75,9 +69,23 @@ def handle_any
end end
end end
def all_types_with_layout
respond_to do |type|
type.html
type.js
end
end
def rescue_action(e) def rescue_action(e)
raise raise
end end
protected
def set_layout
if action_name == "all_types_with_layout"
"standard"
end
end
end end
RespondToController.template_root = File.dirname(__FILE__) + "/../fixtures/" RespondToController.template_root = File.dirname(__FILE__) + "/../fixtures/"
...@@ -173,12 +181,6 @@ def test_using_defaults_with_type_list ...@@ -173,12 +181,6 @@ def test_using_defaults_with_type_list
assert_equal "<p>Hello world!</p>\n", @response.body assert_equal "<p>Hello world!</p>\n", @response.body
end end
def test_using_argument_defaults
@request.env["HTTP_ACCEPT"] = "application/xml"
get :using_argument_defaults
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>David</name>\n</person>\n", @response.body
end
def test_with_content_type def test_with_content_type
@request.env["CONTENT_TYPE"] = "application/atom+xml" @request.env["CONTENT_TYPE"] = "application/atom+xml"
get :made_for_content_type get :made_for_content_type
...@@ -195,8 +197,8 @@ def test_synonyms ...@@ -195,8 +197,8 @@ def test_synonyms
assert_equal 'JS', @response.body assert_equal 'JS', @response.body
@request.env["HTTP_ACCEPT"] = "application/x-xml" @request.env["HTTP_ACCEPT"] = "application/x-xml"
get :using_argument_defaults get :html_xml_or_rss
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>David</name>\n</person>\n", @response.body assert_equal "XML", @response.body
end end
def test_custom_types def test_custom_types
...@@ -234,4 +236,14 @@ def test_handle_any ...@@ -234,4 +236,14 @@ def test_handle_any
get :handle_any get :handle_any
assert_equal 'Either JS or XML', @response.body assert_equal 'Either JS or XML', @response.body
end end
def test_all_types_with_layout
@request.env["HTTP_ACCEPT"] = "text/javascript"
get :all_types_with_layout
assert_equal 'RJS for all_types_with_layout', @response.body
@request.env["HTTP_ACCEPT"] = "text/html"
get :all_types_with_layout
assert_equal '<html>HTML for all_types_with_layout</html>', @response.body
end
end end
\ No newline at end of file
HTML for all_types_with_layout
\ No newline at end of file
page << "RJS for all_types_with_layout"
\ No newline at end of file
<html><%= @content_for_layout %></html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册