Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siegy22 committed Jan 26, 2017
1 parent c9597d6 commit a1527f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
19 changes: 12 additions & 7 deletions lib/dotenv/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ class Railtie < Rails::Railtie
# This will get called during the `before_configuration` callback, but you
# can manually call `Dotenv::Railtie.load` if you needed it sooner.
def load
envs = [
root.join(".env.#{Rails.env}.local"),
root.join(".env.#{Rails.env}"),
root.join(".env")
]
envs.insert(1, root.join(".env.local")) unless Rails.env == 'test'
Dotenv.load(*envs)
Dotenv.load(*dotenv_files)
end

# Internal: `Rails.root` is nil in Rails 4.1 before the application is
Expand All @@ -58,5 +52,16 @@ def self.load
end

config.before_configuration { load }

private
def dotenv_files
envs = [
root.join(".env.#{Rails.env}.local"),
root.join(".env.#{Rails.env}"),
root.join(".env")
]
envs.insert(1, root.join(".env.local")) unless Rails.env == 'test'
envs
end
end
end
10 changes: 5 additions & 5 deletions spec/dotenv/rails_development_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def add(*items)
ENV["RAILS_ENV"] = "development"
allow(Rails).to receive(:root)
.and_return Pathname.new(File.expand_path("../../fixtures", __FILE__))
allow(Rails).to receive(:env).and_return "development"
Rails.application = double(:application)
Spring.watcher = SpecWatcher.new
end
Expand Down Expand Up @@ -52,12 +53,11 @@ def add(*items)
end

it "loads .env, .env.local, and .env.#{Rails.env}" do
p Rails.root
expect(Spring.watcher.items).to eql(
expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql(
[
Rails.root.join(".env.local").to_s,
Rails.root.join(".env.development").to_s,
Rails.root.join(".env").to_s
Rails.root.join(".env.local"),
Rails.root.join(".env.development"),
Rails.root.join(".env")
]
)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/dotenv/rails_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def add(*items)
ENV["RAILS_ENV"] = "test"
allow(Rails).to receive(:root)
.and_return Pathname.new(File.expand_path("../../fixtures", __FILE__))
allow(Rails).to receive(:env).and_return "test"
Rails.application = double(:application)
Spring.watcher = SpecWatcher.new
end
Expand Down Expand Up @@ -52,7 +53,7 @@ def add(*items)
end

it "does not load .env.local in test rails environment" do
expect(Spring.watcher.items).to eql(
expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql(
[
Rails.root.join(".env.test.local").to_s,
Rails.root.join(".env.test").to_s,
Expand Down

0 comments on commit a1527f3

Please sign in to comment.