Skip to content

Commit

Permalink
Fixed simplified render with nested models [#2042 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Mar 7, 2009
1 parent 87e8b16 commit ea8488c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -907,6 +907,9 @@ def render(options = nil, extra_options = {}, &block) #:doc:
extra_options[:template] = options
end

options = extra_options
elsif !options.is_a?(Hash)
extra_options[:partial] = options
options = extra_options
end

Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/fake_models.rb
Expand Up @@ -9,3 +9,11 @@ class BadCustomer < Customer

class GoodCustomer < Customer
end

module Quiz
class Question < Struct.new(:name, :id)
def to_param
id.to_s
end
end
end
18 changes: 18 additions & 0 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -682,6 +682,14 @@ def partial_with_hash_object
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
Expand Down Expand Up @@ -1479,6 +1487,16 @@ def test_partial_with_hash_object
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
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/quiz/questions/_question.html.erb
@@ -0,0 +1 @@
<%= question.name %>
4 changes: 4 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -145,6 +145,10 @@ def test_render_sub_template_with_errors
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
Expand Down

0 comments on commit ea8488c

Please sign in to comment.