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

fix: limit of enum columns of mysql

This commit is contained in:
Yamada Masaki 2012-06-27 19:10:36 +09:00 committed by masarakki
parent 2076efed1c
commit f49800071f
5 changed files with 41 additions and 0 deletions

View file

@ -72,6 +72,8 @@ module ActiveRecord
when /^mediumint/i; 3 when /^mediumint/i; 3
when /^smallint/i; 2 when /^smallint/i; 2
when /^tinyint/i; 1 when /^tinyint/i; 1
when /^enum\((.+)\)/i
$1.split(',').map{|enum| enum.strip.length - 2}.max
else else
super super
end end

View file

@ -0,0 +1,10 @@
require "cases/helper"
class MysqlEnumTest < ActiveRecord::TestCase
class EnumTest < ActiveRecord::Base
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
end
end

View file

@ -0,0 +1,10 @@
require "cases/helper"
class Mysql2EnumTest < ActiveRecord::TestCase
class EnumTest < ActiveRecord::Base
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
end
end

View file

@ -32,4 +32,13 @@ CREATE TABLE collation_tests (
) CHARACTER SET utf8 COLLATE utf8_general_ci ) CHARACTER SET utf8 COLLATE utf8_general_ci
SQL SQL
ActiveRecord::Base.connection.execute <<-SQL
DROP TABLE IF EXISTS enum_tests;
SQL
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
enum_column ENUM('true','false')
)
SQL
end end

View file

@ -41,6 +41,16 @@ CREATE TABLE collation_tests (
string_cs_column VARCHAR(1) COLLATE utf8_bin, string_cs_column VARCHAR(1) COLLATE utf8_bin,
string_ci_column VARCHAR(1) COLLATE utf8_general_ci string_ci_column VARCHAR(1) COLLATE utf8_general_ci
) CHARACTER SET utf8 COLLATE utf8_general_ci ) CHARACTER SET utf8 COLLATE utf8_general_ci
SQL
ActiveRecord::Base.connection.execute <<-SQL
DROP TABLE IF EXISTS enum_tests;
SQL
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
enum_column ENUM('true','false')
)
SQL SQL
end end