diff options
author | yui-knk <spiketeika@gmail.com> | 2015-08-25 22:40:15 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-08-25 22:40:15 +0900 |
commit | c90008a86ee486334531d5096c04da5100ced692 (patch) | |
tree | 6d9d8742663a10ed73d38798d7d657bfa1a6eb2c /activerecord/test/cases | |
parent | 211c31d2718165e68d4676d70eb1315c6b767dcc (diff) | |
download | rails-c90008a86ee486334531d5096c04da5100ced692.tar.gz rails-c90008a86ee486334531d5096c04da5100ced692.tar.bz2 rails-c90008a86ee486334531d5096c04da5100ced692.zip |
Make `change_column_default` to work
This is fix of #20018 which removes `change_column_default` from
array, so `CommandRecorder#method_missing` catches
`change_column_default` and @delegate's method is called.
This PR
* fix this bug
* define `ReversibleAndIrreversibleMethods` const making clear
which this array means to prevent these miss
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/invertible_migration_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index 99230aa3d5..3bc4fa379f 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -1,5 +1,8 @@ require "cases/helper" +class Horse < ActiveRecord::Base +end + module ActiveRecord class InvertibleMigrationTest < ActiveRecord::TestCase class SilentMigration < ActiveRecord::Migration @@ -76,6 +79,20 @@ module ActiveRecord end end + class ChangeColumnDefault1 < SilentMigration + def change + create_table("horses") do |t| + t.column :name, :string, default: "Sekitoba" + end + end + end + + class ChangeColumnDefault2 < SilentMigration + def change + change_column_default :horses, :name, from: "Sekitoba", to: "Diomed" + end + end + class LegacyMigration < ActiveRecord::Migration def self.up create_table("horses") do |t| @@ -223,6 +240,22 @@ module ActiveRecord assert !revert.connection.table_exists?("horses") end + def test_migrate_revert_change_column_default + index_definition = ["horses", [:name, :color]] + migration1 = ChangeColumnDefault1.new + migration1.migrate(:up) + assert_equal "Sekitoba", Horse.new.name + + migration2 = ChangeColumnDefault2.new + migration2.migrate(:up) + Horse.reset_column_information + assert_equal "Diomed", Horse.new.name + + migration2.migrate(:down) + Horse.reset_column_information + assert_equal "Sekitoba", Horse.new.name + end + def test_revert_order block = Proc.new{|t| t.string :name } recorder = ActiveRecord::Migration::CommandRecorder.new(ActiveRecord::Base.connection) |