public
Description: Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Make sure a task only uses the last on_rollback block, once, on rollback [#36 
tagged:committed state:resolved]
Jamis Buck (author)
Tue Aug 19 08:19:30 -0700 2008
commit  1923c120f58091e01e281628c7f37ef1f9463d4f
tree    0661ae00ad67520badfef6a59e72ee30d8ab2d60
parent  e70fa828e61c837527ba17d4f3b11ce3f81798dd
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 == (unreleased)
0
 
0
+* Make sure a task only uses the last on_rollback block, once, on rollback [Jamis Buck]
0
+
0
 * Add :shared_children variable to customize which subdirectories are created by deploy:setup [Jonathan Share]
0
 
0
 * Allow filename globbing in copy_exclude setting for the copy strategy [Jonathan Share]
...
60
61
62
 
 
63
64
65
66
67
...
60
61
62
63
64
65
 
66
67
68
0
@@ -60,8 +60,9 @@ module Capistrano
0
       # hook will be executed.
0
       def on_rollback(&block)
0
         if transaction?
0
+          # don't note a new rollback request if one has already been set
0
+          rollback_requests << task_call_frames.last unless task_call_frames.last.rollback
0
           task_call_frames.last.rollback = block
0
-          rollback_requests << task_call_frames.last
0
         end
0
       end
0
 
...
116
117
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
120
121
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
0
@@ -116,6 +116,22 @@ class ConfigurationExecutionTest < Test::Unit::TestCase
0
     assert @config.state[:aaa]
0
   end
0
 
0
+  def test_on_rollback_called_twice_should_result_in_last_rollback_block_being_effective
0
+    aaa = new_task(@config, :aaa) do
0
+      transaction do
0
+        on_rollback { (state[:rollback] ||= []) << :first }
0
+        on_rollback { (state[:rollback] ||= []) << :second }
0
+        raise "boom"
0
+      end
0
+    end
0
+
0
+    assert_raises(RuntimeError) do
0
+      @config.execute_task(aaa)
0
+    end
0
+
0
+    assert_equal [:second], @config.state[:rollback]
0
+  end
0
+
0
   def test_find_and_execute_task_should_raise_error_when_task_cannot_be_found
0
     @config.expects(:find_task).with("path:to:task").returns(nil)
0
     assert_raises(Capistrano::NoSuchTaskError) { @config.find_and_execute_task("path:to:task") }

Comments