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

@ -5,4 +5,9 @@
*Yves Senn* *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.

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

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

@ -779,7 +779,7 @@ def add_timestamps_sql(table_name, options = {})
[add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)] [add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
end 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)] [remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
end end

@ -107,7 +107,7 @@ def test_remove_timestamps
ActiveRecord::Base.connection.create_table :delete_me do |t| ActiveRecord::Base.connection.create_table :delete_me do |t|
t.timestamps null: true t.timestamps null: true
end 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', 'updated_at', 'datetime')
assert !column_present?('delete_me', 'created_at', 'datetime') assert !column_present?('delete_me', 'created_at', 'datetime')
ensure ensure

@ -107,7 +107,7 @@ def test_remove_timestamps
ActiveRecord::Base.connection.create_table :delete_me do |t| ActiveRecord::Base.connection.create_table :delete_me do |t|
t.timestamps null: true t.timestamps null: true
end 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', 'updated_at', 'datetime')
assert !column_present?('delete_me', 'created_at', 'datetime') assert !column_present?('delete_me', 'created_at', 'datetime')
ensure ensure

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

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