Skip to content
Browse files

fix detect column type of enum

enum includes text or blob or ... hooked by wrong regex
  • Loading branch information...
1 parent 0a16cf1 commit eab657b267ae898e8cad36385574f91ef838610e @masarakki masarakki committed Apr 1, 2013
View
4 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -82,6 +82,8 @@ def simplified_type(field_type)
def extract_limit(sql_type)
case sql_type
+ when /^enum\((.+)\)/i
+ $1.split(',').map{|enum| enum.strip.length - 2}.max
when /blob|text/i
case sql_type
when /tiny/i
@@ -98,8 +100,6 @@ def extract_limit(sql_type)
when /^mediumint/i; 3
when /^smallint/i; 2
when /^tinyint/i; 1
- when /^enum\((.+)\)/i
- $1.split(',').map{|enum| enum.strip.length - 2}.max
else
super
end
View
2 activerecord/test/cases/adapters/mysql/enum_test.rb
@@ -5,6 +5,6 @@ class EnumTest < ActiveRecord::Base
end
def test_enum_limit
- assert_equal 5, EnumTest.columns.first.limit
+ assert_equal 6, EnumTest.columns.first.limit
end
end
View
2 activerecord/test/cases/adapters/mysql2/enum_test.rb
@@ -5,6 +5,6 @@ class EnumTest < ActiveRecord::Base
end
def test_enum_limit
- assert_equal 5, EnumTest.columns.first.limit
+ assert_equal 6, EnumTest.columns.first.limit
end
end
View
2 activerecord/test/schema/mysql2_specific_schema.rb
@@ -52,7 +52,7 @@
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
- enum_column ENUM('true','false')
+ enum_column ENUM('text','blob','tiny','medium','long')
)
SQL
end
View
2 activerecord/test/schema/mysql_specific_schema.rb
@@ -63,7 +63,7 @@
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
- enum_column ENUM('true','false')
+ enum_column ENUM('text','blob','tiny','medium','long')
)
SQL

0 comments on commit eab657b

Please sign in to comment.
Something went wrong with that request. Please try again.