Skip to content

Commit

Permalink
Make unicorn_env default to rails_env or 'production'
Browse files Browse the repository at this point in the history
This contributes towards resolving #46 and #64.
  • Loading branch information
Adam Spiers committed Sep 2, 2013
1 parent 6e91a25 commit 883b1f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -61,7 +61,7 @@ You can modify any of the following options in your `deploy.rb` config.
- `unicorn_roles` - Define which roles to perform unicorn recipes on. Default to `:app`.
- `unicorn_config_path` - Set the directory where unicorn config files reside. Default to `current_path/config`.
- `unicorn_config_filename` - Set the filename of the unicorn config file loaded from `unicorn_config_path`. Should not be present in multistage installations. Default to `unicorn.rb`.
- `unicorn_env` - Set basename of unicorn config `.rb` file to be used loaded from `unicorn_config_path`. Default to `app_env` variable.
- `unicorn_env` - Set basename of unicorn config `.rb` file to be used loaded from `unicorn_config_path`. Default to `rails_env` variable if set, otherwise `production`.
- `app_env` - Set the value which will be passed to unicorn via [the `-E` parameter as the Rack environment](http://unicorn.bogomips.org/unicorn_1.html). Valid values are `development`, `deployment`, and `none`. Default to `rails_env` variable if set, otherwise `production` (this is a bug which will be fixed in the following commit).
- `app_subdir` - If your app lives in a subdirectory 'rails' (say) of your repository, set this to 'foo/' (the trailing slash is required).

Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano-unicorn/capistrano_integration.rb
Expand Up @@ -21,7 +21,7 @@ def self.load_into(capistrano_config)
_cset(:app_subdir) { '' }
_cset(:app_path) { fetch(:current_path) + fetch(:app_subdir) }
_cset(:unicorn_pid) { "#{fetch(:app_path)}/tmp/pids/unicorn.pid" }
_cset(:unicorn_env) { fetch(:app_env) }
_cset(:unicorn_env) { fetch(:rails_env, 'production' ) }
_cset(:unicorn_bin) { "unicorn" }
_cset(:unicorn_bundle) { fetch(:bundle_cmd) rescue 'bundle' }
_cset(:bundle_gemfile) { fetch(:app_path) + '/Gemfile' }
Expand Down
26 changes: 24 additions & 2 deletions spec/capistrano_integration_spec.rb
Expand Up @@ -5,8 +5,28 @@
@configuration = Capistrano::Configuration.new
@configuration.extend(Capistrano::Spec::ConfigurationExtension)
CapistranoUnicorn::CapistranoIntegration.load_into(@configuration)
end

describe "unicorn_env" do
before do
# define _cset etc. from capistrano
@configuration.load 'deploy'

# capistrano-unicorn variables are set during a 'before'
# callback, so in order to be able to test the result, we need
# to ensure the callback is triggered.
@configuration.trigger :before
end

it "should default to value of rails_env if set" do
@configuration.set(:rails_env, :staging)
@configuration.fetch(:unicorn_env).should == \
@configuration.fetch(:rails_env)
end

@configuration.stub(:_cset)
it "should default to production if rails_env not set" do
@configuration.fetch(:unicorn_env).should == 'production'
end
end

shared_examples_for "a task" do |task_name|
Expand All @@ -29,6 +49,7 @@
describe 'unicorn:start' do
before do
@configuration.stub(:start_unicorn)
@configuration.stub(:_cset)
end

it_behaves_like "a task", 'unicorn:start'
Expand All @@ -43,6 +64,7 @@
describe 'unicorn:stop' do
before do
@configuration.stub(:kill_unicorn)
@configuration.stub(:_cset)
end

it_behaves_like "a task", 'unicorn:stop'
Expand All @@ -65,4 +87,4 @@
@configuration.kill_unicorn('QUIT').should match /-u deploy_user kill -s QUIT `cat 999`;/
end
end
end
end

0 comments on commit 883b1f6

Please sign in to comment.