diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-03-07 14:05:18 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-03-07 14:05:18 -0600 |
commit | ea8488caef77cb8cf2031d344e74981ab6ea0e57 (patch) | |
tree | d5aa0502f58ef3354c2baaed0779b19f11b4aa24 /actionpack | |
parent | 87e8b162463f13bd50d27398f020769460a770e3 (diff) | |
download | rails-ea8488caef77cb8cf2031d344e74981ab6ea0e57.tar.gz rails-ea8488caef77cb8cf2031d344e74981ab6ea0e57.tar.bz2 rails-ea8488caef77cb8cf2031d344e74981ab6ea0e57.zip |
Fixed simplified render with nested models [#2042 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/fake_models.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/fixtures/quiz/questions/_question.html.erb | 1 | ||||
-rw-r--r-- | actionpack/test/template/render_test.rb | 4 |
5 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 9d06d052b4..0facf7066d 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -908,6 +908,9 @@ module ActionController #:nodoc: end options = extra_options + elsif !options.is_a?(Hash) + extra_options[:partial] = options + options = extra_options end layout = pick_layout(options) diff --git a/actionpack/test/controller/fake_models.rb b/actionpack/test/controller/fake_models.rb index 7420579ed8..0b30c79b10 100644 --- a/actionpack/test/controller/fake_models.rb +++ b/actionpack/test/controller/fake_models.rb @@ -9,3 +9,11 @@ end class GoodCustomer < Customer end + +module Quiz + class Question < Struct.new(:name, :id) + def to_param + id.to_s + end + end +end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 78a4e8ccbb..e0b3f64b76 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -682,6 +682,14 @@ class TestController < ActionController::Base render :partial => "hash_object", :object => {:first_name => "Sam"} end + def partial_with_nested_object + render :partial => "quiz/questions/question", :object => Quiz::Question.new("first") + end + + def partial_with_nested_object_shorthand + render Quiz::Question.new("first") + end + def partial_hash_collection render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ] end @@ -1479,6 +1487,16 @@ class RenderTest < ActionController::TestCase assert_equal "Sam\nmaS\n", @response.body end + def test_partial_with_nested_object + get :partial_with_nested_object + assert_equal "first", @response.body + end + + def test_partial_with_nested_object_shorthand + get :partial_with_nested_object_shorthand + assert_equal "first", @response.body + end + def test_hash_partial_collection get :partial_hash_collection assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body diff --git a/actionpack/test/fixtures/quiz/questions/_question.html.erb b/actionpack/test/fixtures/quiz/questions/_question.html.erb new file mode 100644 index 0000000000..fb4dcfee64 --- /dev/null +++ b/actionpack/test/fixtures/quiz/questions/_question.html.erb @@ -0,0 +1 @@ +<%= question.name %>
\ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b042eb3d9b..9adf053b09 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -145,6 +145,10 @@ module RenderTestCases assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name end + def test_render_object + assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david")) + end + def test_render_partial_collection assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) end |