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:
parent
2076efed1c
commit
f49800071f
5 changed files with 41 additions and 0 deletions
|
@ -72,6 +72,8 @@ 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
|
||||
|
|
10
activerecord/test/cases/adapters/mysql/enum_test.rb
Normal file
10
activerecord/test/cases/adapters/mysql/enum_test.rb
Normal 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
|
10
activerecord/test/cases/adapters/mysql2/enum_test.rb
Normal file
10
activerecord/test/cases/adapters/mysql2/enum_test.rb
Normal 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
|
|
@ -32,4 +32,13 @@ CREATE TABLE collation_tests (
|
|||
) 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
|
||||
end
|
||||
|
|
|
@ -41,6 +41,16 @@ CREATE TABLE collation_tests (
|
|||
string_cs_column VARCHAR(1) COLLATE utf8_bin,
|
||||
string_ci_column VARCHAR(1) 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
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue