mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Integer limit out of range should be allowed to raise. Closes #6272
This commit is contained in:
parent
7994496ab4
commit
56cef492c6
4 changed files with 34 additions and 7 deletions
|
@ -23,7 +23,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def sql_type
|
||||
base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
|
||||
base.type_to_sql(type.to_sym, limit, precision, scale)
|
||||
end
|
||||
|
||||
def to_sql
|
||||
|
|
|
@ -83,7 +83,6 @@ module ActiveRecord
|
|||
t.column :one_int, :integer, :limit => 1
|
||||
t.column :four_int, :integer, :limit => 4
|
||||
t.column :eight_int, :integer, :limit => 8
|
||||
t.column :eleven_int, :integer, :limit => 11
|
||||
end
|
||||
|
||||
columns = connection.columns(:testings)
|
||||
|
@ -94,20 +93,17 @@ module ActiveRecord
|
|||
one = columns.detect { |c| c.name == "one_int" }
|
||||
four = columns.detect { |c| c.name == "four_int" }
|
||||
eight = columns.detect { |c| c.name == "eight_int" }
|
||||
eleven = columns.detect { |c| c.name == "eleven_int" }
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
assert_equal 'integer', default.sql_type
|
||||
assert_equal 'smallint', one.sql_type
|
||||
assert_equal 'integer', four.sql_type
|
||||
assert_equal 'bigint', eight.sql_type
|
||||
assert_equal 'integer', eleven.sql_type
|
||||
elsif current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
||||
assert_match 'int(11)', default.sql_type
|
||||
assert_match 'tinyint', one.sql_type
|
||||
assert_match 'int', four.sql_type
|
||||
assert_match 'bigint', eight.sql_type
|
||||
assert_match 'int(11)', eleven.sql_type
|
||||
elsif current_adapter?(:OracleAdapter)
|
||||
assert_equal 'NUMBER(38)', default.sql_type
|
||||
assert_equal 'NUMBER(1)', one.sql_type
|
||||
|
|
|
@ -183,6 +183,16 @@ module ActiveRecord
|
|||
assert_instance_of TrueClass, bob.male?
|
||||
assert_kind_of BigDecimal, bob.wealth
|
||||
end
|
||||
|
||||
def test_out_of_range_limit_should_raise
|
||||
skip("MySQL and PostgreSQL only") unless current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
|
||||
|
||||
assert_raise(ActiveRecordError) { add_column :test_models, :integer_too_big, :integer, :limit => 10 }
|
||||
|
||||
unless current_adapter?(:PostgreSQLAdapter)
|
||||
assert_raise(ActiveRecordError) { add_column :test_models, :text_too_big, :integer, :limit => 0xfffffffff }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -375,6 +375,27 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_out_of_range_limit_should_raise
|
||||
skip("MySQL and PostgreSQL only") unless current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
|
||||
|
||||
Person.connection.drop_table :test_limits rescue nil
|
||||
assert_raise(ActiveRecord::ActiveRecordError, "integer limit didn't raise") do
|
||||
Person.connection.create_table :test_integer_limits, :force => true do |t|
|
||||
t.column :bigone, :integer, :limit => 10
|
||||
end
|
||||
end
|
||||
|
||||
unless current_adapter?(:PostgreSQLAdapter)
|
||||
assert_raise(ActiveRecord::ActiveRecordError, "text limit didn't raise") do
|
||||
Person.connection.create_table :test_text_limits, :force => true do |t|
|
||||
t.column :bigtext, :text, :limit => 0xfffffffff
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Person.connection.drop_table :test_limits rescue nil
|
||||
end
|
||||
|
||||
protected
|
||||
def with_env_tz(new_tz = 'US/Eastern')
|
||||
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
||||
|
@ -883,8 +904,8 @@ class CopyMigrationsTest < ActiveRecord::TestCase
|
|||
def test_skipping_migrations
|
||||
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
||||
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
||||
|
||||
sources = {}
|
||||
|
||||
sources = {}
|
||||
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
||||
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
|
||||
|
||||
|
|
Loading…
Reference in a new issue