1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix detect column type of enum

enum includes text or blob or ... hooked by wrong regex
This commit is contained in:
masarakki 2013-04-01 16:48:26 +09:00
parent 0a16cf19c2
commit eab657b267
5 changed files with 6 additions and 6 deletions

View file

@ -82,6 +82,8 @@ module ActiveRecord
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 @@ module ActiveRecord
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 file

@ -5,6 +5,6 @@ class MysqlEnumTest < ActiveRecord::TestCase
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
assert_equal 6, EnumTest.columns.first.limit
end
end

View file

@ -5,6 +5,6 @@ class Mysql2EnumTest < ActiveRecord::TestCase
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
assert_equal 6, EnumTest.columns.first.limit
end
end

View file

@ -52,7 +52,7 @@ SQL
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 file

@ -63,7 +63,7 @@ SQL
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
enum_column ENUM('true','false')
enum_column ENUM('text','blob','tiny','medium','long')
)
SQL