Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6878 from masarakki/master

fix bug in limit of enum columns of mysql

Closes #6432
  • Loading branch information...
commit 48601c27b7942a18482bc817321a1ce9effece20 1 parent 10e5685
Rafael Mendonça França rafaelfranca authored
2  activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
View
@@ -72,6 +72,8 @@ 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
10 activerecord/test/cases/adapters/mysql/enum_test.rb
View
@@ -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
View
@@ -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
9 activerecord/test/schema/mysql2_specific_schema.rb
View
@@ -32,4 +32,13 @@
) 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
10 activerecord/test/schema/mysql_specific_schema.rb
View
@@ -43,4 +43,14 @@
) 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
Please sign in to comment.
Something went wrong with that request. Please try again.