aboutsummaryrefslogtreecommitdiffstats
path: root/test/attributes
diff options
context:
space:
mode:
Diffstat (limited to 'test/attributes')
-rw-r--r--test/attributes/test_attribute.rb258
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