capistrano 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +140 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README +22 -14
  4. data/bin/cap +1 -8
  5. data/bin/capify +77 -0
  6. data/examples/sample.rb +10 -109
  7. data/lib/capistrano.rb +1 -0
  8. data/lib/capistrano/callback.rb +41 -0
  9. data/lib/capistrano/cli.rb +17 -317
  10. data/lib/capistrano/cli/execute.rb +82 -0
  11. data/lib/capistrano/cli/help.rb +102 -0
  12. data/lib/capistrano/cli/help.txt +53 -0
  13. data/lib/capistrano/cli/options.rb +183 -0
  14. data/lib/capistrano/cli/ui.rb +28 -0
  15. data/lib/capistrano/command.rb +62 -29
  16. data/lib/capistrano/configuration.rb +25 -226
  17. data/lib/capistrano/configuration/actions/file_transfer.rb +35 -0
  18. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  19. data/lib/capistrano/configuration/actions/invocation.rb +127 -0
  20. data/lib/capistrano/configuration/callbacks.rb +148 -0
  21. data/lib/capistrano/configuration/connections.rb +159 -0
  22. data/lib/capistrano/configuration/execution.rb +126 -0
  23. data/lib/capistrano/configuration/loading.rb +112 -0
  24. data/lib/capistrano/configuration/namespaces.rb +190 -0
  25. data/lib/capistrano/configuration/roles.rb +51 -0
  26. data/lib/capistrano/configuration/servers.rb +75 -0
  27. data/lib/capistrano/configuration/variables.rb +127 -0
  28. data/lib/capistrano/errors.rb +15 -0
  29. data/lib/capistrano/extensions.rb +27 -8
  30. data/lib/capistrano/gateway.rb +54 -29
  31. data/lib/capistrano/logger.rb +11 -11
  32. data/lib/capistrano/recipes/compat.rb +32 -0
  33. data/lib/capistrano/recipes/deploy.rb +483 -0
  34. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  35. data/lib/capistrano/recipes/deploy/local_dependency.rb +46 -0
  36. data/lib/capistrano/recipes/deploy/remote_dependency.rb +65 -0
  37. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  38. data/lib/capistrano/recipes/deploy/scm/base.rb +180 -0
  39. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  40. data/lib/capistrano/recipes/deploy/scm/cvs.rb +151 -0
  41. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  42. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +129 -0
  43. data/lib/capistrano/recipes/deploy/scm/perforce.rb +126 -0
  44. data/lib/capistrano/recipes/deploy/scm/subversion.rb +103 -0
  45. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  46. data/lib/capistrano/recipes/deploy/strategy/base.rb +64 -0
  47. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  48. data/lib/capistrano/recipes/deploy/strategy/copy.rb +143 -0
  49. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  50. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  51. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +47 -0
  52. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  53. data/lib/capistrano/recipes/standard.rb +26 -276
  54. data/lib/capistrano/recipes/templates/maintenance.rhtml +1 -1
  55. data/lib/capistrano/recipes/upgrade.rb +33 -0
  56. data/lib/capistrano/server_definition.rb +51 -0
  57. data/lib/capistrano/shell.rb +125 -81
  58. data/lib/capistrano/ssh.rb +80 -36
  59. data/lib/capistrano/task_definition.rb +69 -0
  60. data/lib/capistrano/upload.rb +146 -0
  61. data/lib/capistrano/version.rb +13 -17
  62. data/test/cli/execute_test.rb +132 -0
  63. data/test/cli/help_test.rb +139 -0
  64. data/test/cli/options_test.rb +226 -0
  65. data/test/cli/ui_test.rb +28 -0
  66. data/test/cli_test.rb +17 -0
  67. data/test/command_test.rb +284 -25
  68. data/test/configuration/actions/file_transfer_test.rb +40 -0
  69. data/test/configuration/actions/inspect_test.rb +62 -0
  70. data/test/configuration/actions/invocation_test.rb +195 -0
  71. data/test/configuration/callbacks_test.rb +206 -0
  72. data/test/configuration/connections_test.rb +288 -0
  73. data/test/configuration/execution_test.rb +159 -0
  74. data/test/configuration/loading_test.rb +119 -0
  75. data/test/configuration/namespace_dsl_test.rb +283 -0
  76. data/test/configuration/roles_test.rb +47 -0
  77. data/test/configuration/servers_test.rb +90 -0
  78. data/test/configuration/variables_test.rb +180 -0
  79. data/test/configuration_test.rb +60 -212
  80. data/test/deploy/scm/base_test.rb +55 -0
  81. data/test/deploy/strategy/copy_test.rb +146 -0
  82. data/test/extensions_test.rb +69 -0
  83. data/test/fixtures/cli_integration.rb +5 -0
  84. data/test/fixtures/custom.rb +2 -2
  85. data/test/gateway_test.rb +167 -0
  86. data/test/logger_test.rb +123 -0
  87. data/test/server_definition_test.rb +108 -0
  88. data/test/shell_test.rb +64 -0
  89. data/test/ssh_test.rb +67 -154
  90. data/test/task_definition_test.rb +101 -0
  91. data/test/upload_test.rb +131 -0
  92. data/test/utils.rb +31 -39
  93. data/test/version_test.rb +24 -0
  94. metadata +145 -98
  95. data/THANKS +0 -4
  96. data/lib/capistrano/actor.rb +0 -567
  97. data/lib/capistrano/generators/rails/deployment/deployment_generator.rb +0 -25
  98. data/lib/capistrano/generators/rails/deployment/templates/capistrano.rake +0 -49
  99. data/lib/capistrano/generators/rails/deployment/templates/deploy.rb +0 -122
  100. data/lib/capistrano/generators/rails/loader.rb +0 -20
  101. data/lib/capistrano/scm/base.rb +0 -61
  102. data/lib/capistrano/scm/baz.rb +0 -118
  103. data/lib/capistrano/scm/bzr.rb +0 -70
  104. data/lib/capistrano/scm/cvs.rb +0 -129
  105. data/lib/capistrano/scm/darcs.rb +0 -27
  106. data/lib/capistrano/scm/mercurial.rb +0 -83
  107. data/lib/capistrano/scm/perforce.rb +0 -139
  108. data/lib/capistrano/scm/subversion.rb +0 -128
  109. data/lib/capistrano/transfer.rb +0 -97
  110. data/lib/capistrano/utils.rb +0 -26
  111. data/test/actor_test.rb +0 -402
  112. data/test/scm/cvs_test.rb +0 -196
  113. data/test/scm/subversion_test.rb +0 -145
