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

Do not allow to add column without column name

This commit is contained in:
Hiroyuki Morita 2019-01-16 23:11:16 +09:00
parent c7721ea6b3
commit 0914ea8477
2 changed files with 10 additions and 0 deletions

View file

@ -229,6 +229,7 @@ module ActiveRecord
column_types.each do |column_type|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{column_type}(*names, **options)
raise ArgumentError, "missing column name(s) for #{column_type}" if names.empty?
names.each { |name| column(name, :#{column_type}, options) }
end
RUBY

View file

@ -318,6 +318,15 @@ module ActiveRecord
ensure
connection.drop_table(:my_table) rescue nil
end
def test_add_column_without_column_name
e = assert_raise ArgumentError do
connection.create_table "my_table", force: true do |t|
t.timestamp
end
end
assert e.message.include?("timestamp")
end
end
end
end