diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-05-15 04:35:44 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-15 04:35:44 +0900 |
commit | ff083eea0b4e1d273e8309f0257337dbc8615fc8 (patch) | |
tree | 1184e4c61b0eeec89914d9747cf3edc6d3380d3c /activerecord/test | |
parent | df850b8d7126044a820291bbfd2bce80636a442c (diff) | |
parent | 2beafeddf0378c0b4b0780c0d57c694b79f1f710 (diff) | |
download | rails-ff083eea0b4e1d273e8309f0257337dbc8615fc8.tar.gz rails-ff083eea0b4e1d273e8309f0257337dbc8615fc8.tar.bz2 rails-ff083eea0b4e1d273e8309f0257337dbc8615fc8.zip |
Merge pull request #32724 from nikolai-b/add_math_test
Add math test
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/arel/attributes/math_test.rb | 83 | ||||
-rw-r--r-- | activerecord/test/cases/arel/nodes/count_test.rb | 9 |
2 files changed, 83 insertions, 9 deletions
diff --git a/activerecord/test/cases/arel/attributes/math_test.rb b/activerecord/test/cases/arel/attributes/math_test.rb new file mode 100644 index 0000000000..f3aabe4f60 --- /dev/null +++ b/activerecord/test/cases/arel/attributes/math_test.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require_relative "../helper" + +module Arel + module Attributes + class MathTest < Arel::Spec + %i[* /].each do |math_operator| + it "average should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].average.public_send(math_operator, 2)).to_sql.must_be_like %{ + AVG("users"."id") #{math_operator} 2 + } + end + + it "count should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].count.public_send(math_operator, 2)).to_sql.must_be_like %{ + COUNT("users"."id") #{math_operator} 2 + } + end + + it "maximum should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].maximum.public_send(math_operator, 2)).to_sql.must_be_like %{ + MAX("users"."id") #{math_operator} 2 + } + end + + it "minimum should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].minimum.public_send(math_operator, 2)).to_sql.must_be_like %{ + MIN("users"."id") #{math_operator} 2 + } + end + + it "attribute node should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].public_send(math_operator, 2)).to_sql.must_be_like %{ + "users"."id" #{math_operator} 2 + } + end + end + + %i[+ - & | ^ << >>].each do |math_operator| + it "average should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].average.public_send(math_operator, 2)).to_sql.must_be_like %{ + (AVG("users"."id") #{math_operator} 2) + } + end + + it "count should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].count.public_send(math_operator, 2)).to_sql.must_be_like %{ + (COUNT("users"."id") #{math_operator} 2) + } + end + + it "maximum should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].maximum.public_send(math_operator, 2)).to_sql.must_be_like %{ + (MAX("users"."id") #{math_operator} 2) + } + end + + it "minimum should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].minimum.public_send(math_operator, 2)).to_sql.must_be_like %{ + (MIN("users"."id") #{math_operator} 2) + } + end + + it "attribute node should be compatiable with #{math_operator}" do + table = Arel::Table.new :users + (table[:id].public_send(math_operator, 2)).to_sql.must_be_like %{ + ("users"."id" #{math_operator} 2) + } + end + end + end + end +end diff --git a/activerecord/test/cases/arel/nodes/count_test.rb b/activerecord/test/cases/arel/nodes/count_test.rb index 3107659e77..daabea6c4c 100644 --- a/activerecord/test/cases/arel/nodes/count_test.rb +++ b/activerecord/test/cases/arel/nodes/count_test.rb @@ -32,13 +32,4 @@ class Arel::Nodes::CountTest < Arel::Spec assert_equal 2, array.uniq.size end end - - describe "math" do - it "allows mathematical functions" do - table = Arel::Table.new :users - (table[:id].count + 1).to_sql.must_be_like %{ - (COUNT("users"."id") + 1) - } - end - end end |