@@ -1,233 +1,81 @@
1
- $:.unshift File.dirname(__FILE__) + "/../lib"
2
-
3
- require 'test/unit'
1
+ require "#{File.dirname(__FILE__)}/utils"
4
2
  require 'capistrano/configuration'
5
- require 'flexmock'
6
3
 
7
- class ConfigurationTest < Test::Unit::TestCase
8
- class MockActor
9
- attr_reader :tasks
10
-
11
- def initialize(config)
12
- end
13
-
14
- def define_task(*args, &block)
15
- (@tasks ||= []).push [args, block].flatten
16
- end
17
- end
18
-
19
- class MockSCM
20
- attr_reader :configuration
21
-
22
- def initialize(config)
23
- @configuration = config
24
- end
25
- end
4
+ # These tests are only for testing the integration of the various components
5
+ # of the Configuration class. To test specific features, please look at the
6
+ # tests under test/configuration.
26
7
 
8
+ class ConfigurationTest < Test::Unit::TestCase
27
9
  def setup
28
- @config = Capistrano::Configuration.new(MockActor)
29
- @config.set :scm, MockSCM
30
- end
31
-
32
- def test_version_dir_default
33
- assert "releases", @config.version_dir
34
- end
35
-
36
- def test_current_dir_default
37
- assert "current", @config.current_dir
38
- end
39
-
40
- def test_shared_dir_default
41
- assert "shared", @config.shared_dir
42
- end
43
-
44
- def test_set_repository
45
- @config.set :repository, "/foo/bar/baz"
46
- assert_equal "/foo/bar/baz", @config.repository
47
- end
48
-
49
- def test_set_user
50
- @config.set :user, "flippy"
51
- assert_equal "flippy", @config.user
52
- end
53
-
54
- def test_define_single_role
55
- @config.role :app, "somewhere.example.com"
56
- assert_equal 1, @config.roles[:app].length
57
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
58
- assert_equal Hash.new, @config.roles[:app].first.options
59
- end
60
-
61
- def test_define_single_role_with_options
62
- @config.role :app, "somewhere.example.com", :primary => true
63
- assert_equal 1, @config.roles[:app].length
64
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
65
- assert_equal({:primary => true}, @config.roles[:app].first.options)
66
- end
67
-
68
- def test_define_multi_role
69
- @config.role :app, "somewhere.example.com", "else.example.com"
70
- assert_equal 2, @config.roles[:app].length
71
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
72
- assert_equal "else.example.com", @config.roles[:app].last.host
73
- assert_equal({}, @config.roles[:app].first.options)
74
- assert_equal({}, @config.roles[:app].last.options)
75
- end
76
-
77
- def test_define_multi_role_with_options
78
- @config.role :app, "somewhere.example.com", "else.example.com", :primary => true
79
- assert_equal 2, @config.roles[:app].length
80
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
81
- assert_equal "else.example.com", @config.roles[:app].last.host
82
- assert_equal({:primary => true}, @config.roles[:app].first.options)
83
- assert_equal({:primary => true}, @config.roles[:app].last.options)
84
- end
85
-
86
- def test_load_string_unnamed
87
- @config.load :string => "set :repository, __FILE__"
88
- assert_equal "<eval>", @config.repository
89
- end
90
-
91
- def test_load_string_named
92
- @config.load :string => "set :repository, __FILE__", :name => "test.rb"
93
- assert_equal "test.rb", @config.repository
10
+ @config = Capistrano::Configuration.new
94
11
  end
