aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration/command_recorder_test.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2015-05-04 16:11:15 -0400
committerPrem Sichanugrist <s@sikac.hu>2015-06-26 16:25:13 -0400
commita4128725f5a2c6cbf3e963e2b78ba9382732728a (patch)
tree6702300b290791a2dfea1377bf8db6338db3c35b /activerecord/test/cases/migration/command_recorder_test.rb
parent0bee4100f10dec672b70ad63856149c85d8cbc95 (diff)
downloadrails-a4128725f5a2c6cbf3e963e2b78ba9382732728a.tar.gz
rails-a4128725f5a2c6cbf3e963e2b78ba9382732728a.tar.bz2
rails-a4128725f5a2c6cbf3e963e2b78ba9382732728a.zip
Add reversible syntax for change_column_default
Passing `:from` and `:to` to `change_column_default` makes this command reversible as user has defined its previous state. So, instead of having the migration command as: change_column_default(:posts, :state, "draft") They can write it as: change_column_default(:posts, :state, from: nil, to: "draft")
Diffstat (limited to 'activerecord/test/cases/migration/command_recorder_test.rb')
-rw-r--r--activerecord/test/cases/migration/command_recorder_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb
index 90b7c6b38a..99f1dc65b0 100644
--- a/activerecord/test/cases/migration/command_recorder_test.rb
+++ b/activerecord/test/cases/migration/command_recorder_test.rb
@@ -169,6 +169,16 @@ module ActiveRecord
end
end
+ def test_invert_change_column_default_with_from_and_to
+ change = @recorder.inverse_of :change_column_default, [:table, :column, from: "old_value", to: "new_value"]
+ assert_equal [:change_column_default, [:table, :column, from: "new_value", to: "old_value"]], change
+ end
+
+ def test_invert_change_column_default_with_from_and_to_with_boolean
+ change = @recorder.inverse_of :change_column_default, [:table, :column, from: true, to: false]
+ assert_equal [:change_column_default, [:table, :column, from: false, to: true]], change
+ end
+
def test_invert_change_column_null
add = @recorder.inverse_of :change_column_null, [:table, :column, true]
assert_equal [:change_column_null, [:table, :column, false]], add