-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from rgo/ticket-193-alias-task
Alias Task.
- Loading branch information
Showing
7 changed files
with
169 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Capistrano | ||
class Configuration | ||
module AliasTask | ||
# Attempts to find the task at the given fully-qualified path, and | ||
# alias it. If arguments don't have correct task names, an ArgumentError | ||
# wil be raised. If no such task exists, a Capistrano::NoSuchTaskError | ||
# will be raised. | ||
# | ||
# Usage: | ||
# | ||
# alias_task :original_deploy, :deploy | ||
# | ||
def alias_task(new_name, old_name) | ||
if !new_name.respond_to?(:to_sym) or !old_name.respond_to?(:to_sym) | ||
raise ArgumentError, "expected a valid task name" | ||
end | ||
|
||
task = find_task(old_name) or raise NoSuchTaskError, "the task `#{old_name}' does not exist" | ||
task.name = new_name | ||
|
||
define_task(task) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,4 +140,4 @@ def invoke_task_directly(task) | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
require 'utils' | ||
require 'capistrano/configuration/alias_task' | ||
require 'capistrano/configuration/execution' | ||
require 'capistrano/configuration/namespaces' | ||
require 'capistrano/task_definition' | ||
|
||
class AliasTaskTest < Test::Unit::TestCase | ||
class MockConfig | ||
attr_reader :options | ||
attr_accessor :logger | ||
|
||
def initialize(options={}) | ||
@options = {} | ||
@logger = options.delete(:logger) | ||
end | ||
|
||
include Capistrano::Configuration::AliasTask | ||
include Capistrano::Configuration::Execution | ||
include Capistrano::Configuration::Namespaces | ||
end | ||
|
||
def setup | ||
@config = MockConfig.new( :logger => stub(:debug => nil, :info => nil, :important => nil) ) | ||
end | ||
|
||
def test_makes_a_copy_of_the_task | ||
@config.task(:foo) { 42 } | ||
@config.alias_task 'new_foo', 'foo' | ||
|
||
assert @config.tasks.key?(:new_foo) | ||
end | ||
|
||
def test_aliased_task_do_the_same | ||
@config.task(:foo) { 42 } | ||
@config.alias_task 'new_foo', 'foo' | ||
|
||
assert_equal 42, @config.find_and_execute_task('new_foo') | ||
end | ||
|
||
def test_aliased_task_should_preserve_description | ||
@config.task(:foo, :desc => "the Ultimate Question of Life, the Universe, and Everything" ) { 42 } | ||
@config.alias_task 'new_foo', 'foo' | ||
|
||
task = @config.find_task('foo') | ||
new_task = @config.find_task('new_foo') | ||
|
||
assert_equal task.description, new_task.description | ||
end | ||
|
||
def test_aliased_task_should_preserve_on_error | ||
@config.task(:foo, :on_error => :continue) { 42 } | ||
@config.alias_task 'new_foo', 'foo' | ||
|
||
task = @config.find_task('foo') | ||
new_task = @config.find_task('new_foo') | ||
|
||
assert_equal task.on_error, new_task.on_error | ||
end | ||
|
||
def test_aliased_task_should_preserve_max_hosts | ||
@config.task(:foo, :max_hosts => 5) { 42 } | ||
@config.alias_task 'new_foo', 'foo' | ||
|
||
task = @config.find_task('foo') | ||
new_task = @config.find_task('new_foo') | ||
|
||
assert_equal task.max_hosts, new_task.max_hosts | ||
end | ||
|
||
def test_raise_exception_when_task_doesnt_exist | ||
assert_raises(Capistrano::NoSuchTaskError) { @config.alias_task 'non_existant_task', 'fail_miserably' } | ||
end | ||
|
||
def test_convert_task_names_using_to_str | ||
@config.task(:foo, :role => :app) { 42 } | ||
|
||
@config.alias_task 'one', 'foo' | ||
@config.alias_task :two, 'foo' | ||
@config.alias_task 'three', :foo | ||
@config.alias_task :four, :foo | ||
|
||
assert @config.tasks.key?(:one) | ||
assert @config.tasks.key?(:two) | ||
assert @config.tasks.key?(:three) | ||
assert @config.tasks.key?(:four) | ||
end | ||
|
||
def test_raise_an_exception_when_task_names_can_not_be_converted | ||
@config.task(:foo, :role => :app) { 42 } | ||
|
||
assert_raises(ArgumentError) { @config.alias_task mock('x'), :foo } | ||
end | ||
|
||
def test_should_include_namespace | ||
@config.namespace(:outer) do | ||
task(:foo) { 42 } | ||
alias_task 'new_foo', 'foo' | ||
|
||
namespace(:inner) do | ||
task(:foo) { 43 } | ||
alias_task 'new_foo', 'foo' | ||
end | ||
end | ||
|
||
assert_equal 42, @config.find_and_execute_task('outer:new_foo') | ||
assert_equal 42, @config.find_and_execute_task('outer:foo') | ||
assert_equal 43, @config.find_and_execute_task('outer:inner:new_foo') | ||
assert_equal 43, @config.find_and_execute_task('outer:inner:foo') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters