aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2015-08-25 12:19:20 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2015-08-25 12:19:20 -0300
commit61ebc20cdfeb68cd7e6d2e698a5b20f8449131e6 (patch)
tree584bd07d262f4c1cb76d5a435c104e63d0f6f71b /activerecord/test
parent57105d99bccadc7d48af199b73ac2d891a15f9da (diff)
parentc90008a86ee486334531d5096c04da5100ced692 (diff)
downloadrails-61ebc20cdfeb68cd7e6d2e698a5b20f8449131e6.tar.gz
rails-61ebc20cdfeb68cd7e6d2e698a5b20f8449131e6.tar.bz2
rails-61ebc20cdfeb68cd7e6d2e698a5b20f8449131e6.zip
Merge pull request #21372 from yui-knk/fix/revert_change_column_default
Make `change_column_default` to work
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/invertible_migration_test.rb33
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)