mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make execute, change_column and remove_columns methods actually irreversible
[#8267]
This commit is contained in:
parent
e43e8e268f
commit
06c7ba881d
2 changed files with 9 additions and 2 deletions
|
@ -73,7 +73,8 @@ module ActiveRecord
|
||||||
[:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
[:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
||||||
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
||||||
:change_column, :change_column_default, :add_reference, :remove_reference, :transaction,
|
: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|
|
].each do |method|
|
||||||
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
||||||
def #{method}(*args, &block) # def create_table(*args, &block)
|
def #{method}(*args, &block) # def create_table(*args, &block)
|
||||||
|
|
|
@ -34,12 +34,18 @@ module ActiveRecord
|
||||||
assert_equal 'bar', recorder.foo
|
assert_equal 'bar', recorder.foo
|
||||||
end
|
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
|
assert_raises(ActiveRecord::IrreversibleMigration) do
|
||||||
@recorder.inverse_of :execute, ['some sql']
|
@recorder.inverse_of :execute, ['some sql']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_irreversible_commands_raise_exception
|
||||||
|
assert_raises(ActiveRecord::IrreversibleMigration) do
|
||||||
|
@recorder.revert{ @recorder.execute 'some sql' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_record
|
def test_record
|
||||||
@recorder.record :create_table, [:system_settings]
|
@recorder.record :create_table, [:system_settings]
|
||||||
assert_equal 1, @recorder.commands.length
|
assert_equal 1, @recorder.commands.length
|
||||||
|
|
Loading…
Reference in a new issue