aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-07 13:38:54 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-07 13:40:50 -0300
commit1b4399dfe7eaa8dd2a75f35815ea429962c51a29 (patch)
treebdab5581deb27dda70a0a034535fe42667a01c20 /activerecord/test/cases/relations_test.rb
parent4cc5917dce83fb841ac78b250ef3d1024168eb1e (diff)
downloadrails-1b4399dfe7eaa8dd2a75f35815ea429962c51a29.tar.gz
rails-1b4399dfe7eaa8dd2a75f35815ea429962c51a29.tar.bz2
rails-1b4399dfe7eaa8dd2a75f35815ea429962c51a29.zip
Fix regression caused by a01d164b
When preload is used in a default scope the preload_values were returning nested arrays and causing the preloader to fail because it doesn't know how to deal with nested arrays. So before calling preload! we need to splat the arguments. This is not needed to includes because it flatten its arguments.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index acbf85d398..5f48c2b40f 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -647,6 +647,25 @@ class RelationTest < ActiveRecord::TestCase
end
end
+ def test_preloading_with_associations_default_scopes_and_merges
+ post = Post.create! title: 'Uhuu', body: 'body'
+ reader = Reader.create! post_id: post.id, person_id: 1
+
+ post_rel = PostWithPreloadDefaultScope.preload(:readers).joins(:readers).where(title: 'Uhuu')
+ result_post = PostWithPreloadDefaultScope.all.merge(post_rel).to_a.first
+
+ assert_no_queries do
+ assert_equal [reader], result_post.readers.to_a
+ end
+
+ post_rel = PostWithIncludesDefaultScope.includes(:readers).where(title: 'Uhuu')
+ result_post = PostWithIncludesDefaultScope.all.merge(post_rel).to_a.first
+
+ assert_no_queries do
+ assert_equal [reader], result_post.readers.to_a
+ end
+ end
+
def test_loading_with_one_association
posts = Post.preload(:comments)
post = posts.find { |p| p.id == 1 }