diff options
author | Joshua Cody <josh@joshuacody.net> | 2014-07-26 22:27:31 -0500 |
---|---|---|
committer | Joshua Cody <josh@joshuacody.net> | 2014-07-26 22:27:31 -0500 |
commit | bb8416d0943f3e797d572d127a2d74103761d947 (patch) | |
tree | 2d0d4101c213cb4d892d244091515dbb6fc2c103 /test/test_expressions.rb | |
parent | 66cee768bc163537087037a583f60639eae49fc3 (diff) | |
download | rails-bb8416d0943f3e797d572d127a2d74103761d947.tar.gz rails-bb8416d0943f3e797d572d127a2d74103761d947.tar.bz2 rails-bb8416d0943f3e797d572d127a2d74103761d947.zip |
Allow for alias omission in aggregate expressions
Diffstat (limited to 'test/test_expressions.rb')
-rw-r--r-- | test/test_expressions.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_expressions.rb b/test/test_expressions.rb new file mode 100644 index 0000000000..d061bbc335 --- /dev/null +++ b/test/test_expressions.rb @@ -0,0 +1,29 @@ +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 |