mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #40001 from tgxworld/actionable_migration_not_dumping_schema
Fix ActiveRecord::PendingMigrationError action not dumping schema.
This commit is contained in:
commit
211564c638
3 changed files with 21 additions and 21 deletions
|
@ -135,6 +135,12 @@ module ActiveRecord
|
|||
|
||||
action "Run pending migrations" do
|
||||
ActiveRecord::Tasks::DatabaseTasks.migrate
|
||||
|
||||
if ActiveRecord::Base.dump_schema_after_migration
|
||||
ActiveRecord::Tasks::DatabaseTasks.dump_schema(
|
||||
ActiveRecord::Base.connection_db_config
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(message = nil)
|
||||
|
|
|
@ -905,25 +905,6 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase
|
||||
def test_can_migrate_from_pending_migration_error_action_dispatch
|
||||
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
||||
ENV["VERSION"] = "2"
|
||||
ENV["VERBOSE"] = "false"
|
||||
|
||||
# run down migration because it was already run on copied db
|
||||
assert_empty capture_migration_output
|
||||
|
||||
ENV.delete("VERSION")
|
||||
ENV.delete("VERBOSE")
|
||||
|
||||
# re-run up migration
|
||||
assert_includes(capture(:stdout) do
|
||||
ActiveSupport::ActionableError.dispatch ActiveRecord::PendingMigrationError, "Run pending migrations"
|
||||
end, "migrating")
|
||||
ensure
|
||||
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
||||
end
|
||||
|
||||
def test_migrate_set_and_unset_empty_values_for_verbose_and_version_env_vars
|
||||
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
||||
|
||||
|
|
|
@ -153,12 +153,25 @@ module ApplicationTests
|
|||
|
||||
app "development"
|
||||
|
||||
ActiveRecord::Migrator.migrations_paths = ["#{app_path}/db/migrate"]
|
||||
|
||||
begin
|
||||
ActiveRecord::Migrator.migrations_paths = ["#{app_path}/db/migrate"]
|
||||
|
||||
get "/foo"
|
||||
assert_equal 500, last_response.status
|
||||
assert_match "ActiveRecord::PendingMigrationError", last_response.body
|
||||
|
||||
assert_changes -> { File.exist?(File.join(app_path, "db", "schema.rb")) }, from: false, to: true do
|
||||
output = capture(:stdout) do
|
||||
post "/rails/actions", { error: "ActiveRecord::PendingMigrationError", action: "Run pending migrations" }
|
||||
end
|
||||
|
||||
assert_match(/\d{14}\s+CreateUser/, output)
|
||||
end
|
||||
|
||||
assert_equal 302, last_response.status
|
||||
|
||||
get "/foo"
|
||||
assert_equal 404, last_response.status
|
||||
ensure
|
||||
ActiveRecord::Migrator.migrations_paths = nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue