Skip to content

Fix README: .env.local in test should not outrank .env.test.local - #552

Open
hikmetba-bit wants to merge 1 commit into
bkeepers:mainfrom
hikmetba-bit:docs/fix-test-env-local-precedence
Open

hikmetba-bit wants to merge 1 commit into
bkeepers:mainfrom
hikmetba-bit:docs/fix-test-env-local-precedence

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Fixes #543.

The Customizing Rails section's example used Dotenv::Rails.files.unshift(".env.local"), which puts .env.local at index 0 — the highest precedence, ahead of .env.test.local.

Per the precedence table earlier in the same README, .env.local is meant to sit at the 2nd precedence tier in every environment (between the .env.<env>.local and .env.<env> tiers) — the same position it already has by default in development and production (it's just excluded by default in test, per lib/dotenv/rails.rb's (".env.local" unless env.test?)). The test-only snippet that re-adds it should insert it at that same position, not shove it in front of everything.

Verified the replacement snippet actually produces the right order:

files = [".env.test.local", ".env.test", ".env"]
index = files.index(".env.test.local")&.succ || files.index(".env.test") || 0
files.insert(index, ".env.local")
p files
# => [".env.test.local", ".env.local", ".env.test", ".env"]

Docs-only change (README example code), matching the fix the issue reporter already worked out and verified.

🤖 Generated with Claude Code

The Customizing Rails section's example used Dotenv::Rails.files.unshift(
".env.local"), which puts .env.local at index 0 -- the highest
precedence, ahead of .env.test.local. Per the precedence table earlier
in the same README, .env.local is meant to sit at the '2nd' precedence
tier in every environment (between the .env.<env>.local and
.env.<env> tiers), the same position it already has by default in
development and production. The test-only snippet re-adding it should
insert it there too, not at the very front.

Fixes bkeepers#543.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in Customizing Rails section of README

1 participant