diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-10-25 07:38:56 -0500 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-10-25 07:38:56 -0500 |
commit | f8d85cf24bca522a04edc5cc48f8716e65efb107 (patch) | |
tree | 400a9d564be166d15cb6566dd78cd251f8aeaef5 /test/attributes | |
parent | df5723dfbe856abc8c91cc87c609156b432e97d3 (diff) | |
download | rails-f8d85cf24bca522a04edc5cc48f8716e65efb107.tar.gz rails-f8d85cf24bca522a04edc5cc48f8716e65efb107.tar.bz2 rails-f8d85cf24bca522a04edc5cc48f8716e65efb107.zip |
Deprecate passing ranges to `#in` and `#not_in`
The goal of these methods should be to generate in nodes, not handle
every possible permutation of more than one value. The `#between` and
`#not_between` methods have been extracted, which better represent the
semantics of handling ranges in SQL.
Diffstat (limited to 'test/attributes')
-rw-r--r-- | test/attributes/test_attribute.rb | 258 |
1 files changed, 129 insertions, 129 deletions
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index 0851a07258..500f9385f8 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -548,84 +548,84 @@ module Arel end end - describe '#in' do - it 'can be constructed with a subquery' do - relation = Table.new(:users) - mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + describe 'with a range' do + it 'can be constructed with a standard range' do attribute = Attribute.new nil, nil + node = attribute.between(1..3) - node = attribute.in(mgr) - - node.must_equal Nodes::In.new(attribute, mgr.ast) + node.must_equal Nodes::Between.new( + attribute, + Nodes::And.new([ + Nodes::Casted.new(1, attribute), + Nodes::Casted.new(3, attribute) + ]) + ) end - describe 'with a range' do - it 'can be constructed with a standard range' do - attribute = Attribute.new nil, nil - node = attribute.in(1..3) + it 'can be constructed with a range starting from -Infinity' do + attribute = Attribute.new nil, nil + node = attribute.between(-::Float::INFINITY..3) - node.must_equal Nodes::Between.new( - attribute, - Nodes::And.new([ - Nodes::Casted.new(1, attribute), - Nodes::Casted.new(3, attribute) - ]) - ) - end + node.must_equal Nodes::LessThanOrEqual.new( + attribute, + Nodes::Casted.new(3, attribute) + ) + end - it 'can be constructed with a range starting from -Infinity' do - attribute = Attribute.new nil, nil - node = attribute.in(-::Float::INFINITY..3) + it 'can be constructed with an exclusive range starting from -Infinity' do + attribute = Attribute.new nil, nil + node = attribute.between(-::Float::INFINITY...3) - node.must_equal Nodes::LessThanOrEqual.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - end + node.must_equal Nodes::LessThan.new( + attribute, + Nodes::Casted.new(3, attribute) + ) + end - it 'can be constructed with an exclusive range starting from -Infinity' do - attribute = Attribute.new nil, nil - node = attribute.in(-::Float::INFINITY...3) + it 'can be constructed with an infinite range' do + attribute = Attribute.new nil, nil + node = attribute.between(-::Float::INFINITY..::Float::INFINITY) - node.must_equal Nodes::LessThan.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - end + node.must_equal Nodes::NotIn.new(attribute, []) + end - it 'can be constructed with an infinite range' do - attribute = Attribute.new nil, nil - node = attribute.in(-::Float::INFINITY..::Float::INFINITY) + it 'can be constructed with a range ending at Infinity' do + attribute = Attribute.new nil, nil + node = attribute.between(0..::Float::INFINITY) - node.must_equal Nodes::NotIn.new(attribute, []) - end + node.must_equal Nodes::GreaterThanOrEqual.new( + attribute, + Nodes::Casted.new(0, attribute) + ) + end - it 'can be constructed with a range ending at Infinity' do - attribute = Attribute.new nil, nil - node = attribute.in(0..::Float::INFINITY) + it 'can be constructed with an exclusive range' do + attribute = Attribute.new nil, nil + node = attribute.between(0...3) - node.must_equal Nodes::GreaterThanOrEqual.new( + node.must_equal Nodes::And.new([ + Nodes::GreaterThanOrEqual.new( attribute, Nodes::Casted.new(0, attribute) + ), + Nodes::LessThan.new( + attribute, + Nodes::Casted.new(3, attribute) ) - end - - it 'can be constructed with an exclusive range' do - attribute = Attribute.new nil, nil - node = attribute.in(0...3) - - node.must_equal Nodes::And.new([ - Nodes::GreaterThanOrEqual.new( - attribute, - Nodes::Casted.new(0, attribute) - ), - Nodes::LessThan.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - ]) - end + ]) + end + end + + describe '#in' do + it 'can be constructed with a subquery' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + attribute = Attribute.new nil, nil + + node = attribute.in(mgr) + + node.must_equal Nodes::In.new(attribute, mgr.ast) end it 'can be constructed with a list' do @@ -695,87 +695,87 @@ module Arel end end - describe '#not_in' do - it 'can be constructed with a subquery' do - relation = Table.new(:users) - mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + describe 'with a range' do + it 'can be constructed with a standard range' do attribute = Attribute.new nil, nil + node = attribute.not_between(1..3) - node = attribute.not_in(mgr) - - node.must_equal Nodes::NotIn.new(attribute, mgr.ast) - end - - describe 'with a range' do - it 'can be constructed with a standard range' do - attribute = Attribute.new nil, nil - node = attribute.not_in(1..3) - - node.must_equal Nodes::Grouping.new(Nodes::Or.new( - Nodes::LessThan.new( - attribute, - Nodes::Casted.new(1, attribute) - ), - Nodes::GreaterThan.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - )) - end - - it 'can be constructed with a range starting from -Infinity' do - attribute = Attribute.new nil, nil - node = attribute.not_in(-::Float::INFINITY..3) - - node.must_equal Nodes::GreaterThan.new( + node.must_equal Nodes::Grouping.new(Nodes::Or.new( + Nodes::LessThan.new( + attribute, + Nodes::Casted.new(1, attribute) + ), + Nodes::GreaterThan.new( attribute, Nodes::Casted.new(3, attribute) ) - end + )) + end - it 'can be constructed with an exclusive range starting from -Infinity' do - attribute = Attribute.new nil, nil - node = attribute.not_in(-::Float::INFINITY...3) + it 'can be constructed with a range starting from -Infinity' do + attribute = Attribute.new nil, nil + node = attribute.not_between(-::Float::INFINITY..3) - node.must_equal Nodes::GreaterThanOrEqual.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - end + node.must_equal Nodes::GreaterThan.new( + attribute, + Nodes::Casted.new(3, attribute) + ) + end + + it 'can be constructed with an exclusive range starting from -Infinity' do + attribute = Attribute.new nil, nil + node = attribute.not_between(-::Float::INFINITY...3) + + node.must_equal Nodes::GreaterThanOrEqual.new( + attribute, + Nodes::Casted.new(3, attribute) + ) + end - it 'can be constructed with an infinite range' do - attribute = Attribute.new nil, nil - node = attribute.not_in(-::Float::INFINITY..::Float::INFINITY) + it 'can be constructed with an infinite range' do + attribute = Attribute.new nil, nil + node = attribute.not_between(-::Float::INFINITY..::Float::INFINITY) - node.must_equal Nodes::In.new(attribute, []) - end + node.must_equal Nodes::In.new(attribute, []) + end - it 'can be constructed with a range ending at Infinity' do - attribute = Attribute.new nil, nil - node = attribute.not_in(0..::Float::INFINITY) + it 'can be constructed with a range ending at Infinity' do + attribute = Attribute.new nil, nil + node = attribute.not_between(0..::Float::INFINITY) - node.must_equal Nodes::LessThan.new( + node.must_equal Nodes::LessThan.new( + attribute, + Nodes::Casted.new(0, attribute) + ) + end + + it 'can be constructed with an exclusive range' do + attribute = Attribute.new nil, nil + node = attribute.not_between(0...3) + + node.must_equal Nodes::Grouping.new(Nodes::Or.new( + Nodes::LessThan.new( attribute, Nodes::Casted.new(0, attribute) + ), + Nodes::GreaterThanOrEqual.new( + attribute, + Nodes::Casted.new(3, attribute) ) - end - - it 'can be constructed with an exclusive range' do - attribute = Attribute.new nil, nil - node = attribute.not_in(0...3) - - node.must_equal Nodes::Grouping.new(Nodes::Or.new( - Nodes::LessThan.new( - attribute, - Nodes::Casted.new(0, attribute) - ), - Nodes::GreaterThanOrEqual.new( - attribute, - Nodes::Casted.new(3, attribute) - ) - )) - end + )) + end + end + + describe '#not_in' do + it 'can be constructed with a subquery' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + attribute = Attribute.new nil, nil + + node = attribute.not_in(mgr) + + node.must_equal Nodes::NotIn.new(attribute, mgr.ast) end it 'can be constructed with a list' do |