mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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"beda2d43d6
"Refactor calculation test to remove unneeded SQLite special case."47d568ed3f
"no need to to_i, sqlite does that for us"6cf44a1bd6
This commit is contained in:
parent
806f96ceae
commit
cb2934ed79
2 changed files with 4 additions and 9 deletions
|
@ -518,8 +518,7 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_should_sum_expression
|
||||
# Oracle adapter returns floating point value 636.0 after SUM
|
||||
if current_adapter?(:OracleAdapter)
|
||||
if current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter, :OracleAdapter)
|
||||
assert_equal 636, Account.sum("2 * credit_limit")
|
||||
else
|
||||
assert_equal 636, Account.sum("2 * credit_limit").to_i
|
||||
|
|
|
@ -302,14 +302,10 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_cache_does_not_wrap_string_results_in_arrays
|
||||
def test_cache_does_not_wrap_results_in_arrays
|
||||
Task.cache do
|
||||
# Oracle adapter returns count() as Integer or Float
|
||||
if current_adapter?(:OracleAdapter)
|
||||
assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
|
||||
elsif current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter)
|
||||
# Future versions of the sqlite3 adapter will return numeric
|
||||
assert_instance_of 0.class, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
|
||||
if current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :PostgreSQLAdapter, :OracleAdapter)
|
||||
assert_equal 2, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
|
||||
else
|
||||
assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue