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.1
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.2
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Feb 15, 2024

  1. Restore ability to mutate Dotenv::Rails.files

    bkeepers committed Feb 15, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    kamilmysliwiec Kamil Mysliwiec
    Copy the full SHA
    069ec4f View commit details
  2. Merge pull request #486 from bkeepers/mutate-rails-files

    Restore ability to mutate Dotenv::Rails.files
    bkeepers authored Feb 15, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    kamilmysliwiec Kamil Mysliwiec
    Copy the full SHA
    6a5615d View commit details
  3. Prepare for 3.0.2

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

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

## 3.0.2

* Fix: Restore ability to mutate Dotenv::Rails.files by @bkeepers in https://github.com/bkeepers/dotenv/pull/486

## 3.0.1

**What's Changed**
11 changes: 3 additions & 8 deletions lib/dotenv/rails.rb
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
module Dotenv
# Rails integration for using Dotenv to load ENV variables from a file
class Rails < ::Rails::Railtie
delegate :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, :logger=, to: "config.dotenv"
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, :logger=, to: "config.dotenv"

def initialize
super()
@@ -42,22 +42,17 @@ def initialize
)
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
# can manually call `Dotenv::Rails.load` if you needed it sooner.
def load
Dotenv.load(*files, overwrite: overwrite)
Dotenv.load(*files.map { |file| root.join(file).to_s }, overwrite: overwrite)
end

def overload
deprecator.warn("Dotenv::Rails.overload is deprecated. Set `Dotenv::Rails.overwrite = true` and call Dotenv::Rails.load instead.")
Dotenv.load(*files, overwrite: true)
Dotenv.load(*files.map { |file| root.join(file).to_s }, overwrite: true)
end

# Internal: `Rails.root` is nil in Rails 4.1 before the application is
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.1".freeze
VERSION = "3.0.2".freeze
end
39 changes: 23 additions & 16 deletions spec/dotenv/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -47,10 +47,10 @@

expect(Dotenv::Rails.files).to eql(
[
application.root.join(".env.development.local"),
application.root.join(".env.local"),
application.root.join(".env.development"),
application.root.join(".env")
".env.development.local",
".env.local",
".env.development",
".env"
]
)
end
@@ -59,22 +59,16 @@
Rails.env = "test"
expect(Dotenv::Rails.files).to eql(
[
application.root.join(".env.test.local"),
application.root.join(".env.test"),
application.root.join(".env")
".env.test.local",
".env.test",
".env"
]
)
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")])
it "can be modified in place" do
Dotenv::Rails.files << ".env.shared"
expect(Dotenv::Rails.files.last).to eq(".env.shared")
end
end

@@ -110,6 +104,19 @@
expect { subject }.to change { ENV["PLAIN"] }.from(nil).to("true")
end

it "loads file relative to Rails.root" do
allow(Rails).to receive(:root).and_return(Pathname.new("/tmp"))
Dotenv::Rails.files = [".env"]
expect(Dotenv).to receive(:load).with("/tmp/.env", {overwrite: false})
subject
end

it "returns absolute paths unchanged" do
Dotenv::Rails.files = ["/tmp/.env"]
expect(Dotenv).to receive(:load).with("/tmp/.env", {overwrite: false})
subject
end

context "with overwrite = true" do
before { Dotenv::Rails.overwrite = true }