aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-10-31 00:38:24 -0400
committerGitHub <noreply@github.com>2017-10-31 00:38:24 -0400
commitb0ad8046091ce45a20fc7a5cb68b4599f876bbbb (patch)
treed18c95d125a2e6ed1b8ef5d8067022c09a7b3609
parent5cc7e774bb4d2190236cdbf46d66c89507ac6933 (diff)
parent1aeefa68bc93fddfba1d6549bb870d3829dfe0e2 (diff)
downloadrails-b0ad8046091ce45a20fc7a5cb68b4599f876bbbb.tar.gz
rails-b0ad8046091ce45a20fc7a5cb68b4599f876bbbb.tar.bz2
rails-b0ad8046091ce45a20fc7a5cb68b4599f876bbbb.zip
Merge pull request #502 from kddeisz/count-math
Allow count nodes to have math functions
-rw-r--r--lib/arel/nodes/count.rb2
-rw-r--r--test/nodes/test_count.rb9
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/arel/nodes/count.rb b/lib/arel/nodes/count.rb
index a7c6236a22..4dd9be453f 100644
--- a/lib/arel/nodes/count.rb
+++ b/lib/arel/nodes/count.rb
@@ -2,6 +2,8 @@
module Arel
module Nodes
class Count < Arel::Nodes::Function
+ include Math
+
def initialize expr, distinct = false, aliaz = nil
super(expr, aliaz)
@distinct = distinct
diff --git a/test/nodes/test_count.rb b/test/nodes/test_count.rb
index 85e93b1927..29883df681 100644
--- a/test/nodes/test_count.rb
+++ b/test/nodes/test_count.rb
@@ -31,4 +31,13 @@ describe Arel::Nodes::Count do
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