From 2f373dd916cfab568d489e2103ba71284bc3e695 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 3 Jan 2016 05:41:53 +0900 Subject: Fix `unsigned?` and `blob_or_text_column?` for Enum columns in MySQL --- .../connection_adapters/abstract_mysql_adapter.rb | 6 +++--- activerecord/test/cases/adapters/mysql2/enum_test.rb | 13 ++++++++++++- activerecord/test/schema/mysql2_specific_schema.rb | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'activerecord') 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 f5b5482efb..b55995bc8d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -40,11 +40,11 @@ module ActiveRecord end def blob_or_text_column? - sql_type =~ /blob/i || type == :text + /\A(?:tiny|medium|long)?blob\b/ === sql_type || type == :text end def unsigned? - /unsigned/ === sql_type + /\bunsigned\z/ === sql_type end def case_sensitive? @@ -835,7 +835,7 @@ module ActiveRecord def register_integer_type(mapping, key, options) # :nodoc: mapping.register_type(key) do |sql_type| - if /unsigned/i =~ sql_type + if /\bunsigned\z/ === sql_type Type::UnsignedInteger.new(options) else Type::Integer.new(options) diff --git a/activerecord/test/cases/adapters/mysql2/enum_test.rb b/activerecord/test/cases/adapters/mysql2/enum_test.rb index bd732b5eca..bb89e893e0 100644 --- a/activerecord/test/cases/adapters/mysql2/enum_test.rb +++ b/activerecord/test/cases/adapters/mysql2/enum_test.rb @@ -5,6 +5,17 @@ class Mysql2EnumTest < ActiveRecord::Mysql2TestCase end def test_enum_limit - assert_equal 6, EnumTest.columns.first.limit + column = EnumTest.columns_hash['enum_column'] + assert_equal 8, column.limit + end + + def test_should_not_be_blob_or_text_column + column = EnumTest.columns_hash['enum_column'] + assert_not column.blob_or_text_column? + end + + def test_should_not_be_unsigned + column = EnumTest.columns_hash['enum_column'] + assert_not column.unsigned? end end diff --git a/activerecord/test/schema/mysql2_specific_schema.rb b/activerecord/test/schema/mysql2_specific_schema.rb index 92e0b197a7..9e1fe32c2d 100644 --- a/activerecord/test/schema/mysql2_specific_schema.rb +++ b/activerecord/test/schema/mysql2_specific_schema.rb @@ -55,7 +55,7 @@ SQL ActiveRecord::Base.connection.execute <<-SQL CREATE TABLE enum_tests ( - enum_column ENUM('text','blob','tiny','medium','long') + enum_column ENUM('text','blob','tiny','medium','long','unsigned') ) SQL end -- cgit v1.2.3