Skip to content
Browse files

remove_column should raise an ArgumentError when no columns are passed [

#4803 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent e703fc1 commit da93d69bcb8c507a16503f883f67597338b5edeb @zilkey zilkey committed with NZKoz Jun 9, 2010
View
1 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -195,6 +195,7 @@ def add_column(table_name, column_name, type, options = {})
# 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
View
1 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -269,6 +269,7 @@ def add_column(table_name, column_name, type, options = {}) #:nodoc:
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])
View
4 activerecord/test/cases/migration_test.rb
@@ -739,6 +739,10 @@ def test_remove_column_with_multi_column_index
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

0 comments on commit da93d69

Please sign in to comment.
Something went wrong with that request. Please try again.