diff options
author | Rich <rich@fishpercolator.co.uk> | 2017-11-14 19:24:00 +0000 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2017-11-14 14:24:00 -0500 |
commit | df82237a45e930a7ab53b95bee78a3f34c5b92fb (patch) | |
tree | 824f42d4e01f5f1864ba3c0150753df9cdd88730 /activerecord/test/cases | |
parent | 53574ff988ce7927ae3cfeb8d7ed21734680c26c (diff) | |
download | rails-df82237a45e930a7ab53b95bee78a3f34c5b92fb.tar.gz rails-df82237a45e930a7ab53b95bee78a3f34c5b92fb.tar.bz2 rails-df82237a45e930a7ab53b95bee78a3f34c5b92fb.zip |
Add a #populate method to migrations (#31082)
* Add a #populate method to migrations
* Address rubocop issues
* Rename to #up_only and use #execute in the examples intead of the model
* Update CHANGELOG
[Rich Daley & Rafael Mendonça França]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/invertible_migration_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index 60c628511f..e0f40710eb 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -161,6 +161,13 @@ module ActiveRecord end end + class UpOnlyMigration < SilentMigration + def change + add_column :horses, :oldie, :boolean, default: false + up_only { execute "update horses set oldie = 'true'" } + end + end + setup do @verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, false end @@ -378,5 +385,23 @@ module ActiveRecord "horses_index_named index should not exist" end end + + def test_up_only + InvertibleMigration.new.migrate(:up) + horse1 = Horse.create + # populates existing horses with oldie=true but new ones have default false + UpOnlyMigration.new.migrate(:up) + Horse.reset_column_information + horse1.reload + horse2 = Horse.create + + assert horse1.oldie? # created before migration + assert !horse2.oldie? # created after migration + + UpOnlyMigration.new.migrate(:down) # should be no error + connection = ActiveRecord::Base.connection + assert !connection.column_exists?(:horses, :oldie) + Horse.reset_column_information + end end end |