Repository: rails/rails
File: railties/test/application/configuration_test.rb (Ruby)

Code before:

      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", location: "/foo" }
          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
    end

    test "renders actionable exception page when Action Text is not installed" do
      add_to_config <<~RUBY
        config.active_record.migration_error    = :page_load
        config.consider_all_requests_local      = true
        config.action_dispatch.show_exceptions  = :all
      RUBY

      app_file "config/routes.rb", <<~RUBY
        Rails.application.routes.draw do
          post "/blobs" => "blobs#create"
          post "/rich_texts" => "rich_texts#create"
        end
      RUBY

      app_file "app/controllers/blobs_controller.rb", <<~RUBY
        class BlobsController < ActionController::Base
          def create
            ActiveStorage::Blob.create!
          end
        end
      RUBY

      app_file "app/controllers/rich_texts_controller.rb", <<~RUBY
        class RichTextsController < ActionController::Base
          def create
            ActionText::RichText.create!

Review comment (refactor):
This file is already getting really huge, maybe we should move this test to `railties/test/application/action_text/whatever`, like we started to do for Active Storage:
https://github.com/rails/rails/blob/main/railties/test/application/active_storage/uploads_integration_test.rb

Code after:

      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", location: "/foo" }
          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
    end

    test "renders an exception on pending migration for multiple DBs" do
      add_to_config <<-RUBY
        config.active_record.migration_error    = :page_load
        config.consider_all_requests_local      = true
        config.action_dispatch.show_exceptions  = :all
      RUBY

      app_file "config/database.yml", <<-YAML
        <%= Rails.env %>:
          primary:
            adapter: sqlite3
            database: 'dev_db'
          other:
            adapter: sqlite3
            database: 'other_dev_db'
            migrations_paths: db/other_migrate
      YAML

      app_file "db/migrate/20140708012246_create_users.rb", <<-RUBY
        class CreateUsers < ActiveRecord::Migration::Current
          def change
            create_table :users
          end
        end
      RUBY