Skip to content

Error in Customizing Rails section of README #543

Description

@jbigler

The customization suggested to include .env.local in the test environment uses unshift, but this will put env.local at the highest precedence.

# config/application.rb
Bundler.require(*Rails.groups)

# Load .env.local in test
Dotenv::Rails.files.unshift(".env.local") if ENV["RAILS_ENV"] == "test"

module YourApp
  class Application < Rails::Application
    # ...
  end
end

Instead, it should be inserted between .env.test.local and .env.test

Suggestion:

# Load .env.local in test
if ENV["RAILS_ENV"] == "test"
  files = Dotenv::Rails.files
  index = files.index(".env.test.local")&.succ || files.index(".env.test") || 0
  files.insert(index, ".env.local")
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions