aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb2
-rw-r--r--activerecord/test/cases/migration/command_recorder_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index 231e981e53..73450c2390 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -20,7 +20,7 @@ module ActiveRecord
# Returns a list that represents commands that are the inverse of the
# commands stored in +commands+.
def inverse
- @commands.map { |name, args| send(:"invert_#{name}", args) }
+ @commands.reverse.map { |name, args| send(:"invert_#{name}", args) }
end
private
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb
index c33ce7cadf..47c3332078 100644
--- a/activerecord/test/cases/migration/command_recorder_test.rb
+++ b/activerecord/test/cases/migration/command_recorder_test.rb
@@ -20,6 +20,13 @@ module ActiveRecord
assert_equal 2, @recorder.inverse.length
end
+ def test_inverted_commands_are_reveresed
+ @recorder.record :create_table, [:hello]
+ @recorder.record :create_table, [:world]
+ tables = @recorder.inverse.map(&:last)
+ assert_equal [[:world], [:hello]], tables
+ end
+
def test_invert_create_table
@recorder.record :create_table, [:system_settings]
drop_table = @recorder.inverse.first