95
12
 
96
- def test_load
97
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
98
- @config.load file
99
- assert_equal "1/2/foo", @config.repository
100
- assert_equal "./#{file}.example.com", @config.gateway
101
- assert_equal 1, @config.roles[:web].length
102
- end
103
-
104
- def test_load_explicit_name
105
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
106
- @config.load file, :name => "config"
107
- assert_equal "1/2/foo", @config.repository
108
- assert_equal "config.example.com", @config.gateway
109
- assert_equal 1, @config.roles[:web].length
110
- end
111
-
112
- def test_load_file_implied_name
113
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
114
- @config.load :file => file
115
- assert_equal "1/2/foo", @config.repository
116
- assert_equal "./#{file}.example.com", @config.gateway
117
- assert_equal 1, @config.roles[:web].length
118
- end
119
-
120
- def test_load_file_explicit_name
121
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
122
- @config.load :file => file, :name => "config"
123
- assert_equal "1/2/foo", @config.repository
124
- assert_equal "config.example.com", @config.gateway
125
- assert_equal 1, @config.roles[:web].length
126
- end
127
-
128
- def test_load_proc_explicit
129
- @config.load :proc => Proc.new { set :gateway, "nifty.zoo.test" }
130
- assert_equal "nifty.zoo.test", @config.gateway
131
- end
132
-
133
- def test_load_proc_implicit
134
- @config.load { set :gateway, "nifty.zoo.test" }
135
- assert_equal "nifty.zoo.test", @config.gateway
136
- end
137
-
138
- def test_task_without_options
139
- block = Proc.new { }
140
- @config.task :hello, &block
141
- assert_equal 1, @config.actor.tasks.length
142
- assert_equal :hello, @config.actor.tasks[0][0]
143
- assert_equal({}, @config.actor.tasks[0][1])
144
- assert_equal block, @config.actor.tasks[0][2]
145
- end
146
-
147
- def test_task_with_options
148
- block = Proc.new { }
149
- @config.task :hello, :roles => :app, &block
150
- assert_equal 1, @config.actor.tasks.length
151
- assert_equal :hello, @config.actor.tasks[0][0]
152
- assert_equal({:roles => :app}, @config.actor.tasks[0][1])
153
- assert_equal block, @config.actor.tasks[0][2]
154
- end
155
-
156
- def test_source
157
- @config.set :repository, "/foo/bar/baz"
158
- assert_equal "/foo/bar/baz", @config.source.configuration.repository
159
- end
13
+ def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
14
+ Capistrano::SSH.expects(:connect).with { |s,c| s.host == "www.capistrano.test" && c == @config }.returns(:session)
15
+ Capistrano::Command.expects(:process).with("echo 'hello world'", [:session], :logger => @config.logger)
160
16
 
