aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-05-10 13:46:37 +0200
committerYves Senn <yves.senn@gmail.com>2014-05-10 13:51:31 +0200
commited56e596a0467390011bc9d56d462539776adac1 (patch)
tree15a1746ac7c4d2a421085618b64e4d5c343ea154 /activerecord/test/cases/associations
parentf55f5e2b6d265764ff8ac23d56f768fda881f88f (diff)
downloadrails-ed56e596a0467390011bc9d56d462539776adac1.tar.gz
rails-ed56e596a0467390011bc9d56d462539776adac1.tar.bz2
rails-ed56e596a0467390011bc9d56d462539776adac1.zip
deprecate, join, preload, eager load of instance dependent associations.
Closes #15024. These operations happen before instances are created. The current behavior is misleading and can result in broken behavior.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb31
1 files changed, 27 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 7eaa5adc86..07903a3441 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -826,11 +826,15 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_preload_with_interpolation
- post = Post.includes(:comments_with_interpolated_conditions).find(posts(:welcome).id)
- assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
+ assert_deprecated do
+ post = Post.includes(:comments_with_interpolated_conditions).find(posts(:welcome).id)
+ assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
+ end
- post = Post.joins(:comments_with_interpolated_conditions).find(posts(:welcome).id)
- assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
+ assert_deprecated do
+ post = Post.joins(:comments_with_interpolated_conditions).find(posts(:welcome).id)
+ assert_equal [comments(:greetings)], post.comments_with_interpolated_conditions
+ end
end
def test_polymorphic_type_condition
@@ -1232,4 +1236,23 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal 2, author.posts.size
}
end
+
+ test "include instance dependent associations is deprecated" do
+ message = "association scope 'posts_with_signature' is"
+ assert_deprecated message do
+ begin
+ Author.includes(:posts_with_signature).to_a
+ rescue NoMethodError
+ # it's expected that preloading of this association fails
+ end
+ end
+
+ assert_deprecated message do
+ Author.preload(:posts_with_signature).to_a rescue NoMethodError
+ end
+
+ assert_deprecated message do
+ Author.eager_load(:posts_with_signature).to_a
+ end
+ end
end