diff options
author | Richard Schneeman <richard.schneeman@gmail.com> | 2016-01-14 13:07:35 -0600 |
---|---|---|
committer | Richard Schneeman <richard.schneeman@gmail.com> | 2016-01-14 13:07:35 -0600 |
commit | 5854de38859fd770702c41747576d5c86c82d4b9 (patch) | |
tree | cad216e046cd718f57c54da91bab5d1e56b90025 /activerecord/test | |
parent | a461dbd637791d3bd399007f234a1ca5c919e199 (diff) | |
parent | 4d60e93174a3d6d90b1a06fc7515cb5cd749a6f3 (diff) | |
download | rails-5854de38859fd770702c41747576d5c86c82d4b9.tar.gz rails-5854de38859fd770702c41747576d5c86c82d4b9.tar.bz2 rails-5854de38859fd770702c41747576d5c86c82d4b9.zip |
Merge pull request #23017 from schneems/schneems/migration-sets-environment-value
Set environment even when no migration runs
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index cfa223f93e..fe74ca127f 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -301,7 +301,7 @@ class MigrationTest < ActiveRecord::TestCase e = assert_raise(StandardError) { migrator.run } - assert_equal "An error has occurred, this migration was canceled:\n\nSomething broke", e.message + assert_equal "An error has occurred, this and all later migrations canceled:\n\nSomething broke", e.message assert_no_column Person, :last_name, "On error, the Migrator should revert schema changes but it did not." @@ -398,6 +398,33 @@ class MigrationTest < ActiveRecord::TestCase ENV["RACK_ENV"] = original_rack_env end + + def test_migration_sets_internal_metadata_even_when_fully_migrated + current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + migrations_path = MIGRATIONS_ROOT + "/valid" + old_path = ActiveRecord::Migrator.migrations_paths + ActiveRecord::Migrator.migrations_paths = migrations_path + + ActiveRecord::Migrator.up(migrations_path) + assert_equal current_env, ActiveRecord::InternalMetadata[:environment] + + original_rails_env = ENV["RAILS_ENV"] + original_rack_env = ENV["RACK_ENV"] + ENV["RAILS_ENV"] = ENV["RACK_ENV"] = "foofoo" + new_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + + refute_equal current_env, new_env + + sleep 1 # mysql by default does not store fractional seconds in the database + + ActiveRecord::Migrator.up(migrations_path) + assert_equal new_env, ActiveRecord::InternalMetadata[:environment] + ensure + ActiveRecord::Migrator.migrations_paths = old_path + ENV["RAILS_ENV"] = original_rails_env + ENV["RACK_ENV"] = original_rack_env + end + def test_proper_table_name_on_migration reminder_class = new_isolated_reminder_class migration = ActiveRecord::Migration.new |