aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-01-03 05:41:53 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-01-04 14:46:59 +0900
commit2f373dd916cfab568d489e2103ba71284bc3e695 (patch)
tree0bbb0ab9f62b7a2927395e5d8e04caa080eb95a2 /activerecord
parent3d590add45b7ff1de972d99b076cb504d5208935 (diff)
downloadrails-2f373dd916cfab568d489e2103ba71284bc3e695.tar.gz
rails-2f373dd916cfab568d489e2103ba71284bc3e695.tar.bz2
rails-2f373dd916cfab568d489e2103ba71284bc3e695.zip
Fix `unsigned?` and `blob_or_text_column?` for Enum columns in MySQL
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb6
-rw-r--r--activerecord/test/cases/adapters/mysql2/enum_test.rb13
-rw-r--r--activerecord/test/schema/mysql2_specific_schema.rb2
3 files changed, 16 insertions, 5 deletions
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