Skip to content

Commit d7824b2

Browse files
committed
Fix error in ActiveRecord::Migration.check_pending!
Since rails@e9d835f this method has not worked, it has failed with this error: ``` NoMethodError: undefined method `pending_migrations' for #<ActiveRecord::MigrationContext:0x00005598468f8e58> Did you mean? pending_migration_versions ``` I agree with Eileen that eventually we could deprecate it, but to get it working I just reversed the changes in rails@e9d835f and added a regression test.
1 parent a9506eb commit d7824b2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

activerecord/lib/active_record/migration.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,7 @@ def nearest_delegate # :nodoc:
644644

645645
# Raises <tt>ActiveRecord::PendingMigrationError</tt> error if any migrations are pending.
646646
def check_pending!(connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection)
647-
if pending_migrations = connection.migration_context.pending_migrations
648-
raise ActiveRecord::PendingMigrationError.new(pending_migrations: pending_migrations)
649-
end
647+
raise ActiveRecord::PendingMigrationError if connection.migration_context.needs_migration?
650648
end
651649

652650
def load_schema_if_pending!

activerecord/test/cases/migration/pending_migrations_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def test_with_stdlib_logger
8989
private
9090
def assert_pending_migrations(*expected_migrations)
9191
2.times do
92+
assert_raises ActiveRecord::PendingMigrationError do
93+
ActiveRecord::Migration.check_pending!
94+
end
95+
9296
error = assert_raises ActiveRecord::PendingMigrationError do
9397
CheckPending.new(proc { flunk }).call({})
9498
end
@@ -105,6 +109,10 @@ def assert_no_pending_migrations
105109
check_pending = CheckPending.new(app)
106110

107111
2.times do
112+
assert_nothing_raised do
113+
ActiveRecord::Migration.check_pending!
114+
end
115+
108116
app.expect :call, nil, [{}]
109117
check_pending.call({})
110118
app.verify

0 commit comments

Comments
 (0)