diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 5c3c0513dc..eec05e9458 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1162,7 +1162,7 @@ module ActiveRecord records.compact! unless records.all?(klass) - raise ArgumentError, "You must only pass a single or collection of #{klass.name} objects to #excluding." + raise ArgumentError, "You must only pass a single or collection of #{klass.name} objects to ##{__callee__}." end spawn.excluding!(records) diff --git a/activerecord/test/cases/excluding_test.rb b/activerecord/test/cases/excluding_test.rb index e2fb7d61a3..2d120db10c 100644 --- a/activerecord/test/cases/excluding_test.rb +++ b/activerecord/test/cases/excluding_test.rb @@ -48,6 +48,9 @@ class ExcludingTest < ActiveRecord::TestCase def test_raises_on_record_from_different_class error = assert_raises(ArgumentError) { Post.excluding(@post, comments(:greetings)) } assert_equal "You must only pass a single or collection of Post objects to #excluding.", error.message + + error = assert_raises(ArgumentError) { Post.without(@post, comments(:greetings)) } + assert_equal "You must only pass a single or collection of Post objects to #without.", error.message end private