Skip to content

Commit

Permalink
Remove integration with RAILS_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jun 15, 2015
1 parent 82d9600 commit f4d4b02
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ matrix:
allow_failures:
- rvm: rbx-2.1.1
- rvm: ruby-head
env: ARUBA_TIMEOUT=120 RAILS_ENV=development AHN_ENV=development
env: ARUBA_TIMEOUT=120 AHN_ENV=development
notifications:
irc: "irc.freenode.org#adhearsion"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [develop](https://github.com/adhearsion/adhearsion)
* Change: Removed `Adhearsion.ahn_root=` which was deprecated in favour of `Adhearsion.root=`
* Change: Remove integration with `RAILS_ENV`

# [2.6.1](https://github.com/adhearsion/adhearsion/compare/v2.6.0...v2.6.1) - [2015-06-15](https://rubygems.org/gems/adhearsion/versions/2.6.1)
* Bugfix: Improve Call initialization performance. Use an ActorProxy (subclass) instead of a method_missing definition on every Call.new. This considerably improves Call.new performance; benchmarks show approximately a 30-40% improvement: https://gist.github.com/kares/3576e272250204eb66d1
Expand Down
2 changes: 1 addition & 1 deletion lib/adhearsion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def initialize_config
end

def environment
ENV['AHN_ENV'] || ENV['RAILS_ENV'] || :development
ENV['AHN_ENV'] || :development
end

def environments
Expand Down
2 changes: 1 addition & 1 deletion lib/adhearsion/cli_commands/ahn_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def execute_from_app_dir!(path)
raise PathInvalid, path unless File.directory?(path)

raise PathInvalid, path unless ScriptAhnLoader.in_ahn_application?(path)
# load script/ahn which than boots the Rails environment :
# load script/ahn which then boots the application environment
Dir.chdir(path) { ScriptAhnLoader.load_script_ahn(path) }
path
end
Expand Down
20 changes: 0 additions & 20 deletions lib/adhearsion/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def start
catch_termination_signal
set_ahn_proc_name
initialize_exception_logger
update_rails_env_var
init_plugins

run_plugins
Expand Down Expand Up @@ -92,25 +91,6 @@ def debugging_log
end
end

def update_rails_env_var
env = ENV['AHN_ENV']
if env && Adhearsion.config.valid_environment?(env.to_sym)
unless ENV['RAILS_ENV']
logger.info "Copying AHN_ENV (#{env}) to RAILS_ENV"
ENV['RAILS_ENV'] = env
end
else
unless ENV['RAILS_ENV']
env = Adhearsion.config.platform.environment.to_s
ENV['AHN_ENV'] = env
logger.info "Setting RAILS_ENV to \"#{env}\""
ENV['RAILS_ENV'] = env
end
end
logger.warn "AHN_ENV(#{ENV['AHN_ENV']}) does not match RAILS_ENV(#{ENV['RAILS_ENV']})!" unless ENV['RAILS_ENV'] == ENV['AHN_ENV']
env
end

def default_pid_path
File.join Adhearsion.config.root, DEFAULT_PID_FILE_NAME
end
Expand Down
80 changes: 0 additions & 80 deletions spec/adhearsion/initializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,83 +196,3 @@
end
end
end

describe "Updating RAILS_ENV variable" do
include InitializerStubs

before do
::Logging.reset
expect(Adhearsion::Logging).to receive(:start).once.and_return('')
expect(::Logging::Appenders).to receive(:file).and_return(nil)
Adhearsion.config = nil
end

before do
ENV['RAILS_ENV'] = nil
ENV['AHN_ENV'] = nil
end

after :all do
ENV['RAILS_ENV'] = nil
ENV['AHN_ENV'] = nil
end

describe "when neither RAILS_ENV nor AHN_ENV are set" do
[:development, :production, :staging, :test].each do |env|
it "should set the RAILS_ENV to #{env.to_s} when Adhearsion environment is set to #{env.to_s}" do
ahn = nil
stub_behavior_for_initializer_with_no_path_changing_behavior do
Adhearsion.config.platform.environment = env
ahn = Adhearsion::Initializer.start
end
ahn.update_rails_env_var
expect(ENV['RAILS_ENV']).to eq(env.to_s)
end
end
end

context "when RAILS_ENV is set" do
before do
ENV['RAILS_ENV'] = "test"
end

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
expect(ENV['RAILS_ENV']).to eq("test")
end
end

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
expect(ENV['RAILS_ENV']).to eq("test")
end
end
end

context "when RAILS_ENV is unset and AHN_ENV is set" do
before do
ENV['AHN_ENV'] = "production"
end

it "should define the RAILS_ENV value with the AHN_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
expect(ENV['RAILS_ENV']).to eq("production")
end
end

end
2 changes: 1 addition & 1 deletion spec/support/initializer_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module InitializerStubs
UNWANTED_BEHAVIOR = {
Adhearsion::Initializer => [:debugging_log, :initialize_log_paths, :update_rails_env_var, :require, :load, :init_plugins, :run_plugins]
Adhearsion::Initializer => [:debugging_log, :initialize_log_paths, :require, :load, :init_plugins, :run_plugins]
} unless defined? UNWANTED_BEHAVIOR

def stub_behavior_for_initializer_with_no_path_changing_behavior
Expand Down

0 comments on commit f4d4b02

Please sign in to comment.