aboutsummaryrefslogtreecommitdiffstats
path: root/test/attributes
diff options
context:
space:
mode:
Diffstat (limited to 'test/attributes')
-rw-r--r--test/attributes/test_attribute.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb
index e53b32d0ac..dd2d9d343e 100644
--- a/test/attributes/test_attribute.rb
+++ b/test/attributes/test_attribute.rb
@@ -66,7 +66,7 @@ module Arel
relation[:id].gt(10).must_be_kind_of Nodes::GreaterThan
end
- it 'should generate >= in sql' do
+ it 'should generate > in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt(10)
@@ -74,6 +74,17 @@ module Arel
SELECT "users"."id" FROM "users" WHERE "users"."id" > 10
}
end
+
+ it 'should handle comparing with a subquery' do
+ users = Table.new(:users)
+
+ avg = users.project(users[:karma].average)
+ mgr = users.project(Arel.star).where(users[:karma].gt(avg))
+
+ mgr.to_sql.must_be_like %{
+ SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") FROM "users")
+ }
+ end
end
describe '#gt_any' do
@@ -258,12 +269,11 @@ module Arel
relation[:id].average.must_be_kind_of Nodes::Avg
end
- # FIXME: backwards compat. Is this really necessary?
- it 'should set the alias to "avg_id"' do
+ it 'should generate the proper SQL' do
relation = Table.new(:users)
mgr = relation.project relation[:id].average
mgr.to_sql.must_be_like %{
- SELECT AVG("users"."id") AS avg_id
+ SELECT AVG("users"."id")
FROM "users"
}
end
@@ -275,12 +285,11 @@ module Arel
relation[:id].maximum.must_be_kind_of Nodes::Max
end
- # FIXME: backwards compat. Is this really necessary?
- it 'should set the alias to "max_id"' do
+ it 'should generate the proper SQL' do
relation = Table.new(:users)
mgr = relation.project relation[:id].maximum
mgr.to_sql.must_be_like %{
- SELECT MAX("users"."id") AS max_id
+ SELECT MAX("users"."id")
FROM "users"
}
end
@@ -299,12 +308,11 @@ module Arel
relation[:id].sum.must_be_kind_of Nodes::Sum
end
- # FIXME: backwards compat. Is this really necessary?
- it 'should set the alias to "sum_id"' do
+ it 'should generate the proper SQL' do
relation = Table.new(:users)
mgr = relation.project relation[:id].sum
mgr.to_sql.must_be_like %{
- SELECT SUM("users"."id") AS sum_id
+ SELECT SUM("users"."id")
FROM "users"
}
end
@@ -550,8 +558,6 @@ module Arel
end
describe '#not_in' do
- it 'can be constructed with a list' do
- end
it 'should return a NotIn node' do
attribute = Attribute.new nil, nil