mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42317 from martinjaimem/enhancement/add-test-for-or-query-error-message
Added test for or query error message
This commit is contained in:
commit
0f5700ac35
2 changed files with 46 additions and 1 deletions
43
activerecord/test/cases/relation/and_test.rb
Normal file
43
activerecord/test/cases/relation/and_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "cases/helper"
|
||||
require "models/author"
|
||||
|
||||
module ActiveRecord
|
||||
class AndTest < ActiveRecord::TestCase
|
||||
fixtures :authors
|
||||
|
||||
def test_and
|
||||
david, mary, bob = authors(:david, :mary, :bob)
|
||||
|
||||
david_and_mary = Author.where(id: [david, mary]).order(:id)
|
||||
mary_and_bob = Author.where(id: [mary, bob]).order(:id)
|
||||
|
||||
assert_equal [mary], david_and_mary.and(mary_and_bob)
|
||||
end
|
||||
|
||||
def test_and_with_non_relation_attribute
|
||||
hash = { "id" => 123 }
|
||||
error = assert_raises(ArgumentError) do
|
||||
Author.and(hash)
|
||||
end
|
||||
|
||||
assert_equal(
|
||||
"You have passed Hash object to #and. Pass an ActiveRecord::Relation object instead.",
|
||||
error.message
|
||||
)
|
||||
end
|
||||
|
||||
def test_and_with_structurally_incompatible_scope
|
||||
posts_scope = Author.unscope(:order).limit(10).offset(10).select(:id).order(:id)
|
||||
error = assert_raises(ArgumentError) do
|
||||
Author.limit(10).select(:id).order(:name).and(posts_scope)
|
||||
end
|
||||
|
||||
assert_equal(
|
||||
"Relation passed to #and must be structurally compatible. Incompatible values: [:order, :offset]",
|
||||
error.message
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -133,9 +133,11 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def test_or_with_non_relation_object_raises_error
|
||||
assert_raises ArgumentError do
|
||||
error = assert_raises ArgumentError do
|
||||
Post.where(id: [1, 2, 3]).or(title: "Rails")
|
||||
end
|
||||
|
||||
assert_equal "You have passed Hash object to #or. Pass an ActiveRecord::Relation object instead.", error.message
|
||||
end
|
||||
|
||||
def test_or_with_references_inequality
|
||||
|
|
Loading…
Reference in a new issue