diff options
author | Dan Olson <daniel.olson@code42.com> | 2014-10-27 09:35:34 -0500 |
---|---|---|
committer | Dan Olson <daniel.olson@code42.com> | 2014-10-27 09:42:07 -0500 |
commit | 68bad9960a07508e24726d598d86fc26a2931264 (patch) | |
tree | c00d6fcbef69b904fe8753039108e1904694df94 | |
parent | d616fec8117ac25753ee23e15ac14261d298ee51 (diff) | |
download | rails-68bad9960a07508e24726d598d86fc26a2931264.tar.gz rails-68bad9960a07508e24726d598d86fc26a2931264.tar.bz2 rails-68bad9960a07508e24726d598d86fc26a2931264.zip |
Allow Relation#rewhere to work with infinite range values
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_chain_test.rb | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index a53e8c9d0a..e4bebf78e8 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -913,7 +913,7 @@ module ActiveRecord where_values.reject! do |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.name == target_value end diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index 478ac1bc42..619055f1e7 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -156,5 +156,26 @@ module ActiveRecord assert_equal 1, relation.where_values.size assert_equal Post.where(comments_count: 3..5), relation 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 |