aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2014-03-30 20:23:50 +0200
committerthedarkone <thedarkone2@gmail.com>2014-03-30 20:23:50 +0200
commitde32d972bfde8871f7c1a4621f2223ea9b6715b2 (patch)
treebff561681218b1362952fd93151f6b2833e7dbc0 /activerecord/test
parent593e6978656e3dd07683d2add186b72c9fbad683 (diff)
downloadrails-de32d972bfde8871f7c1a4621f2223ea9b6715b2.tar.gz
rails-de32d972bfde8871f7c1a4621f2223ea9b6715b2.tar.bz2
rails-de32d972bfde8871f7c1a4621f2223ea9b6715b2.zip
Fix polymorphic preloads on NOT NULL _type columns.
Defer to Association#klass instead of having a custom/duplicate code.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index e59161fc5b..d594697280 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -235,6 +235,17 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
end
+ def test_finding_with_includes_on_empty_polymorphic_type_column
+ sponsor = sponsors(:moustache_club_sponsor_for_groucho)
+ sponsor.update!(sponsorable_type: '', sponsorable_id: nil) # sponsorable_type column might be declared NOT NULL
+ sponsor = assert_queries(1) do
+ assert_nothing_raised { Sponsor.all.merge!(:includes => :sponsorable).find(sponsor.id) }
+ end
+ assert_no_queries do
+ assert_equal nil, sponsor.sponsorable
+ end
+ end
+
def test_loading_from_an_association
posts = authors(:david).posts.merge(:includes => :comments, :order => "posts.id").to_a
assert_equal 2, posts.first.comments.size