diff options
author | Rob Trame <Redapted@users.noreply.github.com> | 2019-05-01 13:53:35 -0700 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2019-05-01 15:53:35 -0500 |
commit | f4fd7d1d20dfbc4389435a8f0f153f7960bb1544 (patch) | |
tree | f54f9768c049730b19b3c0e5d3ed752f99598950 /activerecord/test | |
parent | f8243f81ffc561420c2404cb344f9d9b85b818d7 (diff) | |
download | rails-f4fd7d1d20dfbc4389435a8f0f153f7960bb1544.tar.gz rails-f4fd7d1d20dfbc4389435a8f0f153f7960bb1544.tar.bz2 rails-f4fd7d1d20dfbc4389435a8f0f153f7960bb1544.zip |
Make scope arity check consistent (#36134)
* Make scope arity check consistent
* Add test for arity change
[Rob Trame + Rafael Mendonça França]
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 18 | ||||
-rw-r--r-- | activerecord/test/models/author.rb | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index b865002f03..49bcb1d010 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1516,6 +1516,24 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_match message, error.message end + test "preloading and eager loading of optional instance dependent associations is not supported" do + message = "association scope 'posts_mentioning_author' is" + error = assert_raises(ArgumentError) do + Author.includes(:posts_mentioning_author).to_a + end + assert_match message, error.message + + error = assert_raises(ArgumentError) do + Author.preload(:posts_mentioning_author).to_a + end + assert_match message, error.message + + error = assert_raises(ArgumentError) do + Author.eager_load(:posts_mentioning_author).to_a + end + assert_match message, error.message + end + test "preload with invalid argument" do exception = assert_raises(ArgumentError) do Author.preload(10).to_a diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 67be59a1fe..b52b643ad7 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -153,6 +153,7 @@ class Author < ActiveRecord::Base has_many :comments_on_posts_with_default_include, through: :posts_with_default_include, source: :comments has_many :posts_with_signature, ->(record) { where("posts.title LIKE ?", "%by #{record.name.downcase}%") }, class_name: "Post" + has_many :posts_mentioning_author, ->(record = nil) { where("posts.body LIKE ?", "%#{record&.name&.downcase}%") }, class_name: "Post" has_many :posts_with_extension, -> { order(:title) }, class_name: "Post" do def extension_method; end |