1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Allow Relation#rewhere to work with infinite range values

This commit is contained in:
Dan Olson 2014-10-27 09:35:34 -05:00
parent d616fec811
commit 68bad9960a
2 changed files with 22 additions and 1 deletions

View file

@ -913,7 +913,7 @@ module ActiveRecord
where_values.reject! do |rel| where_values.reject! do |rel|
case rel case rel
when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right) subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name == target_value subrelation.name == target_value
end end

View file

@ -156,5 +156,26 @@ module ActiveRecord
assert_equal 1, relation.where_values.size assert_equal 1, relation.where_values.size
assert_equal Post.where(comments_count: 3..5), relation assert_equal Post.where(comments_count: 3..5), relation
end end
def test_rewhere_with_infinite_upper_bound_range
relation = Post.where(comments_count: 1..Float::INFINITY).rewhere(comments_count: 3..5)
assert_equal 1, relation.where_values.size
assert_equal Post.where(comments_count: 3..5), relation
end
def test_rewhere_with_infinite_lower_bound_range
relation = Post.where(comments_count: -Float::INFINITY..1).rewhere(comments_count: 3..5)
assert_equal 1, relation.where_values.size
assert_equal Post.where(comments_count: 3..5), relation
end
def test_rewhere_with_infinite_range
relation = Post.where(comments_count: -Float::INFINITY..Float::INFINITY).rewhere(comments_count: 3..5)
assert_equal 1, relation.where_values.size
assert_equal Post.where(comments_count: 3..5), relation
end
end end
end end