diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2012-05-02 11:45:48 -0700 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2012-05-02 11:45:48 -0700 |
commit | ae8f4974d1acea4c46e21f6ba29d90dbb43b0979 (patch) | |
tree | 38be1da4eeae6f02b8c75adf9c7fbcf16ec8b8ac | |
parent | 6a4541d63e65b1de99bc20c9d260ac13c02fa581 (diff) | |
parent | 6d6907e40d2ff5b08560ee24fc192a72acfa0347 (diff) | |
download | rails-ae8f4974d1acea4c46e21f6ba29d90dbb43b0979.tar.gz rails-ae8f4974d1acea4c46e21f6ba29d90dbb43b0979.tar.bz2 rails-ae8f4974d1acea4c46e21f6ba29d90dbb43b0979.zip |
Merge pull request #3707 from ebeigarts/refactor_remove_column
Refactored remove_column
4 files changed, 4 insertions, 6 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 3546873550..f0b6ae2b7d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -408,7 +408,7 @@ module ActiveRecord # t.remove(:qualification) # t.remove(:qualification, :experience) def remove(*column_names) - @base.remove_column(@table_name, column_names) + @base.remove_column(@table_name, *column_names) end # Removes the given index from the table. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 30a4f9aa35..e7a4f061fd 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -618,8 +618,6 @@ module ActiveRecord end def columns_for_remove(table_name, *column_names) - column_names = column_names.flatten - raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.blank? column_names.map {|column_name| quote_column_name(column_name) } end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 83f75e3505..44e407a561 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -446,7 +446,7 @@ module ActiveRecord 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| + column_names.each do |column_name| alter_table(table_name) do |definition| definition.columns.delete(definition[column_name]) end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e71b84a3a5..f788690b0d 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -588,14 +588,14 @@ class ChangeTableMigrationsTest < ActiveRecord::TestCase def test_remove_drops_single_column with_change_table do |t| - @connection.expects(:remove_column).with(:delete_me, [:bar]) + @connection.expects(:remove_column).with(:delete_me, :bar) t.remove :bar end end def test_remove_drops_multiple_columns with_change_table do |t| - @connection.expects(:remove_column).with(:delete_me, [:bar, :baz]) + @connection.expects(:remove_column).with(:delete_me, :bar, :baz) t.remove :bar, :baz end end |