Skip to content

Commit

Permalink
Stop showing deprecations for Ruby 1.8.7 with remove_column
Browse files Browse the repository at this point in the history
String is Enumerable in 1.8.7, which means that passing a String to
remove_column was generating deprecation warnings during tests.
  • Loading branch information
carlosantoniodasilva committed May 9, 2012
1 parent cb242a9 commit fa34ace
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -269,13 +269,15 @@ def add_column(table_name, column_name, type, options = {})
# remove_column(:suppliers, :qualification) # remove_column(:suppliers, :qualification)
# remove_columns(:suppliers, :qualification, :experience) # remove_columns(:suppliers, :qualification, :experience)
def remove_column(table_name, *column_names) def remove_column(table_name, *column_names)
if column_names.first.kind_of?(Enumerable) if column_names.flatten!
message = 'Passing array to remove_columns is deprecated, please use ' + message = 'Passing array to remove_columns is deprecated, please use ' +
'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`' 'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`'
ActiveSupport::Deprecation.warn message, caller ActiveSupport::Deprecation.warn message, caller
end end


columns_for_remove(table_name, *column_names).each {|column_name| execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}" } columns_for_remove(table_name, *column_names).each do |column_name|
execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}"
end
end end
alias :remove_columns :remove_column alias :remove_columns :remove_column


Expand Down
Expand Up @@ -408,13 +408,13 @@ def add_column(table_name, column_name, type, options = {}) #:nodoc:
def remove_column(table_name, *column_names) #:nodoc: 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? raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?


if column_names.first.kind_of?(Enumerable) if column_names.flatten!
message = 'Passing array to remove_columns is deprecated, please use ' + message = 'Passing array to remove_columns is deprecated, please use ' +
'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`' 'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`'
ActiveSupport::Deprecation.warn message, caller ActiveSupport::Deprecation.warn message, caller
end end


column_names.flatten.each do |column_name| column_names.each do |column_name|
alter_table(table_name) do |definition| alter_table(table_name) do |definition|
definition.columns.delete(definition[column_name]) definition.columns.delete(definition[column_name])
end end
Expand Down

0 comments on commit fa34ace

Please sign in to comment.