mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #6349 from erichmenge/patch-raise-type-errors
Integer limit out of range should be allowed to raise. Closes #6272
This commit is contained in:
commit
4025efb53b
4 changed files with 34 additions and 7 deletions
|
@ -23,7 +23,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def sql_type
|
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
|
end
|
||||||
|
|
||||||
def to_sql
|
def to_sql
|
||||||
|
|
|
@ -83,7 +83,6 @@ module ActiveRecord
|
||||||
t.column :one_int, :integer, :limit => 1
|
t.column :one_int, :integer, :limit => 1
|
||||||
t.column :four_int, :integer, :limit => 4
|
t.column :four_int, :integer, :limit => 4
|
||||||
t.column :eight_int, :integer, :limit => 8
|
t.column :eight_int, :integer, :limit => 8
|
||||||
t.column :eleven_int, :integer, :limit => 11
|
|
||||||
end
|
end
|
||||||
|
|
||||||
columns = connection.columns(:testings)
|
columns = connection.columns(:testings)
|
||||||
|
@ -94,20 +93,17 @@ module ActiveRecord
|
||||||
one = columns.detect { |c| c.name == "one_int" }
|
one = columns.detect { |c| c.name == "one_int" }
|
||||||
four = columns.detect { |c| c.name == "four_int" }
|
four = columns.detect { |c| c.name == "four_int" }
|
||||||
eight = columns.detect { |c| c.name == "eight_int" }
|
eight = columns.detect { |c| c.name == "eight_int" }
|
||||||
eleven = columns.detect { |c| c.name == "eleven_int" }
|
|
||||||
|
|
||||||
if current_adapter?(:PostgreSQLAdapter)
|
if current_adapter?(:PostgreSQLAdapter)
|
||||||
assert_equal 'integer', default.sql_type
|
assert_equal 'integer', default.sql_type
|
||||||
assert_equal 'smallint', one.sql_type
|
assert_equal 'smallint', one.sql_type
|
||||||
assert_equal 'integer', four.sql_type
|
assert_equal 'integer', four.sql_type
|
||||||
assert_equal 'bigint', eight.sql_type
|
assert_equal 'bigint', eight.sql_type
|
||||||
assert_equal 'integer', eleven.sql_type
|
|
||||||
elsif current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
elsif current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
||||||
assert_match 'int(11)', default.sql_type
|
assert_match 'int(11)', default.sql_type
|
||||||
assert_match 'tinyint', one.sql_type
|
assert_match 'tinyint', one.sql_type
|
||||||
assert_match 'int', four.sql_type
|
assert_match 'int', four.sql_type
|
||||||
assert_match 'bigint', eight.sql_type
|
assert_match 'bigint', eight.sql_type
|
||||||
assert_match 'int(11)', eleven.sql_type
|
|
||||||
elsif current_adapter?(:OracleAdapter)
|
elsif current_adapter?(:OracleAdapter)
|
||||||
assert_equal 'NUMBER(38)', default.sql_type
|
assert_equal 'NUMBER(38)', default.sql_type
|
||||||
assert_equal 'NUMBER(1)', one.sql_type
|
assert_equal 'NUMBER(1)', one.sql_type
|
||||||
|
|
|
@ -183,6 +183,16 @@ module ActiveRecord
|
||||||
assert_instance_of TrueClass, bob.male?
|
assert_instance_of TrueClass, bob.male?
|
||||||
assert_kind_of BigDecimal, bob.wealth
|
assert_kind_of BigDecimal, bob.wealth
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -375,6 +375,27 @@ class MigrationTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
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
|
protected
|
||||||
def with_env_tz(new_tz = 'US/Eastern')
|
def with_env_tz(new_tz = 'US/Eastern')
|
||||||
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
||||||
|
@ -883,8 +904,8 @@ class CopyMigrationsTest < ActiveRecord::TestCase
|
||||||
def test_skipping_migrations
|
def test_skipping_migrations
|
||||||
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
||||||
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
||||||
|
|
||||||
sources = {}
|
sources = {}
|
||||||
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
||||||
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
|
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue