Fix default options argument on ActiveRecord::ConnectionAdaptors::Table#column_exists?

Changed the default value for the `options` argument on `ActiveRecord::ConnectionAdapters::Table#column_exists?` from `nil` to an empty Hash `{}`.

That method calls through to `ActiveRecord::ConnectionAdapters::SchemaStatements#column_exists?` which expects `options` to be a Hash.

When `options` was `nil`, an error would occur in cases where the column did exist because the called method attempted to perform a key lookup on options.
This commit is contained in:
Grant Neufeld
2011-06-20 11:45:20 -06:00
parent f542188e7a
commit 88aa2efd69
2 changed files with 13 additions and 1 deletions

View File

@@ -328,7 +328,7 @@ module ActiveRecord
end
# Checks to see if a column exists. See SchemaStatements#column_exists?
def column_exists?(column_name, type = nil, options = nil)
def column_exists?(column_name, type = nil, options = {})
@base.column_exists?(@table_name, column_name, type, options)
end

View File

@@ -1071,6 +1071,18 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.drop_table :testings rescue nil
end
def test_column_exists_on_table_with_no_options_parameter_supplied
Person.connection.create_table :testings do |t|
t.string :foo
end
Person.connection.change_table :testings do |t|
assert t.column_exists?(:foo)
assert !(t.column_exists?(:bar))
end
ensure
Person.connection.drop_table :testings rescue nil
end
def test_add_table
assert !Reminder.table_exists?