161
- def test_releases_path_default
162
- @config.set :deploy_to, "/start/of/path"
163
- assert_equal "/start/of/path/releases", @config.releases_path
164
- end
165
-
166
- def test_releases_path_custom
167
- @config.set :deploy_to, "/start/of/path"
168
- @config.set :version_dir, "right/here"
169
- assert_equal "/start/of/path/right/here", @config.releases_path
170
- end
171
-
172
- def test_current_path_default
173
- @config.set :deploy_to, "/start/of/path"
174
- assert_equal "/start/of/path/current", @config.current_path
175
- end
176
-
177
- def test_current_path_custom
178
- @config.set :deploy_to, "/start/of/path"
179
- @config.set :current_dir, "right/here"
180
- assert_equal "/start/of/path/right/here", @config.current_path
181
- end
182
-
183
- def test_shared_path_default
184
- @config.set :deploy_to, "/start/of/path"
185
- assert_equal "/start/of/path/shared", @config.shared_path
186
- end
17
+ @config.load do
18
+ role :test, "www.capistrano.test"
19
+ set :message, "hello world"
20
+ namespace :testing do
21
+ task :example, :roles => :test do
22
+ run "echo '#{message}'"
23
+ end
24
+ end
25
+ end
187
26
 
188
- def test_shared_path_custom
189
- @config.set :deploy_to, "/start/of/path"
190
- @config.set :shared_dir, "right/here"
191
- assert_equal "/start/of/path/right/here", @config.shared_path
27
+ @config.testing.example
192
28
  end
193
29
 
194
- def test_release_path_implicit
195
- @config.set :deploy_to, "/start/of/path"
196
- assert_equal "/start/of/path/releases/#{@config.now.strftime("%Y%m%d%H%M%S")}", @config.release_path
197
- end
30
+ def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_same_namespace
31
+ @config.namespace(:outer) do
32
+ task(:first) { set :called_first, true }
33
+ namespace(:inner) do
34
+ task(:first) { set :called_inner_first, true }
35
+ task(:second) { first }
36
+ end
37
+ end
198
38
 
199
- def test_release_path_explicit
200
- @config.set :deploy_to, "/start/of/path"
201
- assert_equal "/start/of/path/releases/silly", @config.release_path("silly")
39
+ @config.outer.inner.second
40
+ assert !@config[:called_first]
41
+ assert @config[:called_inner_first]
202
42
  end
203
43
 
204
- def test_task_description
205
- block = Proc.new { }
206
- @config.desc "A sample task"
207
- @config.task :hello, &block
208
- assert_equal "A sample task", @config.actor.tasks[0][1][:desc]
209
- end
44
+ def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_parent_namespace
45
+ @config.namespace(:outer) do
46
+ task(:first) { set :called_first, true }
47
+ namespace(:inner) do
48
+ task(:second) { first }
49
+ end
50
+ end
210
51
 
211
- def test_set_scm_to_darcs
212
- @config.set :scm, :darcs
213
- assert_equal "Capistrano::SCM::Darcs", @config.source.class.name
52
+ @config.outer.inner.second
53
+ assert @config[:called_first]
214
54
  end
215
55
 
216
- def test_set_scm_to_subversion
217
- @config.set :scm, :subversion
218
- assert_equal "Capistrano::SCM::Subversion", @config.source.class.name
219
- end
56
+ def test_tasks_in_nested_namespace_should_be_able_to_call_shadowed_tasks_in_parent_namespace
57
+ @config.namespace(:outer) do
58
+ task(:first) { set :called_first, true }
59
+ namespace(:inner) do
60
+ task(:first) { set :called_inner_first, true }
61
+ task(:second) { parent.first }
62
+ end
63
+ end
220
64
 
