diff options
author | phinze <paul.t.hinze@gmail.com> | 2013-05-14 13:27:51 -0500 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-15 17:50:55 -0700 |
commit | 09a16ef1786f89181b51d5fb2c37fab65fafa976 (patch) | |
tree | 2950dd10815f16cc66db93c37ccb4da0c3637869 /activerecord/test/cases | |
parent | 9db6e63bfbb1756a6f43620dfa7e099d89c46dd0 (diff) | |
download | rails-09a16ef1786f89181b51d5fb2c37fab65fafa976.tar.gz rails-09a16ef1786f89181b51d5fb2c37fab65fafa976.tar.bz2 rails-09a16ef1786f89181b51d5fb2c37fab65fafa976.zip |
add failing test exposing mysql adapter tinyint bug
in myself, a column with type TINYINT(N) where N > 1 can be used to
represent an integer, but the rails mysql adapter refuses to interpret
as anything but a boolean.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb index a75883cd3a..4a23287448 100644 --- a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb +++ b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb @@ -95,14 +95,27 @@ module ActiveRecord assert_equal @conn.default_sequence_name('ex_with_custom_index_type_pk', 'id'), seq end + def test_tinyint_integer_typecasting + @conn.exec_query('drop table if exists ex_with_non_boolean_tinyint_column') + @conn.exec_query(<<-eosql) + CREATE TABLE `ex_with_non_boolean_tinyint_column` ( + `status` TINYINT(4)) + eosql + insert(@conn, { 'status' => 2 }, 'ex_with_non_boolean_tinyint_column') + + result = @conn.exec_query('SELECT status FROM ex_with_non_boolean_tinyint_column') + + assert_equal 2, result.column_types['status'].type_cast(result.last['status']) + end + private - def insert(ctx, data) + def insert(ctx, data, table='ex') binds = data.map { |name, value| - [ctx.columns('ex').find { |x| x.name == name }, value] + [ctx.columns(table).find { |x| x.name == name }, value] } columns = binds.map(&:first).map(&:name) - sql = "INSERT INTO ex (#{columns.join(", ")}) + sql = "INSERT INTO #{table} (#{columns.join(", ")}) VALUES (#{(['?'] * columns.length).join(', ')})" ctx.exec_insert(sql, 'SQL', binds) |