mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make ActiveRecord::PendingMigrationError actionable
This commit is contained in:
parent
45f1c7a3e1
commit
255a2422a3
2 changed files with 10 additions and 2 deletions
|
@ -129,6 +129,12 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class PendingMigrationError < MigrationError #:nodoc:
|
||||
include ActiveSupport::ActionableError
|
||||
|
||||
action "Run pending migrations" do
|
||||
ActiveRecord::Tasks::DatabaseTasks.migrate
|
||||
end
|
||||
|
||||
def initialize(message = nil)
|
||||
if !message && defined?(Rails.env)
|
||||
super("Migrations are pending. To resolve this issue, run:\n\n rails db:migrate RAILS_ENV=#{::Rails.env}")
|
||||
|
|
|
@ -760,7 +760,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase
|
||||
def test_migrate_set_and_unset_verbose_and_version_env_vars
|
||||
def test_can_migrate_from_pending_migration_error_action_dispatch
|
||||
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
||||
ENV["VERSION"] = "2"
|
||||
ENV["VERBOSE"] = "false"
|
||||
|
@ -772,7 +772,9 @@ module ActiveRecord
|
|||
ENV.delete("VERBOSE")
|
||||
|
||||
# re-run up migration
|
||||
assert_includes capture_migration_output, "migrating"
|
||||
assert_includes(capture(:stdout) do
|
||||
ActiveSupport::ActionableError.dispatch ActiveRecord::PendingMigrationError, "Run pending migrations"
|
||||
end, "migrating")
|
||||
ensure
|
||||
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue