Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AquaGeek/971749 to your computer and use it in GitHub Desktop.
Save AquaGeek/971749 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6158
From 49cf79257e799e05f0687f7b00fc3ccbe9b40eae Mon Sep 17 00:00:00 2001
From: Jarrett Meyer <jarrettmeyer@gmail.com>
Date: Fri, 18 Feb 2011 09:54:17 -0500
Subject: [PATCH] Added unit test for count
---
activerecord/test/cases/calculations_test.rb | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 3121f16..ffc0a56 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -318,6 +318,11 @@ class CalculationsTest < ActiveRecord::TestCase
assert_raise(ArgumentError) { Account.count(1, 2, 3) }
end
+ def test_count_returns_integer_on_decimal_column
+ NumericData.create(:bank_balance => 19.83)
+ assert NumericData.count(:bank_balance).is_a? Integer
+ end
+
def test_should_sum_expression
# Oracle adapter returns floating point value 636.0 after SUM
if current_adapter?(:OracleAdapter)
--
1.7.1
From 09fa01b2106a5646dac860f59c54d7cf81f2a12c Mon Sep 17 00:00:00 2001
From: Jarrett Meyer <jarrettmeyer@gmail.com>
Date: Mon, 13 Dec 2010 15:45:53 -0500
Subject: [PATCH 1/2] Added failing unit test
---
activerecord/test/cases/calculations_test.rb | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 5cb8485..f0f8246 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -302,6 +302,11 @@ class CalculationsTest < ActiveRecord::TestCase
def test_count_with_no_parameters_isnt_deprecated
assert_not_deprecated { Account.count }
end
+
+ def test_count_decimal_column_returns_integer
+ NumericData.create(:bank_balance => 19.83)
+ assert NumericData.count(:bank_balance).is_a?(Integer)
+ end
def test_count_with_too_many_parameters_raises
assert_raise(ArgumentError) { Account.count(1, 2, 3) }
--
1.7.0.4
From 120471d8a239278e7b13e9ba775b85c5a6febe6f Mon Sep 17 00:00:00 2001
From: Jarrett Meyer <jarrettmeyer@gmail.com>
Date: Mon, 13 Dec 2010 15:52:09 -0500
Subject: [PATCH 2/2] Added line to force count result to return an integer [#6158 state:resolved]
---
.../lib/active_record/relation/calculations.rb | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index fd45bb2..5be0b9c 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -290,7 +290,10 @@ module ActiveRecord
else type_cast_using_column(value, column)
end
else
- type_cast_using_column(value, column)
+ case operation
+ when 'count' then value.to_i
+ else type_cast_using_column(value, column)
+ end
end
end
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment