mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
remove_column should raise an ArgumentError when no columns are passed [#4803 state:resolved]
Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
parent
995b1a243c
commit
e639536ea8
3 changed files with 6 additions and 0 deletions
|
@ -205,6 +205,7 @@ module ActiveRecord
|
|||
# remove_column(:suppliers, :qualification)
|
||||
# remove_columns(:suppliers, :qualification, :experience)
|
||||
def remove_column(table_name, *column_names)
|
||||
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
|
||||
column_names.flatten.each do |column_name|
|
||||
execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{quote_column_name(column_name)}"
|
||||
end
|
||||
|
|
|
@ -246,6 +246,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def remove_column(table_name, *column_names) #:nodoc:
|
||||
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
|
||||
column_names.flatten.each do |column_name|
|
||||
alter_table(table_name) do |definition|
|
||||
definition.columns.delete(definition[column_name])
|
||||
|
|
|
@ -748,6 +748,10 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|||
ActiveRecord::Base.connection.drop_table(:hats)
|
||||
end
|
||||
|
||||
def test_remove_column_no_second_parameter_raises_exception
|
||||
assert_raise(ArgumentError) { Person.connection.remove_column("funny") }
|
||||
end
|
||||
|
||||
def test_change_type_of_not_null_column
|
||||
assert_nothing_raised do
|
||||
Topic.connection.change_column "topics", "written_on", :datetime, :null => false
|
||||
|
|
Loading…
Reference in a new issue