diff options
author | José Valim <jose.valim@gmail.com> | 2010-02-16 23:26:29 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-02-16 23:26:29 +0100 |
commit | b1edd096626d6f536b87ff5e307c37a89dd78133 (patch) | |
tree | 10521b97477f883af2cad10cf992ec58ca6d68e6 /actionpack | |
parent | 47a236e291f0235a08ce4bb2a2d43fe221794461 (diff) | |
download | rails-b1edd096626d6f536b87ff5e307c37a89dd78133.tar.gz rails-b1edd096626d6f536b87ff5e307c37a89dd78133.tar.bz2 rails-b1edd096626d6f536b87ff5e307c37a89dd78133.zip |
Ensure render :text => resource first tries to invoke :to_text on it
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/rendering.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 9 | ||||
-rw-r--r-- | actionpack/test/lib/controller/fake_models.rb | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 0aae9f8579..0bd362fd64 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -36,6 +36,13 @@ module ActionController super end + def _determine_template(options) + if options.key?(:text) && options[:text].respond_to?(:to_text) + options[:text] = options[:text].to_text + end + super + end + def format_for_text formats.first end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 2c3dc2a72d..eceec3b08e 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -214,6 +214,10 @@ class TestController < ActionController::Base render :text => false end + def render_text_with_resource + render :text => Customer.new("David") + end + # :ported: def render_nothing_with_appendix render :text => "appended" @@ -817,6 +821,11 @@ class RenderTest < ActionController::TestCase assert_equal 'appended', @response.body end + def test_render_text_with_resource + get :render_text_with_resource + assert_equal 'name: David', @response.body + end + # :ported: def test_attempt_to_access_object_method assert_raise(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index 7346cb22bc..a8c86f70b6 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -21,6 +21,7 @@ class Customer < Struct.new(:name, :id) def to_js(options={}) "name: #{name.inspect}" end + alias :to_text :to_js def errors [] |