diff options
author | Joshua Cody <josh@joshuacody.net> | 2014-07-31 07:49:57 -0500 |
---|---|---|
committer | Joshua Cody <josh@joshuacody.net> | 2014-07-31 07:49:57 -0500 |
commit | 712c002af51700d128eb45996687600bb20c75a7 (patch) | |
tree | 4caf67fe5b75c6925cf3cb80b6a19f109d18a4a8 /test | |
parent | bb8416d0943f3e797d572d127a2d74103761d947 (diff) | |
download | rails-712c002af51700d128eb45996687600bb20c75a7.tar.gz rails-712c002af51700d128eb45996687600bb20c75a7.tar.bz2 rails-712c002af51700d128eb45996687600bb20c75a7.zip |
Remove default aliases from aggregate functions
Diffstat (limited to 'test')
-rw-r--r-- | test/attributes/test_attribute.rb | 17 | ||||
-rw-r--r-- | test/test_expressions.rb | 29 |
2 files changed, 7 insertions, 39 deletions
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index 38ee189a46..f8886297a3 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -82,7 +82,7 @@ module Arel 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") AS avg_id FROM "users") + SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") FROM "users") } end end @@ -269,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 @@ -286,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 @@ -310,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 diff --git a/test/test_expressions.rb b/test/test_expressions.rb deleted file mode 100644 index d061bbc335..0000000000 --- a/test/test_expressions.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'helper' - -module Arel - describe "Expressions" do - before do - @table = Table.new(:users) - end - - describe "average" do - it "aliases the average as avg_id by default" do - @table[:score].average.to_sql.must_be_like %{ - AVG("users"."score") AS avg_id - } - end - - it "aliases the average as another string" do - @table[:score].average("my_alias").to_sql.must_be_like %{ - AVG("users"."score") AS my_alias - } - end - - it "omits the alias if nil" do - @table[:score].average(nil).to_sql.must_be_like %{ - AVG("users"."score") - } - end - end - end -end |