Skip to content

Commit

Permalink
Don't allow nil environment variables to pass through
Browse files Browse the repository at this point in the history
  • Loading branch information
njonsson committed Feb 3, 2012
1 parent ae8566f commit b4c35a2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,48 @@ Feature: The #mirror_rake_tasks DSL method with arguments of a defined task and
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""

Scenario: mirror Rake task 'with_period' with its implementation, ignoring nil environment variable names
Given a full-featured Rakefile
And a Capfile with:
"""
set :current_path, '/path/to/current/deployed/application'
set :rails_env, 'production'
Cape do
mirror_rake_tasks :roles => :app do |env|
env[nil] = 'foo'
end
end
"""
When I run `cap with_period`
Then the output should contain:
"""
* executing `with_period'
* executing "cd /path/to/current/deployed/application && /usr/bin/env rake with_period"
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""

Scenario: mirror Rake task 'with_period' with its implementation, ignoring nil environment variable values
Given a full-featured Rakefile
And a Capfile with:
"""
set :current_path, '/path/to/current/deployed/application'
set :rails_env, 'production'
Cape do
mirror_rake_tasks :roles => :app do |env|
env['FOO'] = nil
end
end
"""
When I run `cap with_period`
Then the output should contain:
"""
* executing `with_period'
* executing "cd /path/to/current/deployed/application && /usr/bin/env rake with_period"
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""

Scenario: mirror Rake task 'with_one_arg' with its description
Given a full-featured Rakefile
And a Capfile with:
Expand Down
3 changes: 3 additions & 0 deletions lib/cape/capistrano.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def implement(task, capistrano_context, options, &env_block)
end
env_hash = {}
env_block.call(env_hash) if env_block
env_hash.reject! do |var_name, var_value|
var_name.nil? || var_value.nil?
end
env_strings = env_hash.collect do |var_name, var_value|
"#{var_name}=#{var_value.inspect}"
end
Expand Down

0 comments on commit b4c35a2

Please sign in to comment.