Skip to content

Commit decb213

Browse files
committed
Fallback to production when Rails env config is missing
1 parent 179856f commit decb213

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/shakapacker/env.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Shakapacker::Env
2+
FALLBACK_ENV = "production".freeze
3+
24
delegate :config_path, :logger, to: :@instance
35

46
def self.inquire(instance)
@@ -11,7 +13,7 @@ def initialize(instance)
1113

1214
def inquire
1315
fallback_env_warning if config_path.exist? && !current
14-
current || Shakapacker::DEFAULT_ENV.inquiry
16+
current || FALLBACK_ENV.inquiry
1517
end
1618

1719
private
@@ -20,7 +22,7 @@ def current
2022
end
2123

2224
def fallback_env_warning
23-
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in #{config_path}, falling back to #{Shakapacker::DEFAULT_ENV} environment"
25+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in #{config_path}, falling back to #{FALLBACK_ENV} environment"
2426
end
2527

2628
def available_environments

spec/shakapacker/env_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
expect(Shakapacker.env).to eq Rails.env
66
end
77

8-
it "uses development env without config" do
8+
it "uses production env when config for current env is missing" do
99
with_rails_env("foo") do
10-
expect(Shakapacker.env).to eq "development"
10+
expect(Shakapacker.env).to eq "production"
1111
end
1212
end
1313

0 commit comments

Comments
 (0)