提交 15426be1 编写于 作者: R Ryuta Kamizono

Avoid making query when using `where(attr: out-of-range-value)`

Like as before Rails 6.0.

Closes #38309.
上级 0d0c30e5
......@@ -87,7 +87,14 @@ def self.empty
end
def contradiction?
predicates.any? { |x| Arel::Nodes::In === x && Array === x.right && x.right.empty? }
predicates.any? do |x|
case x
when Arel::Nodes::In
Array === x.right && x.right.empty?
when Arel::Nodes::Equality
x.right.respond_to?(:unboundable?) && x.right.unboundable?
end
end
end
protected
......
......@@ -905,14 +905,18 @@ def test_pluck_loaded_relation_sql_fragment
def test_pick_one
assert_equal "The First Topic", Topic.order(:id).pick(:heading)
assert_nil Topic.none.pick(:heading)
assert_nil Topic.where(id: 9999999999999999999).pick(:heading)
assert_no_queries do
assert_nil Topic.none.pick(:heading)
assert_nil Topic.where(id: 9999999999999999999).pick(:heading)
end
end
def test_pick_two
assert_equal ["David", "david@loudthinking.com"], Topic.order(:id).pick(:author_name, :author_email_address)
assert_nil Topic.none.pick(:author_name, :author_email_address)
assert_nil Topic.where(id: 9999999999999999999).pick(:author_name, :author_email_address)
assert_no_queries do
assert_nil Topic.none.pick(:author_name, :author_email_address)
assert_nil Topic.where(id: 9999999999999999999).pick(:author_name, :author_email_address)
end
end
def test_pick_delegate_to_all
......
......@@ -397,15 +397,24 @@ def test_find_by_ids_with_limit_and_offset
end
def test_find_with_large_number
assert_raises(ActiveRecord::RecordNotFound) { Topic.find("9999999999999999999999999999999") }
Topic.send(:load_schema)
assert_no_queries do
assert_raises(ActiveRecord::RecordNotFound) { Topic.find("9999999999999999999999999999999") }
end
end
def test_find_by_with_large_number
assert_nil Topic.find_by(id: "9999999999999999999999999999999")
Topic.send(:load_schema)
assert_no_queries do
assert_nil Topic.find_by(id: "9999999999999999999999999999999")
end
end
def test_find_by_id_with_large_number
assert_nil Topic.find_by_id("9999999999999999999999999999999")
Topic.send(:load_schema)
assert_no_queries do
assert_nil Topic.find_by_id("9999999999999999999999999999999")
end
end
def test_find_on_relation_with_large_number
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册