Skip to content

Commit 18a1c75

Browse files
committed
Remove meaningless ActiveRecord::MigrationContext.new(old_path) in ensure block
`ActiveRecord::MigrationContext.new` just create an instance, doesn't have any side-effect.
1 parent 7931951 commit 18a1c75

File tree

2 files changed

+0
-16
lines changed

2 files changed

+0
-16
lines changed

activerecord/test/cases/migration_test.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def test_migration_version_matches_component_version
8787

8888
def test_migrator_versions
8989
migrations_path = MIGRATIONS_ROOT + "/valid"
90-
old_path = ActiveRecord::Migrator.migrations_paths
9190
migrator = ActiveRecord::MigrationContext.new(migrations_path)
9291

9392
migrator.up
@@ -100,33 +99,25 @@ def test_migrator_versions
10099

101100
ActiveRecord::SchemaMigration.create!(version: 3)
102101
assert_equal true, migrator.needs_migration?
103-
ensure
104-
ActiveRecord::MigrationContext.new(old_path)
105102
end
106103

107104
def test_migration_detection_without_schema_migration_table
108105
ActiveRecord::Base.connection.drop_table "schema_migrations", if_exists: true
109106

110107
migrations_path = MIGRATIONS_ROOT + "/valid"
111-
old_path = ActiveRecord::Migrator.migrations_paths
112108
migrator = ActiveRecord::MigrationContext.new(migrations_path)
113109

114110
assert_equal true, migrator.needs_migration?
115-
ensure
116-
ActiveRecord::MigrationContext.new(old_path)
117111
end
118112

119113
def test_any_migrations
120-
old_path = ActiveRecord::Migrator.migrations_paths
121114
migrator = ActiveRecord::MigrationContext.new(MIGRATIONS_ROOT + "/valid")
122115

123116
assert_predicate migrator, :any_migrations?
124117

125118
migrator_empty = ActiveRecord::MigrationContext.new(MIGRATIONS_ROOT + "/empty")
126119

127120
assert_not_predicate migrator_empty, :any_migrations?
128-
ensure
129-
ActiveRecord::MigrationContext.new(old_path)
130121
end
131122

132123
def test_migration_version
@@ -393,7 +384,6 @@ def test_internal_metadata_table_name
393384
def test_internal_metadata_stores_environment
394385
current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
395386
migrations_path = MIGRATIONS_ROOT + "/valid"
396-
old_path = ActiveRecord::Migrator.migrations_paths
397387
migrator = ActiveRecord::MigrationContext.new(migrations_path)
398388

399389
migrator.up
@@ -410,7 +400,6 @@ def test_internal_metadata_stores_environment
410400
migrator.up
411401
assert_equal new_env, ActiveRecord::InternalMetadata[:environment]
412402
ensure
413-
migrator = ActiveRecord::MigrationContext.new(old_path)
414403
ENV["RAILS_ENV"] = original_rails_env
415404
ENV["RACK_ENV"] = original_rack_env
416405
migrator.up
@@ -422,16 +411,12 @@ def test_internal_metadata_stores_environment_when_other_data_exists
422411

423412
current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
424413
migrations_path = MIGRATIONS_ROOT + "/valid"
425-
old_path = ActiveRecord::Migrator.migrations_paths
426414

427415
current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
428416
migrator = ActiveRecord::MigrationContext.new(migrations_path)
429417
migrator.up
430418
assert_equal current_env, ActiveRecord::InternalMetadata[:environment]
431419
assert_equal "bar", ActiveRecord::InternalMetadata[:foo]
432-
ensure
433-
migrator = ActiveRecord::MigrationContext.new(old_path)
434-
migrator.up
435420
end
436421

437422
def test_proper_table_name_on_migration

activerecord/test/cases/migrator_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def test_finds_migrations
100100
def test_finds_migrations_in_subdirectories
101101
migrations = ActiveRecord::MigrationContext.new(MIGRATIONS_ROOT + "/valid_with_subdirectories").migrations
102102

103-
104103
[[1, "ValidPeopleHaveLastNames"], [2, "WeNeedReminders"], [3, "InnocentJointable"]].each_with_index do |pair, i|
105104
assert_equal migrations[i].version, pair.first
106105
assert_equal migrations[i].name, pair.last

0 commit comments

Comments
 (0)