Skip to content

Commit

Permalink
Make execute, change_column and remove_columns methods actually irrev…
Browse files Browse the repository at this point in the history
…ersible

[rails#8267]
  • Loading branch information
marcandre committed Dec 21, 2012
1 parent e43e8e2 commit 06c7ba8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/migration/command_recorder.rb
Expand Up @@ -73,7 +73,8 @@ def respond_to?(*args) # :nodoc:
[:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
:change_column, :change_column_default, :add_reference, :remove_reference, :transaction,
:drop_join_table, :drop_table, :remove_columns, :remove_index,
:drop_join_table, :drop_table, :remove_index,
:change_column, :execute, :remove_columns, # irreversible methods need to be here too
].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
Expand Down
8 changes: 7 additions & 1 deletion activerecord/test/cases/migration/command_recorder_test.rb
Expand Up @@ -34,12 +34,18 @@ def test_unknown_commands_delegate
assert_equal 'bar', recorder.foo
end

def test_unknown_commands_raise_exception_if_they_cannot_delegate
def test_inverse_of_raise_exception_on_unknown_commands
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse_of :execute, ['some sql']
end
end

def test_irreversible_commands_raise_exception
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.revert{ @recorder.execute 'some sql' }
end
end

def test_record
@recorder.record :create_table, [:system_settings]
assert_equal 1, @recorder.commands.length
Expand Down

0 comments on commit 06c7ba8

Please sign in to comment.