Permalink
Browse files

Merge pull request #318 from jeroenj/cap-rollback

Makes sure capistrano cd's to the right directory when executing a deploy:rollback
  • Loading branch information...
2 parents 0c6596f + aa9ba24 commit d25009dee11de352b6fa25c4897aa61b40189a0e @javan committed Feb 22, 2013
Showing with 30 additions and 9 deletions.
  1. +2 −9 lib/whenever/capistrano/recipes.rb
  2. +12 −0 lib/whenever/capistrano/support.rb
  3. +16 −0 test/unit/capistrano_support_test.rb
@@ -22,18 +22,11 @@
}
if whenever_servers.any?
+ args = whenever_prepare_for_rollback(args) if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'
whenever_run_commands(args)
on_rollback do
- if fetch(:previous_release)
- # rollback to the previous release's crontab
- args[:path] = fetch(:previous_release)
- else
- # clear the crontab if no previous release
- args[:path] = fetch(:release_path)
- args[:flags] = fetch(:whenever_clear_flags)
- end
-
+ args = whenever_prepare_for_rollback(args)
whenever_run_commands(args)
end
end
@@ -22,6 +22,18 @@ def whenever_server_roles
end
end
+ def whenever_prepare_for_rollback args
+ if fetch(:previous_release)
+ # rollback to the previous release's crontab
+ args[:path] = fetch(:previous_release)
+ else
+ # clear the crontab if no previous release
+ args[:path] = fetch(:release_path)
+ args[:flags] = fetch(:whenever_clear_flags)
+ end
+ args
+ end
+
def whenever_run_commands(args)
unless [:command, :path, :flags].all? { |a| args.include?(a) }
raise ArgumentError, ":command, :path, & :flags are required"
@@ -78,6 +78,22 @@ class CapistranoSupportTest < Test::Unit::TestCase
end
end
+ context "#whenever_prepare_for_rollback" do
+ should "set path to previous_release if there is a previous release" do
+ args = {}
+ @capistrano.stubs(:fetch).with(:previous_release).returns("/some/path/20121221010000")
+ assert_equal({:path => "/some/path/20121221010000"}, @capistrano.whenever_prepare_for_rollback(args))
+ end
+
+ should "set path to release_path and flags to whenever_clear_flags if there is no previous release" do
+ args = {}
+ @capistrano.stubs(:fetch).with(:previous_release).returns(nil)
+ @capistrano.stubs(:fetch).with(:release_path).returns("/some/path/20121221010000")
+ @capistrano.stubs(:fetch).with(:whenever_clear_flags).returns("--clear-crontab whenever_identifier")
+ assert_equal({:path => "/some/path/20121221010000", :flags => "--clear-crontab whenever_identifier"}, @capistrano.whenever_prepare_for_rollback(args))
+ end
+ end
+
context "#whenever_run_commands" do
should "require :command arg" do
assert_raise ArgumentError do

0 comments on commit d25009d

Please sign in to comment.