Skip to content

Commit

Permalink
[BUGFIX] Never override AHN_ENV or RAILS_ENV if they are set
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jan 31, 2012
1 parent df96bf6 commit 8fd1da4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions lib/adhearsion/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def start
def update_rails_env_var
env = ENV['AHN_ENV']
if env && Adhearsion.config.valid_environment?(env.to_sym)
if ENV['RAILS_ENV'] == env
logger.info "Using the configured value for RAILS_ENV : <#{env}>"
if ENV['RAILS_ENV']
logger.info "Using provided RAILS_ENV value of <#{ENV['RAILS_ENV']}>"
else
logger.warn "Updating AHN_RAILS variable to <#{env}>"
logger.warn "Setting RAILS_ENV variable to <#{env}>"
ENV['RAILS_ENV'] = env
end
else
Expand All @@ -75,7 +75,7 @@ def update_rails_env_var
logger.info "Using the configured value for RAILS_ENV : <#{env}>"
else
env = Adhearsion.config.platform.environment.to_s
logger.info "Defining AHN_RAILS variable to <#{env}>"
logger.info "Defining RAILS_ENV variable to <#{env}>"
ENV['RAILS_ENV'] = env
end
end
Expand Down
30 changes: 17 additions & 13 deletions spec/adhearsion/initializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,27 @@
ENV['RAILS_ENV'] = "test"
end

it "should preserve the RAILS_ENV value if AHN_ENV is unset" do
ahn = nil
stub_behavior_for_initializer_with_no_path_changing_behavior do
ahn = Adhearsion::Initializer.start
context "if AHN_ENV is set" do
it "should preserve the RAILS_ENV value" do
ENV['AHN_ENV'] = "production"
ahn = nil
stub_behavior_for_initializer_with_no_path_changing_behavior do
ahn = Adhearsion::Initializer.start
end
ahn.update_rails_env_var
ENV['RAILS_ENV'].should == "test"
end
ahn.update_rails_env_var
ENV['RAILS_ENV'].should == "test"
end

it "should update the RAILS_ENV value with the AHN_ENV value" do
ENV['AHN_ENV'] = "production"
ahn = nil
stub_behavior_for_initializer_with_no_path_changing_behavior do
ahn = Adhearsion::Initializer.start
context "if AHN_ENV is unset" do
it "should preserve the RAILS_ENV value" do
ahn = nil
stub_behavior_for_initializer_with_no_path_changing_behavior do
ahn = Adhearsion::Initializer.start
end
ahn.update_rails_env_var
ENV['RAILS_ENV'].should == "test"
end
ahn.update_rails_env_var
ENV['RAILS_ENV'].should == "production"
end
end

Expand Down

0 comments on commit 8fd1da4

Please sign in to comment.