Skip to content

Commit

Permalink
Formerly remove all support for before_, around_, and after_ magical …
Browse files Browse the repository at this point in the history
…method names
  • Loading branch information
leehambley committed Feb 20, 2012
1 parent 7fee3ab commit 3eecac2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 74 deletions.
21 changes: 1 addition & 20 deletions lib/capistrano/configuration/callbacks.rb
Expand Up @@ -19,18 +19,13 @@ def initialize_with_callbacks(*args) #:nodoc:
end

def invoke_task_directly_with_callbacks(task) #:nodoc:
before = find_hook(task, :before)
execute_task(before) if before


trigger :before, task

result = invoke_task_directly_without_callbacks(task)

trigger :after, task

after = find_hook(task, :after)
execute_task(after) if after

return result
end

Expand Down Expand Up @@ -132,20 +127,6 @@ def trigger(event, task=nil)
end
end

private

# Looks for before_foo or after_foo tasks. This method of extending tasks
# is now discouraged (though not formally deprecated). You should use the
# before and after methods to declare hooks for such callbacks.
def find_hook(task, hook)
if task == task.namespace.default_task
result = task.namespace.search_task("#{hook}_#{task.namespace.name}")
return result if result
end

task.namespace.search_task("#{hook}_#{task.name}")
end

end
end
end
43 changes: 0 additions & 43 deletions test/configuration/callbacks_test.rb
Expand Up @@ -186,47 +186,4 @@ def test_execute_task_without_named_hooks_should_just_call_task
assert_equal [task], @config.called
end

def test_execute_task_with_named_before_hook_should_call_named_before_hook
ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
before_task = stub(:fully_qualified_name => "any:old:before_thing", :name => "before_thing", :namespace => ns)

ns.stubs(:search_task).returns(nil)
ns.expects(:search_task).with("before_thing").returns(before_task)

@config.execute_task(task)
assert_equal [before_task, task], @config.called
end

def test_execute_task_with_named_after_hook_should_call_named_after_hook
ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
after_task = stub(:fully_qualified_name => "any:old:after_thing", :name => "after_thing", :namespace => ns)

ns.stubs(:search_task).returns(nil)
ns.expects(:search_task).with("after_thing").returns(after_task)

@config.execute_task(task)
assert_equal [task, after_task], @config.called
end

def test_execute_task_with_on_hooks_should_trigger_hooks_around_task
ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
before_task = stub(:fully_qualified_name => "any:old:before_thing", :name => "before_thing", :namespace => ns)
after_task = stub(:fully_qualified_name => "any:old:after_thing", :name => "after_thing", :namespace => ns)

ns.stubs(:search_task).returns(nil)
ns.expects(:search_task).with("before_thing").returns(before_task)
ns.expects(:search_task).with("after_thing").returns(after_task)

@config.before("any:old:thing", :first_this, :then_this)
@config.after("any:old:thing", :and_then_this, :lastly_this)

[:first_this, :then_this, :and_then_this, :lastly_this].each do |t|
@config.expects(:find_and_execute_task).with(t)
end

@config.execute_task(task)
end
end
11 changes: 0 additions & 11 deletions test/configuration_test.rb
Expand Up @@ -74,15 +74,4 @@ def test_tasks_in_nested_namespace_should_be_able_to_call_shadowed_tasks_in_pare
assert !@config[:called_inner_first]
end

def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
@config.namespace(:outer) do
task(:default) { set :called_default, true }
task(:before_outer) { set :called_before_outer, true }
task(:after_outer) { set :called_after_outer, true }
end
@config.outer.default
assert @config[:called_before_outer]
assert @config[:called_default]
assert @config[:called_after_outer]
end
end

0 comments on commit 3eecac2

Please sign in to comment.