diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-11-19 01:12:36 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-21 13:54:52 -0500 |
commit | af871a0623740f53a4dca5858b78efb35f0e32e0 (patch) | |
tree | e8a1f4983b6654a792bdcd93348ee2d3df84d850 /activerecord/test/cases/migration | |
parent | bd155d2ae31a1e4c19274cfef6049d66136fd0cd (diff) | |
download | rails-af871a0623740f53a4dca5858b78efb35f0e32e0.tar.gz rails-af871a0623740f53a4dca5858b78efb35f0e32e0.tar.bz2 rails-af871a0623740f53a4dca5858b78efb35f0e32e0.zip |
Make drop_table reversible [#8267]
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/command_recorder_test.rb | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb index af033f11d9..66be0df4cd 100644 --- a/activerecord/test/cases/migration/command_recorder_test.rb +++ b/activerecord/test/cases/migration/command_recorder_test.rb @@ -50,7 +50,7 @@ module ActiveRecord @recorder.record :create_table, [:hello] @recorder.record :create_table, [:world] end - tables = @recorder.commands.map(&:last) + tables = @recorder.commands.map{|_cmd, args, _block| args} assert_equal [[:world], [:hello]], tables end @@ -61,20 +61,20 @@ module ActiveRecord revert do create_table("bananas", &block) revert do - create_table("clementines") + create_table("clementines", &block) create_table("dates") end create_table("elderberries") end revert do - create_table("figs") + create_table("figs", &block) create_table("grapes") end end - assert_equal [[:create_table, ["apples"], block], [:drop_table, ["elderberries"]], - [:create_table, ["clementines"], nil], [:create_table, ["dates"], nil], - [:drop_table, ["bananas"]], [:drop_table, ["grapes"]], - [:drop_table, ["figs"]]], @recorder.commands + assert_equal [[:create_table, ["apples"], block], [:drop_table, ["elderberries"], nil], + [:create_table, ["clementines"], block], [:create_table, ["dates"], nil], + [:drop_table, ["bananas"], block], [:drop_table, ["grapes"], nil], + [:drop_table, ["figs"], block]], @recorder.commands end @@ -83,12 +83,25 @@ module ActiveRecord @recorder.record :create_table, [:system_settings] end drop_table = @recorder.commands.first - assert_equal [:drop_table, [:system_settings]], drop_table + assert_equal [:drop_table, [:system_settings], nil], drop_table end - def test_invert_create_table_with_options - drop_table = @recorder.inverse_of :create_table, [:people_reminders, id: false] - assert_equal [:drop_table, [:people_reminders]], drop_table + def test_invert_create_table_with_options_and_block + block = Proc.new{} + drop_table = @recorder.inverse_of :create_table, [:people_reminders, id: false], &block + assert_equal [:drop_table, [:people_reminders, id: false], block], drop_table + end + + def test_invert_drop_table + block = Proc.new{} + create_table = @recorder.inverse_of :drop_table, [:people_reminders, id: false], &block + assert_equal [:create_table, [:people_reminders, id: false], block], create_table + end + + def test_invert_drop_table_without_a_block_nor_option + assert_raises(ActiveRecord::IrreversibleMigration) do + @recorder.inverse_of :drop_table, [:people_reminders] + end end def test_invert_create_join_table |