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

Merge pull request #22896 from kamipo/fix_unsigned_and_blob_or_text_column

Fix `unsigned?` and `blob_or_text_column` for Enum columns in MySQL
This commit is contained in:
Rafael França 2016-01-04 21:14:50 -02:00
commit 35dd9e9f2a
3 changed files with 16 additions and 5 deletions

View file

@ -40,11 +40,11 @@ module ActiveRecord
end
def blob_or_text_column?
sql_type =~ /blob/i || type == :text
/\A(?:tiny|medium|long)?blob\b/ === sql_type || type == :text
end
def unsigned?
/unsigned/ === sql_type
/\bunsigned\z/ === sql_type
end
def case_sensitive?
@ -835,7 +835,7 @@ module ActiveRecord
def register_integer_type(mapping, key, options) # :nodoc:
mapping.register_type(key) do |sql_type|
if /unsigned/i =~ sql_type
if /\bunsigned\z/ === sql_type
Type::UnsignedInteger.new(options)
else
Type::Integer.new(options)

View file

@ -5,6 +5,17 @@ class Mysql2EnumTest < ActiveRecord::Mysql2TestCase
end
def test_enum_limit
assert_equal 6, EnumTest.columns.first.limit
column = EnumTest.columns_hash['enum_column']
assert_equal 8, column.limit
end
def test_should_not_be_blob_or_text_column
column = EnumTest.columns_hash['enum_column']
assert_not column.blob_or_text_column?
end
def test_should_not_be_unsigned
column = EnumTest.columns_hash['enum_column']
assert_not column.unsigned?
end
end

View file

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