1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Fix renaming of the deprecated "deploy:symlink" task to "deploy:create_symlink"

An earlier commit did not account for the case when the "deploy:symlink" task appears as a "before" or "after" hook.
This commit is contained in:
Roy Liu 2012-08-21 01:30:51 -04:00
parent d263896aa4
commit 662270778a
2 changed files with 32 additions and 22 deletions

View file

@ -19,7 +19,7 @@ module Capistrano
end
def invoke_task_directly_with_callbacks(task) #:nodoc:
trigger :before, task
result = invoke_task_directly_without_callbacks(task)
@ -106,24 +106,30 @@ module Capistrano
elsif block
callbacks[event] << ProcCallback.new(block, options)
else
args.each do |name|
[:only, :except].each do |key|
if options[key] == 'deploy:symlink'
warn "[Deprecation Warning] This API has changed, please hook `deploy:create_symlink` instead of `deploy:symlink`."
options[key] = 'deploy:create_symlink'
elsif options[key].is_a?(Array) && options[key].include?('deploy:symlink')
warn "[Deprecation Warning] This API has changed, please hook `deploy:create_symlink` instead of `deploy:symlink`."
options[key] = options[key].collect do |task|
task == 'deploy:symlink' ? 'deploy:create_symlink' : task
end
end
end
callbacks[event] << TaskCallback.new(self, name, options)
end
args = filter_deprecated_tasks(args)
options[:only] = filter_deprecated_tasks(options[:only])
options[:expect] = filter_deprecated_tasks(options[:expect])
callbacks[event].concat(args.map { |name| TaskCallback.new(self, name, options) })
end
end
# Filters the given task name or names and attempts to replace deprecated tasks with their equivalents.
def filter_deprecated_tasks(names)
deprecation_msg = "[Deprecation Warning] This API has changed, please hook `deploy:create_symlink` instead of" \
" `deploy:symlink`."
if names == "deploy:symlink"
warn deprecation_msg
names = "deploy:create_symlink"
elsif names.is_a?(Array)
warn deprecation_msg
names = names.map { |name| name == "deploy:symlink" ? "deploy:create_symlink" : name }
end
names
end
# Trigger the named event for the named task. All associated callbacks
# will be fired, in the order they were defined.
def trigger(event, task=nil)

View file

@ -40,8 +40,10 @@ class ConfigurationCallbacksTest < Test::Unit::TestCase
end
def test_before_should_map_before_deploy_symlink
@config.before "deploy:symlink", "bing:blang"
assert_equal ["deploy:create_symlink"], @config.callbacks[:before].last.only
@config.before "deploy:symlink", "bing:blang", "deploy:symlink"
assert_equal "bing:blang", @config.callbacks[:before][0].source
assert_equal "deploy:create_symlink", @config.callbacks[:before][1].source
assert_equal ["deploy:create_symlink"], @config.callbacks[:before][1].only
end
def test_before_should_map_before_deploy_symlink_array
@ -55,13 +57,15 @@ class ConfigurationCallbacksTest < Test::Unit::TestCase
end
def test_after_should_map_before_deploy_symlink
@config.after "deploy:symlink", "bing:blang"
assert_equal ["deploy:create_symlink"], @config.callbacks[:after].last.only
@config.after "deploy:symlink", "bing:blang", "deploy:symlink"
assert_equal "bing:blang", @config.callbacks[:after][0].source
assert_equal "deploy:create_symlink", @config.callbacks[:after][1].source
assert_equal ["deploy:create_symlink"], @config.callbacks[:after][1].only
end
def test_after_should_map_before_deploy_symlink_array
@config.after ["deploy:symlink", 'bingo:blast'], "bing:blang"
assert_equal ["deploy:create_symlink", 'bingo:blast'], @config.callbacks[:after].last.only
@config.after ["deploy:symlink", "bingo:blast"], "bing:blang"
assert_equal ["deploy:create_symlink", "bingo:blast"], @config.callbacks[:after].last.only
end
def test_on_with_single_reference_should_add_task_callback