diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-18 15:12:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-19 10:24:15 -0800 |
commit | 96b50a039276b4391ddf07b0a74850ce7bad6863 (patch) | |
tree | a1bb5eff45e86cbbe78639883c885ccee1f9d147 /activerecord | |
parent | b29a24bb6f13b8af9c12b77ee0ddc1f84c79ab55 (diff) | |
download | rails-96b50a039276b4391ddf07b0a74850ce7bad6863.tar.gz rails-96b50a039276b4391ddf07b0a74850ce7bad6863.tar.bz2 rails-96b50a039276b4391ddf07b0a74850ce7bad6863.zip |
IrreversibleMigration is raised if we cannot invert the command
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration/command_recorder.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/migration/command_recorder_test.rb | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index 73450c2390..87ad603c04 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -20,7 +20,11 @@ module ActiveRecord # Returns a list that represents commands that are the inverse of the # commands stored in +commands+. def inverse - @commands.reverse.map { |name, args| send(:"invert_#{name}", args) } + @commands.reverse.map { |name, args| + method = :"invert_#{name}" + raise IrreversibleMigration unless respond_to?(method, true) + send(method, args) + } end private diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb index 47c3332078..50d75e0400 100644 --- a/activerecord/test/cases/migration/command_recorder_test.rb +++ b/activerecord/test/cases/migration/command_recorder_test.rb @@ -7,6 +7,13 @@ module ActiveRecord @recorder = CommandRecorder.new end + def test_unknown_commands_raise_exception + @recorder.record :execute, ['some sql'] + assert_raises(ActiveRecord::IrreversibleMigration) do + @recorder.inverse + end + end + def test_record @recorder.record :create_table, [:system_settings] assert_equal 1, @recorder.commands.length |