Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bkeepers/dotenv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0
Choose a base ref
...
head repository: bkeepers/dotenv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.1
Choose a head ref
  • 7 commits
  • 5 files changed
  • 1 contributor

Commits on Feb 13, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    f55afd8 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    86390d2 View commit details

Commits on Feb 14, 2024

  1. Merge pull request #483 from bkeepers/autorestore-cc

    Disable autorestore if using climate_control or ice_age
    bkeepers authored Feb 14, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    cb8cd58 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    229cfc3 View commit details
  3. Merge pull request #484 from bkeepers/rails-root

    Join files to Rails.root at load time
    bkeepers authored Feb 14, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    3a2500c View commit details
  4. Merge pull request #481 from bkeepers/check-optional-rails

    Manually check optional Rails dependency version
    bkeepers authored Feb 14, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    ac8ea76 View commit details
  5. Prepare for 3.0.1 release

    bkeepers committed Feb 14, 2024
    Copy the full SHA
    09caa4d View commit details
Showing with 52 additions and 8 deletions.
  1. +10 −0 Changelog.md
  2. +1 −1 README.md
  3. +17 −6 lib/dotenv/rails.rb
  4. +1 −1 lib/dotenv/version.rb
  5. +23 −0 spec/dotenv/rails_spec.rb
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

[Unreleased changes](https://github.com/bkeepers/dotenv/compare/v3.0.0...main)

## 3.0.1

**What's Changed**

* Disable autorestore if using climate_control or ice_age by @bkeepers in https://github.com/bkeepers/dotenv/pull/483
* Join files to Rails.root at load time by @bkeepers in https://github.com/bkeepers/dotenv/pull/484
* Manually check optional Rails dependency version by @bkeepers in https://github.com/bkeepers/dotenv/pull/481

**Full Changelog**: https://github.com/bkeepers/dotenv/compare/v3.0.0...v3.0.1

## 3.0.0

**Breaking Changes**
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ Dotenv.load('file1.env', 'file2.env')

Since 3.0, dotenv in a Rails app will automatically restore `ENV` after each test. This means you can modify `ENV` in your tests without fear of leaking state to other tests. It works with both `ActiveSupport::TestCase` and `Rspec`.

To disable this behavior, set `config.dotenv.autorestore = false` in `config/application.rb` or `config/environments/test.rb`.
To disable this behavior, set `config.dotenv.autorestore = false` in `config/application.rb` or `config/environments/test.rb`. It is disabled by default if your app uses [climate_control](https://github.com/thoughtbot/climate_control) or [ice_age](https://github.com/dpep/ice_age_rb).

To use this behavior outside of a Rails app, just `require "dotenv/autorestore"` in your test suite.

23 changes: 17 additions & 6 deletions lib/dotenv/rails.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Since rubygems doesn't support optional dependencies, we have to manually check
unless Gem::Requirement.new(">= 6.1").satisfied_by?(Gem::Version.new(Rails.version))
warn "dotenv 3.0 only supports Rails 6.1 or later. Use dotenv ~> 2.0."
return
end

require "dotenv"
require "dotenv/replay_logger"
require "dotenv/log_subscriber"
@@ -18,7 +24,7 @@
module Dotenv
# Rails integration for using Dotenv to load ENV variables from a file
class Rails < ::Rails::Railtie
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, :logger=, to: "config.dotenv"
delegate :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, :logger=, to: "config.dotenv"

def initialize
super()
@@ -27,15 +33,20 @@ def initialize
logger: Dotenv::ReplayLogger.new,
overwrite: false,
files: [
root.join(".env.#{env}.local"),
(root.join(".env.local") unless env.test?),
root.join(".env.#{env}"),
root.join(".env")
".env.#{env}.local",
(".env.local" unless env.test?),
".env.#{env}",
".env"
].compact,
autorestore: env.test?
autorestore: env.test? && !defined?(ClimateControl) && !defined?(IceAge)
)
end

# The list of files to load, joined with Rails.root
def files
config.dotenv.files.map { |file| root.join(file) }
end

# Public: Load dotenv
#
# This will get called during the `before_configuration` callback, but you
2 changes: 1 addition & 1 deletion lib/dotenv/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Dotenv
VERSION = "3.0.0".freeze
VERSION = "3.0.1".freeze
end
23 changes: 23 additions & 0 deletions spec/dotenv/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -65,6 +65,17 @@
]
)
end

it "returns the relatives paths to Rails.root" do
expect(Dotenv::Rails.files.last).to eql(fixture_path(".env"))
allow(Rails).to receive(:root).and_return(Pathname.new("/tmp"))
expect(Dotenv::Rails.files.last.to_s).to eql("/tmp/.env")
end

it "returns absolute paths unchanged" do
Dotenv::Rails.files = ["/tmp/.env"]
expect(Dotenv::Rails.files).to eql([Pathname.new("/tmp/.env")])
end
end

it "watches other loaded files with Spring" do
@@ -150,5 +161,17 @@
expect(Dotenv::Rails.instance).not_to receive(:require).with("dotenv/autorestore")
application.initialize!
end

it "is not loaded if ClimateControl is defined" do
stub_const("ClimateControl", Module.new)
expect(Dotenv::Rails.instance).not_to receive(:require).with("dotenv/autorestore")
application.initialize!
end

it "is not loaded if IceAge is defined" do
stub_const("IceAge", Module.new)
expect(Dotenv::Rails.instance).not_to receive(:require).with("dotenv/autorestore")
application.initialize!
end
end
end