Skip to content
This repository
Browse code

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 authored June 27, 2012
2  activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -72,6 +72,8 @@ def extract_limit(sql_type)
72 72
           when /^mediumint/i; 3
73 73
           when /^smallint/i;  2
74 74
           when /^tinyint/i;   1
  75
+          when /^enum\((.+)\)/i
  76
+            $1.split(',').map{|enum| enum.strip.length - 2}.max
75 77
           else
76 78
             super
77 79
           end
10  activerecord/test/cases/adapters/mysql/enum_test.rb
... ...
@@ -0,0 +1,10 @@
  1
+require "cases/helper"
  2
+
  3
+class MysqlEnumTest < ActiveRecord::TestCase
  4
+  class EnumTest < ActiveRecord::Base
  5
+  end
  6
+
  7
+  def test_enum_limit
  8
+    assert_equal 5, EnumTest.columns.first.limit
  9
+  end
  10
+end
10  activerecord/test/cases/adapters/mysql2/enum_test.rb
... ...
@@ -0,0 +1,10 @@
  1
+require "cases/helper"
  2
+
  3
+class Mysql2EnumTest < ActiveRecord::TestCase
  4
+  class EnumTest < ActiveRecord::Base
  5
+  end
  6
+
  7
+  def test_enum_limit
  8
+    assert_equal 5, EnumTest.columns.first.limit
  9
+  end
  10
+end
9  activerecord/test/schema/mysql2_specific_schema.rb
@@ -32,4 +32,13 @@
32 32
 ) CHARACTER SET utf8 COLLATE utf8_general_ci
33 33
 SQL
34 34
 
  35
+  ActiveRecord::Base.connection.execute <<-SQL
  36
+DROP TABLE IF EXISTS enum_tests;
  37
+SQL
  38
+
  39
+  ActiveRecord::Base.connection.execute <<-SQL
  40
+CREATE TABLE enum_tests (
  41
+  enum_column ENUM('true','false')
  42
+)
  43
+SQL
35 44
 end
10  activerecord/test/schema/mysql_specific_schema.rb
@@ -43,4 +43,14 @@
43 43
 ) CHARACTER SET utf8 COLLATE utf8_general_ci
44 44
 SQL
45 45
 
  46
+  ActiveRecord::Base.connection.execute <<-SQL
  47
+DROP TABLE IF EXISTS enum_tests;
  48
+SQL
  49
+
  50
+  ActiveRecord::Base.connection.execute <<-SQL
  51
+CREATE TABLE enum_tests (
  52
+  enum_column ENUM('true','false')
  53
+)
  54
+SQL
  55
+
46 56
 end

0 notes on commit 48601c2

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