221
- def test_get_proc_variable_sets_original_value_hash
222
- @config.set(:proc) { "foo" }
223
- assert_nil @config[:original_value][:proc]
224
- assert_equal "foo", @config[:proc]
225
- assert_not_nil @config[:original_value][:proc]
226
- assert @config[:original_value][:proc].respond_to?(:call)
65
+ @config.outer.inner.second
66
+ assert @config[:called_first]
67
+ assert !@config[:called_inner_first]
227
68
  end
228
69
 
229
- def test_require
230
- @config.require "#{File.dirname(__FILE__)}/fixtures/custom"
231
- assert_equal "foo", @config.gateway
70
+ def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
71
+ @config.namespace(:outer) do
72
+ task(:default) { set :called_default, true }
73
+ task(:before_outer) { set :called_before_outer, true }
74
+ task(:after_outer) { set :called_after_outer, true }
75
+ end
76
+ @config.outer.default
77
+ assert @config[:called_before_outer]
78
+ assert @config[:called_default]
79
+ assert @config[:called_after_outer]
232
80
  end
233
81
  end
@@ -0,0 +1,55 @@
1
+ require "#{File.dirname(__FILE__)}/../../utils"
2
+ require 'capistrano/recipes/deploy/scm/base'
3
+
4
+ class DeploySCMBaseTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Base
6
+ default_command "floopy"
7
+ end
8
+
9
+ def setup
10
+ @config = { }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_command_should_default_to_default_command
17
+ assert_equal "floopy", @source.command
18
+ @source.local { assert_equal "floopy", @source.command }
19
+ end
20
+
21
+ def test_command_should_use_scm_command_if_available
22
+ @config[:scm_command] = "/opt/local/bin/floopy"
23
+ assert_equal "/opt/local/bin/floopy", @source.command
24
+ end
25
+
26
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
27
+ @config[:scm_command] = "/opt/local/bin/floopy"
28
+ @source.local { assert_equal "/opt/local/bin/floopy", @source.command }
29
+ end
30
+
31
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
32
+ @config[:scm_command] = "/opt/local/bin/floopy"
33
+ @config[:local_scm_command] = "/usr/local/bin/floopy"
34
+ assert_equal "/opt/local/bin/floopy", @source.command
35
+ @source.local { assert_equal "/usr/local/bin/floopy", @source.command }
36
+ end
37
+
38
+ def test_command_should_use_default_if_scm_command_is_default
39
+ @config[:scm_command] = :default
40
+ assert_equal "floopy", @source.command
41
+ end
42
+
43
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
44
+ @config[:scm_command] = "/foo/bar/floopy"
45
+ @config[:local_scm_command] = :default
46
+ @source.local { assert_equal "floopy", @source.command }
47
+ end
48
+
49
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
50
+ @config[:scm_command] = "/foo/bar/floopy"
51
+ @config[:local_scm_command] = :default
52
+ assert_equal "floopy", @source.local.command
53
+ assert_equal "/foo/bar/floopy", @source.command
54
+ end
55
+ end
@@ -0,0 +1,146 @@
1
+ require "#{File.dirname(__FILE__)}/../../utils"
2
+ require 'capistrano/logger'
3
+ require 'capistrano/recipes/deploy/strategy/copy'
4
+
5
+ class DeployStrategyCopyTest < Test::Unit::TestCase
6
+ def setup
7
+ @config = { :logger => Capistrano::Logger.new(:output => StringIO.new),
8
+ :releases_path => "/u/apps/test/releases",
9
+ :release_path => "/u/apps/test/releases/1234567890",
10
+ :real_revision => "154" }
11
+ @source = mock("source")
12
+ @config.stubs(:source).returns(@source)
13
+ @strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
14
+ end
15
+
16
+ def test_deploy_with_defaults_should_use_tar_gz_and_checkout
17
+ Dir.expects(:tmpdir).returns("/temp/dir")
18
+ Dir.expects(:chdir).with("/temp/dir").yields
19
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
20
+
21
+ @strategy.expects(:system).with(:local_checkout)
22
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
23
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
24
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
25
+
26
+ mock_file = mock("file")
27
+ mock_file.expects(:puts).with("154")
28
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
29
+ File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
30
+
31
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
32
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
33
+
34
+ @strategy.deploy!
35
+ end
36
+
37
+ def test_deploy_with_export_should_use_tar_gz_and_export
38
+ Dir.expects(:tmpdir).returns("/temp/dir")
39
+ Dir.expects(:chdir).with("/temp/dir").yields
40
+ @config[:copy_strategy] = :export
41
+ @source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
42
+
43
+ @strategy.expects(:system).with(:local_export)
44
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
45
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
46
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
47
+
48
+ mock_file = mock("file")
49
+ mock_file.expects(:puts).with("154")
50
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
51
+ File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
52
+
53
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
54
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
55
+
56
+ @strategy.deploy!
57
+ end
58
+
59
+ def test_deploy_with_zip_should_use_zip_and_checkout
60
+ Dir.expects(:tmpdir).returns("/temp/dir")
61
+ Dir.expects(:chdir).with("/temp/dir").yields
62
+ @config[:copy_compression] = :zip
63
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
64
+
65
+ @strategy.expects(:system).with(:local_checkout)
66
+ @strategy.expects(:system).with("zip -qr 1234567890.zip 1234567890")
67
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.zip")
68
+ @strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
69
+
70
+ mock_file = mock("file")
71
+ mock_file.expects(:puts).with("154")
72
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
73
+ File.expects(:read).with("/temp/dir/1234567890.zip").returns(:mock_file_contents)
74
+
75
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
76
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
77
+
78
+ @strategy.deploy!
79
+ end
80
+
81
+ def test_deploy_with_bzip2_should_use_zip_and_checkout
82
+ Dir.expects(:tmpdir).returns("/temp/dir")
83
+ Dir.expects(:chdir).with("/temp/dir").yields
84
+ @config[:copy_compression] = :bzip2
85
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
86
+
87
+ @strategy.expects(:system).with(:local_checkout)
88
+ @strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
89
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.bz2")
90
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
91
+
92
+ mock_file = mock("file")
93
+ mock_file.expects(:puts).with("154")
94
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
95
+ File.expects(:read).with("/temp/dir/1234567890.tar.bz2").returns(:mock_file_contents)
96
+
97
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
98
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
99
+
100
+ @strategy.deploy!
101
+ end
102
+
103
+ def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
104
+ Dir.expects(:tmpdir).never
105
+ Dir.expects(:chdir).with("/other/path").yields
106
+ @config[:copy_dir] = "/other/path"
107
+ @source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)
108
+
109
+ @strategy.expects(:system).with(:local_checkout)
110
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
111
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
112
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
113
+
114
+ mock_file = mock("file")
115
+ mock_file.expects(:puts).with("154")
116
+ File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
117
+ File.expects(:read).with("/other/path/1234567890.tar.gz").returns(:mock_file_contents)
118
+
119
+ FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
120
+ FileUtils.expects(:rm_rf).with("/other/path/1234567890")
121
+
122
+ @strategy.deploy!
123
+ end
124
+
125
+ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
126
+ @config[:copy_remote_dir] = "/somewhere/else"
127
+ Dir.expects(:tmpdir).returns("/temp/dir")
128
+ Dir.expects(:chdir).yields
129
+ @source.expects(:checkout).returns(:local_checkout)
130
+
131
+ @strategy.expects(:system).with(:local_checkout)
132
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
133
+ @strategy.expects(:put).with(:mock_file_contents, "/somewhere/else/1234567890.tar.gz")
134
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
135
+
136
+ mock_file = mock("file")
137
+ mock_file.expects(:puts).with("154")
138
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
139
+ File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
140
+
141
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
142
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
143
+
144
+ @strategy.deploy!
145
+ end
146
+ end