diff options
author | Hiroyuki Morita <chiastolite.1980@gmail.com> | 2019-01-16 23:11:16 +0900 |
---|---|---|
committer | Hiroyuki Morita <chiastolite.1980@gmail.com> | 2019-02-10 04:01:59 +0900 |
commit | 0914ea8477aab6620983cee9b51be4c2c574705f (patch) | |
tree | 0102db2d1b4d8be4ed31ca8843238dbfab07c125 | |
parent | c7721ea6b3a2319820decccce1a26eb9ebf3b290 (diff) | |
download | rails-0914ea8477aab6620983cee9b51be4c2c574705f.tar.gz rails-0914ea8477aab6620983cee9b51be4c2c574705f.tar.bz2 rails-0914ea8477aab6620983cee9b51be4c2c574705f.zip |
Do not allow to add column without column name
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/migration/columns_test.rb | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index dfb4953cbd..897b50a158 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -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 diff --git a/activerecord/test/cases/migration/columns_test.rb b/activerecord/test/cases/migration/columns_test.rb index cedd9c44e3..e5dfdf1655 100644 --- a/activerecord/test/cases/migration/columns_test.rb +++ b/activerecord/test/cases/migration/columns_test.rb @@ -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 |