Failure to rollback t.timestamps when within a change_table migration

When running the following migration:

    change_table(:table_name) { |t| t/timestamps }

The following error was produced:

    wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps'

This is due to `arguments` containing an empty hash as its second
argument.
This commit is contained in:
noam 2014-11-17 12:54:40 -05:00
parent 497544f0b3
commit b64fb3020b
8 changed files with 16 additions and 11 deletions

View File

@ -5,4 +5,9 @@
*Yves Senn*
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) for previous changes.
* `add_timestamps` and `remove_timestamps` now properly reversible with
options.
*Noam Gagliardi-Rabinovich*
Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.

View File

@ -509,8 +509,8 @@ module ActiveRecord
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table.
#
# t.remove_timestamps
def remove_timestamps
@base.remove_timestamps(name)
def remove_timestamps(options = {})
@base.remove_timestamps(name, options)
end
# Renames a column.

View File

@ -854,7 +854,7 @@ module ActiveRecord
#
# remove_timestamps(:suppliers)
#
def remove_timestamps(table_name)
def remove_timestamps(table_name, options = {})
remove_column table_name, :updated_at
remove_column table_name, :created_at
end

View File

@ -779,7 +779,7 @@ module ActiveRecord
[add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
end
def remove_timestamps_sql(table_name)
def remove_timestamps_sql(table_name, options = {})
[remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
end

View File

@ -107,7 +107,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase
ActiveRecord::Base.connection.create_table :delete_me do |t|
t.timestamps null: true
end
ActiveRecord::Base.connection.remove_timestamps :delete_me
ActiveRecord::Base.connection.remove_timestamps :delete_me, { null: true }
assert !column_present?('delete_me', 'updated_at', 'datetime')
assert !column_present?('delete_me', 'created_at', 'datetime')
ensure

View File

@ -107,7 +107,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase
ActiveRecord::Base.connection.create_table :delete_me do |t|
t.timestamps null: true
end
ActiveRecord::Base.connection.remove_timestamps :delete_me
ActiveRecord::Base.connection.remove_timestamps :delete_me, { null: true }
assert !column_present?('delete_me', 'updated_at', 'datetime')
assert !column_present?('delete_me', 'created_at', 'datetime')
ensure

View File

@ -95,8 +95,8 @@ module ActiveRecord
def test_remove_timestamps_creates_updated_at_and_created_at
with_change_table do |t|
@connection.expect :remove_timestamps, nil, [:delete_me]
t.remove_timestamps
@connection.expect :remove_timestamps, nil, [:delete_me, { null: true }]
t.remove_timestamps({ null: true })
end
end

View File

@ -237,8 +237,8 @@ module ActiveRecord
end
def test_invert_remove_timestamps
add = @recorder.inverse_of :remove_timestamps, [:table]
assert_equal [:add_timestamps, [:table], nil], add
add = @recorder.inverse_of :remove_timestamps, [:table, { null: true }]
assert_equal [:add_timestamps, [:table, {null: true }], nil], add
end
def test_invert_add_reference