diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-08-07 17:59:27 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-11-11 16:15:00 +0100 |
commit | 07ae1e9b5557182f69e5ffbac54b334284abf36f (patch) | |
tree | d160eab55a7f40da7101d5ff1a52eecd744f0b36 /activerecord | |
parent | 07790d5832e1822ce7278f05db1fe8394b5eb780 (diff) | |
download | rails-07ae1e9b5557182f69e5ffbac54b334284abf36f.tar.gz rails-07ae1e9b5557182f69e5ffbac54b334284abf36f.tar.bz2 rails-07ae1e9b5557182f69e5ffbac54b334284abf36f.zip |
Unifies mysql and mysql2 casting of booleans.
Diffstat (limited to 'activerecord')
4 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 1e387769de..54c243951d 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`. + `type_cast` will return `1` for `true` and `0` for `false`. + + Fixes #11119. + + *Adam Williams*, *Yves Senn* + * Fix bug where has_one associaton record update result in crash, when replaced with itself. Fixes #12834. diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 138ab811dc..ee6ca4fb6f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -206,6 +206,12 @@ module ActiveRecord true end + def type_cast(value, column) + return super unless value == true || value == false + + value ? 1 : 0 + end + # MySQL 4 technically support transaction isolation, but it is affected by a bug # where the transaction level gets persisted for the whole session: # diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index a690404892..7b18b95c44 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -160,12 +160,6 @@ module ActiveRecord # QUOTING ================================================== - def type_cast(value, column) - return super unless value == true || value == false - - value ? 1 : 0 - end - def quote_string(string) #:nodoc: @connection.quote(string) end diff --git a/activerecord/test/cases/adapters/mysql2/boolean_test.rb b/activerecord/test/cases/adapters/mysql2/boolean_test.rb index 7d23ba28d2..267aa232d9 100644 --- a/activerecord/test/cases/adapters/mysql2/boolean_test.rb +++ b/activerecord/test/cases/adapters/mysql2/boolean_test.rb @@ -46,8 +46,8 @@ class Mysql2BooleanTest < ActiveRecord::TestCase assert_equal 1, attributes["archived"] assert_equal "1", attributes["published"] - assert_equal "t", @connection.type_cast(true, boolean_column) - assert_equal "t", @connection.type_cast(true, string_column) + assert_equal 1, @connection.type_cast(true, boolean_column) + assert_equal 1, @connection.type_cast(true, string_column) end test "test type casting without emulated booleans" do @@ -60,7 +60,7 @@ class Mysql2BooleanTest < ActiveRecord::TestCase assert_equal "1", attributes["published"] assert_equal 1, @connection.type_cast(true, boolean_column) - assert_equal "t", @connection.type_cast(true, string_column) + assert_equal 1, @connection.type_cast(true, string_column) end test "with booleans stored as 1 and 0" do |