提交 6bc5bd26 编写于 作者: R Ryuta Kamizono

Improve deprecation message for nested `where.not` condition

上级 ea0755c5
......@@ -52,7 +52,15 @@ def not(opts, *rest)
ActiveSupport::Deprecation.warn(<<~MSG.squish)
NOT conditions will no longer behave as NOR in Rails 6.1.
To continue using NOR conditions, NOT each conditions manually
(`#{ opts.keys.map { |key| ".where.not(#{key.inspect} => ...)" }.join }`).
(`#{
opts.flat_map { |key, value|
if value.is_a?(Hash) && value.size > 1
value.map { |k, v| ".where.not(#{key.inspect} => { #{k.inspect} => ... })" }
else
".where.not(#{key.inspect} => ...)"
end
}.join
}`).
MSG
@scope.where_clause += where_clause.invert(:nor)
else
......
......@@ -184,9 +184,14 @@ def test_where_not_polymorphic_id_and_type_as_nor_is_deprecated
def test_where_not_association_as_nor_is_deprecated
treasure = Treasure.create!(name: "my_treasure")
PriceEstimate.create!(estimate_of: treasure, price: 2, currency: "USD")
PriceEstimate.create(estimate_of: treasure, price: 2, currency: "EUR")
PriceEstimate.create!(estimate_of: treasure, price: 2, currency: "EUR")
assert_deprecated do
message = <<~MSG.squish
NOT conditions will no longer behave as NOR in Rails 6.1.
To continue using NOR conditions, NOT each conditions manually
(`.where.not(:price_estimates => { :price => ... }).where.not(:price_estimates => { :currency => ... })`).
MSG
assert_deprecated(message) do
result = Treasure.joins(:price_estimates).where.not(price_estimates: { price: 2, currency: "USD" })
assert_predicate result, :empty?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册