aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-01 03:53:39 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-01 03:53:39 +0000
commita6a1dc967cb65ac3f842d15f89eef7e32f7547cf (patch)
tree0d49ee17962c31f2218b6dc3a45fe4b5281aa011
parentb05fc40b5d096695dad5b3282664512d7509a529 (diff)
downloadrails-a6a1dc967cb65ac3f842d15f89eef7e32f7547cf.tar.gz
rails-a6a1dc967cb65ac3f842d15f89eef7e32f7547cf.tar.bz2
rails-a6a1dc967cb65ac3f842d15f89eef7e32f7547cf.zip
render :partial recognizes Active Record associations as Arrays. Closes #8538.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6920 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/partials.rb2
-rw-r--r--actionpack/test/activerecord/render_partial_with_record_identification_test.rb64
-rw-r--r--actionpack/test/fixtures/topic.rb2
4 files changed, 68 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 7bd1a71d7c..016eb72363 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* render :partial recognizes Active Record associations as Arrays. #8538 [kamal]
+
* Routing: drop semicolon and comma as route separators. [Jeremy Kemper]
* request.remote_ip understands X-Forwarded-For addresses with nonstandard whitespace. #7386 [moses]
diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb
index 4d7e276255..06e69bcccf 100644
--- a/actionpack/lib/action_view/partials.rb
+++ b/actionpack/lib/action_view/partials.rb
@@ -64,7 +64,7 @@ module ActionView
else
render("#{path}/_#{partial_name}", local_assigns)
end
- when Array
+ when Array, ActiveRecord::Associations::AssociationCollection
if partial_path.any?
path = ActionController::RecordIdentifier.partial_path(partial_path.first)
collection = partial_path
diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
new file mode 100644
index 0000000000..7aeb1192f1
--- /dev/null
+++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../active_record_unit'
+
+class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
+ fixtures :developers, :projects, :developers_projects, :topics, :replies
+
+ class RenderPartialWithRecordIdentificationController < ActionController::Base
+ def render_with_has_many_and_belongs_to_association
+ @developer = Developer.find(1)
+ render :partial => @developer.projects
+ end
+
+ def render_with_has_many_association
+ @topic = Topic.find(1)
+ render :partial => @topic.replies
+ end
+
+ def render_with_belongs_to_association
+ @reply = Reply.find(1)
+ render :partial => @reply.topic
+ end
+
+ def render_with_record
+ @developer = Developer.find(:first)
+ render :partial => @developer
+ end
+
+ def render_with_record_collection
+ @developers = Developer.find(:all)
+ render :partial => @developers
+ end
+ end
+
+ def setup
+ @controller = RenderPartialWithRecordIdentificationController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ super
+ end
+
+ def test_rendering_partial_with_has_many_and_belongs_to_association
+ get :render_with_has_many_and_belongs_to_association
+ assert_template 'projects/_project'
+ end
+
+ def test_rendering_partial_with_has_many_association
+ get :render_with_has_many_association
+ assert_template 'replies/_reply'
+ end
+
+ def test_rendering_partial_with_belongs_to_association
+ get :render_with_belongs_to_association
+ assert_template 'topics/_topic'
+ end
+
+ def test_render_with_record
+ get :render_with_record
+ assert_template 'developers/_developer'
+ end
+
+ def test_render_with_record_collection
+ get :render_with_record_collection
+ assert_template 'developers/_developer'
+ end
+end
diff --git a/actionpack/test/fixtures/topic.rb b/actionpack/test/fixtures/topic.rb
index 0beeecf28d..9fa9746535 100644
--- a/actionpack/test/fixtures/topic.rb
+++ b/actionpack/test/fixtures/topic.rb
@@ -1,3 +1,3 @@
class Topic < ActiveRecord::Base
- has_many :replies, :include => [:user], :dependent => :destroy
+ has_many :replies, :dependent => :destroy
end