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

Code before:
        end

        assert_equal 302, last_response.status

        get "/foo"
        assert_equal 404, last_response.status
      ensure
        ActiveRecord::Migrator.migrations_paths = nil
      end
    end

    test "Rails.groups returns available groups" do
      require "rails"

      Rails.env = "development"
      assert_equal [:default, "development"], Rails.groups
      assert_equal [:default, "development", :assets], Rails.groups(assets: [:development])
      assert_equal [:default, "development", :another, :assets], Rails.groups(:another, assets: %w(development))

      Rails.env = "test"
      assert_equal [:default, "test"], Rails.groups(assets: [:development])

      ENV["RAILS_GROUPS"] = "javascripts,stylesheets"
      assert_equal [:default, "test", "javascripts", "stylesheets"], Rails.groups
    ensure
      ENV.delete "RAILS_GROUPS"
    end

    test "Rails.application is nil until app is initialized" do
      require "rails"
      assert_nil Rails.application
      app "development"
      assert_equal AppTemplate::Application.instance, Rails.application
    end

    test "Rails.application responds to all instance methods" do
      app "development"
      assert_equal Rails.application.routes_reloader, AppTemplate::Application.routes_reloader
      assert_kind_of ActiveSupport::MessageVerifiers, Rails.application.message_verifiers
      assert_kind_of ActiveSupport::Deprecation::Deprecators, Rails.application.deprecators
    end

    test "Rails::Application responds to paths" do
      app "development"
      assert_equal ["#{app_path}/app/views"], AppTemplate::Application.paths["app/views"].expanded
    end

    test "the application root is set correctly" do
      app "development"
      assert_equal Pathname.new(app_path), Rails.application.root
    end

Review comment (refactor):
We shouldn't `ENV.delete` but restore to whatever it was. We got a helper for that (`set_env` I think?) that is copy pasted in a bunch of places. Would be good to clean that up.

Code after:
      require "rails"

      Rails.env = "development"
      assert_equal [:default, "development"], Rails.groups
      assert_equal [:default, "development", :assets], Rails.groups(assets: [:development])
      assert_equal [:default, "development", :another, :assets], Rails.groups(:another, assets: %w(development))

      Rails.env = "test"
      assert_equal [:default, "test"], Rails.groups(assets: [:development])

      with_env RAILS_GROUPS: "javascripts,stylesheets" do
        assert_equal [:default, "test", "javascripts", "stylesheets"], Rails.groups
      end
    end

    test "Rails.application is nil until app is initialized" do
      require "rails"
      assert_nil Rails.application
      app "development"
      assert_equal AppTemplate::Application.instance, Rails.application
    end

    test "Rails.application responds to all instance methods" do
      app "development"
      assert_equal Rails.application.routes_reloader, AppTemplate::Application.routes_reloader
      assert_kind_of ActiveSupport::MessageVerifiers, Rails.application.message_verifiers
      assert_kind_of ActiveSupport::Deprecation::Deprecators, Rails.application.deprecators
    end

    test "Rails::Application responds to paths" do
      app "development"
      assert_equal ["#{app_path}/app/views"], AppTemplate::Application.paths["app/views"].expanded
    end

    test "the application root is set correctly" do
      app "development"
      assert_equal Pathname.new(app_path), Rails.application.root
    end

    test "the application root can be seen from the application singleton" do
      app "development"
      assert_equal Pathname.new(app_path), AppTemplate::Application.root
    end

    test "the application root can be set" do
      copy_app
      add_to_config <<-RUBY
        config.root = '#{new_app}'
      RUBY

      use_frameworks []