Skip to content

Commit

Permalink
Merge pull request #483 from bkeepers/autorestore-cc
Browse files Browse the repository at this point in the history
Disable autorestore if using climate_control or ice_age
  • Loading branch information
bkeepers committed Feb 14, 2024
2 parents dd40e1c + 86390d2 commit cb8cd58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion lib/dotenv/rails.rb
Expand Up @@ -32,7 +32,7 @@ def initialize
root.join(".env.#{env}"),
root.join(".env")
].compact,
autorestore: env.test?
autorestore: env.test? && !defined?(ClimateControl) && !defined?(IceAge)
)
end

Expand Down
12 changes: 12 additions & 0 deletions spec/dotenv/rails_spec.rb
Expand Up @@ -150,5 +150,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

0 comments on commit cb8cd58

Please sign in to comment.