Skip to content

Commit cb2934e

Browse files
committed
sqlite3 adapter returns integer value which used to be string
`to_i` was added for SQLite3 adapter which did not handle number but sqlite3 gem already supports it then `to_i` is unnecessary. else condition is kept for adapters which return string, i.e. mysql(not mysql2) and sqlserver. Renamed `test_cache_does_not_wrap_string_results_in_arrays` to `test_cache_does_not_wrap_results_in_arrays` to explain the current behavior. most of adapters return integer, not only string. * Refer these commits: "future proofing the sqlite3 adapter code" rails@beda2d4 "Refactor calculation test to remove unneeded SQLite special case." rails@47d568e "no need to to_i, sqlite does that for us" rails@6cf44a1
1 parent 806f96c commit cb2934e

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

activerecord/test/cases/calculations_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ def test_count_with_block
518518
end
519519

520520
def test_should_sum_expression
521-
# Oracle adapter returns floating point value 636.0 after SUM
522-
if current_adapter?(:OracleAdapter)
521+
if current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter, :OracleAdapter)
523522
assert_equal 636, Account.sum("2 * credit_limit")
524523
else
525524
assert_equal 636, Account.sum("2 * credit_limit").to_i

activerecord/test/cases/query_cache_test.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,10 @@ def test_cache_is_flat
302302
end
303303
end
304304

305-
def test_cache_does_not_wrap_string_results_in_arrays
305+
def test_cache_does_not_wrap_results_in_arrays
306306
Task.cache do
307-
# Oracle adapter returns count() as Integer or Float
308-
if current_adapter?(:OracleAdapter)
309-
assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
310-
elsif current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter)
311-
# Future versions of the sqlite3 adapter will return numeric
312-
assert_instance_of 0.class, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
307+
if current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter, :OracleAdapter)
308+
assert_equal 2, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
313309
else
314310
assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
315311
end

0 commit comments

Comments
 (0)