dump 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +13 -0
- data/.gitignore +12 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +250 -0
- data/dump.gemspec +22 -0
- data/lib/dump.rb +3 -0
- data/lib/dump/capistrano.rb +1 -0
- data/lib/dump/railtie.rb +8 -0
- data/lib/dump_rake.rb +85 -0
- data/lib/dump_rake/archive_tar_minitar_fix.rb +8 -0
- data/lib/dump_rake/assets.rb +22 -0
- data/lib/dump_rake/continious_timeout.rb +38 -0
- data/lib/dump_rake/dump.rb +175 -0
- data/lib/dump_rake/dump_reader.rb +289 -0
- data/lib/dump_rake/dump_writer.rb +119 -0
- data/lib/dump_rake/env.rb +139 -0
- data/lib/dump_rake/env/filter.rb +26 -0
- data/lib/dump_rake/rails_root.rb +12 -0
- data/lib/dump_rake/table_manipulation.rb +131 -0
- data/lib/generators/assets_config/assets_config_generator.rb +16 -0
- data/lib/generators/assets_config/templates/assets +8 -0
- data/lib/tasks/assets.rake +17 -0
- data/lib/tasks/dump.rake +27 -0
- data/recipes/dump.rb +343 -0
- data/script/update_readme +21 -0
- data/spec/.gitignore +1 -0
- data/spec/.tmignore +1 -0
- data/spec/cycle_spec.rb +229 -0
- data/spec/db/database.example.yml +19 -0
- data/spec/db/schema.rb +7 -0
- data/spec/dummy-3.1.3/.gitignore +15 -0
- data/spec/dummy-3.1.3/.rspec +1 -0
- data/spec/dummy-3.1.3/Gemfile +23 -0
- data/spec/dummy-3.1.3/Gemfile.lock +159 -0
- data/spec/dummy-3.1.3/README +261 -0
- data/spec/dummy-3.1.3/Rakefile +7 -0
- data/spec/dummy-3.1.3/app/assets/images/rails.png +0 -0
- data/spec/dummy-3.1.3/app/assets/javascripts/application.js +9 -0
- data/spec/dummy-3.1.3/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy-3.1.3/app/controllers/application_controller.rb +3 -0
- data/spec/dummy-3.1.3/app/helpers/application_helper.rb +2 -0
- data/spec/dummy-3.1.3/app/mailers/.gitkeep +0 -0
- data/spec/dummy-3.1.3/app/models/.gitkeep +0 -0
- data/spec/dummy-3.1.3/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy-3.1.3/config.ru +4 -0
- data/spec/dummy-3.1.3/config/application.rb +54 -0
- data/spec/dummy-3.1.3/config/boot.rb +6 -0
- data/spec/dummy-3.1.3/config/database.yml +25 -0
- data/spec/dummy-3.1.3/config/environment.rb +5 -0
- data/spec/dummy-3.1.3/config/environments/development.rb +30 -0
- data/spec/dummy-3.1.3/config/environments/production.rb +60 -0
- data/spec/dummy-3.1.3/config/environments/test.rb +39 -0
- data/spec/dummy-3.1.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy-3.1.3/config/initializers/inflections.rb +10 -0
- data/spec/dummy-3.1.3/config/initializers/mime_types.rb +5 -0
- data/spec/dummy-3.1.3/config/initializers/secret_token.rb +7 -0
- data/spec/dummy-3.1.3/config/initializers/session_store.rb +8 -0
- data/spec/dummy-3.1.3/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy-3.1.3/config/locales/en.yml +5 -0
- data/spec/dummy-3.1.3/config/routes.rb +58 -0
- data/spec/dummy-3.1.3/db/seeds.rb +7 -0
- data/spec/dummy-3.1.3/doc/README_FOR_APP +2 -0
- data/spec/dummy-3.1.3/lib/assets/.gitkeep +0 -0
- data/spec/dummy-3.1.3/lib/tasks/.gitkeep +0 -0
- data/spec/dummy-3.1.3/log/.gitkeep +0 -0
- data/spec/dummy-3.1.3/public/404.html +26 -0
- data/spec/dummy-3.1.3/public/422.html +26 -0
- data/spec/dummy-3.1.3/public/500.html +26 -0
- data/spec/dummy-3.1.3/public/favicon.ico +0 -0
- data/spec/dummy-3.1.3/public/index.html +241 -0
- data/spec/dummy-3.1.3/public/robots.txt +5 -0
- data/spec/dummy-3.1.3/script/rails +6 -0
- data/spec/dummy-3.1.3/spec/spec_helper.rb +32 -0
- data/spec/dummy-3.1.3/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy-3.1.3/vendor/plugins/.gitkeep +0 -0
- data/spec/lib/dump_rake/dump_reader_spec.rb +638 -0
- data/spec/lib/dump_rake/dump_spec.rb +291 -0
- data/spec/lib/dump_rake/dump_writer_spec.rb +328 -0
- data/spec/lib/dump_rake/env/filter_spec.rb +56 -0
- data/spec/lib/dump_rake/env_spec.rb +139 -0
- data/spec/lib/dump_rake/rails_root_spec.rb +45 -0
- data/spec/lib/dump_rake/table_manipulation_spec.rb +256 -0
- data/spec/lib/dump_rake_spec.rb +326 -0
- data/spec/recipes/dump_spec.rb +553 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/tasks/assets_spec.rb +92 -0
- data/spec/tasks/dump_spec.rb +107 -0
- metadata +272 -0
@@ -0,0 +1,326 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe DumpRake do
|
4
|
+
describe "versions" do
|
5
|
+
it "should call Dump.list if called without version" do
|
6
|
+
DumpRake::Dump.should_receive(:list).and_return([])
|
7
|
+
DumpRake.versions
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should call Dump.list with options if called with version" do
|
11
|
+
DumpRake::Dump.should_receive(:list).with(:like => '123').and_return([])
|
12
|
+
DumpRake.versions(:like => '123')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should print versions" do
|
16
|
+
DumpRake::Dump.should_receive(:list).and_return(%w[123.tgz 456.tgz])
|
17
|
+
grab_output{
|
18
|
+
DumpRake.versions
|
19
|
+
}[:stdout].should == "123.tgz\n456.tgz\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not show summary if not asked for" do
|
23
|
+
dumps = %w[123.tgz 456.tgz].map do |s|
|
24
|
+
dump = mock("dump_#{s}", :path => mock("dump_#{s}_path"))
|
25
|
+
DumpRake::DumpReader.should_not_receive(:summary)
|
26
|
+
dump
|
27
|
+
end
|
28
|
+
|
29
|
+
DumpRake::Dump.should_receive(:list).and_return(dumps)
|
30
|
+
grab_output{
|
31
|
+
$stderr.should_not_receive(:puts)
|
32
|
+
DumpRake.versions
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should show summary if asked for" do
|
37
|
+
dumps = %w[123.tgz 456.tgz].map do |s|
|
38
|
+
dump = mock("dump_#{s}", :path => mock("dump_#{s}_path"))
|
39
|
+
DumpRake::DumpReader.should_receive(:summary).with(dump.path)
|
40
|
+
dump
|
41
|
+
end
|
42
|
+
|
43
|
+
DumpRake::Dump.should_receive(:list).and_return(dumps)
|
44
|
+
grab_output{
|
45
|
+
$stderr.should_not_receive(:puts)
|
46
|
+
DumpRake.versions(:summary => '1')
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should show summary with scmema if asked for" do
|
51
|
+
dumps = %w[123.tgz 456.tgz].map do |s|
|
52
|
+
dump = mock("dump_#{s}", :path => mock("dump_#{s}_path"))
|
53
|
+
DumpRake::DumpReader.should_receive(:summary).with(dump.path, :schema => true)
|
54
|
+
dump
|
55
|
+
end
|
56
|
+
|
57
|
+
DumpRake::Dump.should_receive(:list).and_return(dumps)
|
58
|
+
grab_output{
|
59
|
+
$stderr.should_not_receive(:puts)
|
60
|
+
DumpRake.versions(:summary => '2')
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should show output to stderr if summary raises error" do
|
65
|
+
DumpRake::DumpReader.stub!(:summary)
|
66
|
+
dumps = %w[123.tgz 456.tgz].map do |s|
|
67
|
+
mock("dump_#{s}", :path => mock("dump_#{s}_path"))
|
68
|
+
end
|
69
|
+
DumpRake::DumpReader.should_receive(:summary).with(dumps[1].path).and_raise('terrible error')
|
70
|
+
|
71
|
+
DumpRake::Dump.should_receive(:list).and_return(dumps)
|
72
|
+
grab_output{
|
73
|
+
$stderr.stub!(:puts)
|
74
|
+
$stderr.should_receive(:puts) do |s|
|
75
|
+
s['terrible error'].should_not be_nil
|
76
|
+
end
|
77
|
+
DumpRake.versions(:summary => 'true')
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "create" do
|
83
|
+
describe "naming" do
|
84
|
+
it "should create file in 'rails app root'/dump" do
|
85
|
+
File.stub!(:rename)
|
86
|
+
DumpRake::DumpWriter.should_receive(:create) do |path|
|
87
|
+
File.dirname(path).should == File.join(DumpRake::RailsRoot, 'dump')
|
88
|
+
end
|
89
|
+
grab_output{
|
90
|
+
DumpRake.create
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should create file with name like 'yyyymmddhhmmss.tmp' when called without description" do
|
95
|
+
File.stub!(:rename)
|
96
|
+
DumpRake::DumpWriter.should_receive(:create) do |path|
|
97
|
+
File.basename(path).should match(/^\d{14}\.tmp$/)
|
98
|
+
end
|
99
|
+
grab_output{
|
100
|
+
DumpRake.create
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should create file with name like 'yyyymmddhhmmss-Some text and _.tmp' when called with description 'Some text and !@'" do
|
105
|
+
File.stub!(:rename)
|
106
|
+
DumpRake::DumpWriter.should_receive(:create) do |path|
|
107
|
+
File.basename(path).should match(/^\d{14}-Some text and _\.tmp$/)
|
108
|
+
end
|
109
|
+
grab_output{
|
110
|
+
DumpRake.create(:desc => 'Some text and !@')
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should create file with name like 'yyyymmddhhmmss@super tag,second.tmp' when called with description 'Some text and !@'" do
|
115
|
+
File.stub!(:rename)
|
116
|
+
DumpRake::DumpWriter.should_receive(:create) do |path|
|
117
|
+
File.basename(path).should match(/^\d{14}-Some text and _\.tmp$/)
|
118
|
+
end
|
119
|
+
grab_output{
|
120
|
+
DumpRake.create(:desc => 'Some text and !@')
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should rename file after creating" do
|
125
|
+
File.should_receive(:rename) do |tmp_path, tgz_path|
|
126
|
+
File.basename(tmp_path).should match(/^\d{14}-Some text and _\.tmp$/)
|
127
|
+
File.basename(tgz_path).should match(/^\d{14}-Some text and _\.tgz$/)
|
128
|
+
end
|
129
|
+
DumpRake::DumpWriter.stub!(:create)
|
130
|
+
grab_output{
|
131
|
+
DumpRake.create(:desc => 'Some text and !@')
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should output file name" do
|
136
|
+
File.stub!(:rename)
|
137
|
+
DumpRake::DumpWriter.stub!(:create)
|
138
|
+
grab_output{
|
139
|
+
DumpRake.create(:desc => 'Some text and !@')
|
140
|
+
}[:stdout].should match(/^\d{14}-Some text and _\.tgz$/)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "writing" do
|
145
|
+
it "should dump schema, tables, assets" do
|
146
|
+
File.stub!(:rename)
|
147
|
+
@dump = mock('dump')
|
148
|
+
DumpRake::DumpWriter.should_receive(:create)
|
149
|
+
|
150
|
+
grab_output{
|
151
|
+
DumpRake.create
|
152
|
+
}
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "restore" do
|
158
|
+
describe "without version" do
|
159
|
+
it "should call Dump.list" do
|
160
|
+
DumpRake::Dump.stub!(:list)
|
161
|
+
DumpRake::Dump.should_receive(:list).and_return([])
|
162
|
+
grab_output{
|
163
|
+
DumpRake.restore
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should not call DumpReader.restore and should call Dump.list and output it to $stderr if there are no versions at all" do
|
168
|
+
DumpRake::Dump.stub!(:list).and_return([])
|
169
|
+
DumpRake::DumpReader.should_not_receive(:restore)
|
170
|
+
all_dumps = mock('all_dumps')
|
171
|
+
DumpRake::Dump.should_receive(:list).with().and_return(all_dumps)
|
172
|
+
grab_output{
|
173
|
+
$stderr.should_receive(:puts).with(kind_of(String))
|
174
|
+
$stderr.should_receive(:puts).with(all_dumps)
|
175
|
+
DumpRake.restore
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should not call DumpReader.restore and should call Dump.list and output it to $stderr if there are no versions at all" do
|
180
|
+
DumpRake::Dump.stub!(:list).and_return([])
|
181
|
+
DumpRake::DumpReader.should_not_receive(:restore)
|
182
|
+
all_dumps = mock('all_dumps')
|
183
|
+
DumpRake::Dump.should_receive(:list).with().and_return(all_dumps)
|
184
|
+
grab_output{
|
185
|
+
$stderr.should_receive(:puts).with(kind_of(String))
|
186
|
+
$stderr.should_receive(:puts).with(all_dumps)
|
187
|
+
DumpRake.restore('213')
|
188
|
+
}
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should call DumpReader.restore if there are versions" do
|
192
|
+
@dump = mock('dump', :path => 'dump/213.tgz')
|
193
|
+
DumpRake::Dump.should_receive(:list).once.and_return([@dump])
|
194
|
+
DumpRake::DumpReader.should_receive(:restore).with('dump/213.tgz')
|
195
|
+
grab_output{
|
196
|
+
$stderr.should_not_receive(:puts)
|
197
|
+
DumpRake.restore
|
198
|
+
}
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "with version" do
|
203
|
+
it "should call Dump.list with options" do
|
204
|
+
DumpRake::Dump.stub!(:list)
|
205
|
+
DumpRake::Dump.should_receive(:list).with(:like => '213').and_return([])
|
206
|
+
grab_output{
|
207
|
+
DumpRake.restore(:like => '213')
|
208
|
+
}
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should not call DumpReader.restore and should call versions if desired version not found" do
|
212
|
+
DumpRake::Dump.stub!(:list).and_return([])
|
213
|
+
DumpRake::DumpReader.should_not_receive(:restore)
|
214
|
+
all_dumps = mock('all_dumps')
|
215
|
+
DumpRake::Dump.should_receive(:list).with().and_return(all_dumps)
|
216
|
+
grab_output{
|
217
|
+
$stderr.should_receive(:puts).with(kind_of(String))
|
218
|
+
$stderr.should_receive(:puts).with(all_dumps)
|
219
|
+
DumpRake.restore('213')
|
220
|
+
}
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should call DumpReader.restore if there is desired version" do
|
224
|
+
@dump = mock('dump', :path => 'dump/213.tgz')
|
225
|
+
DumpRake::Dump.should_receive(:list).once.and_return([@dump])
|
226
|
+
DumpRake::DumpReader.should_receive(:restore).with('dump/213.tgz')
|
227
|
+
DumpRake.should_not_receive(:versions)
|
228
|
+
grab_output{
|
229
|
+
$stderr.should_not_receive(:puts)
|
230
|
+
DumpRake.restore(:like => '213')
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should call DumpReader.restore on last version if found multiple matching versions" do
|
235
|
+
@dump_a = mock('dump_a', :path => 'dump/213-a.tgz')
|
236
|
+
@dump_b = mock('dump_b', :path => 'dump/213-b.tgz')
|
237
|
+
DumpRake::Dump.should_receive(:list).once.and_return([@dump_a, @dump_b])
|
238
|
+
DumpRake::DumpReader.should_receive(:restore).with('dump/213-b.tgz')
|
239
|
+
grab_output{
|
240
|
+
$stderr.should_not_receive(:puts)
|
241
|
+
DumpRake.restore(:like => '213')
|
242
|
+
}
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe "cleanup" do
|
248
|
+
it "should call ask for all files in dump dir and for dumps" do
|
249
|
+
DumpRake::Dump.should_receive(:list).with(:all => true).and_return([])
|
250
|
+
DumpRake::Dump.should_receive(:list).with({}).and_return([])
|
251
|
+
DumpRake.cleanup
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should call Dump.list with options if called with version and tags" do
|
255
|
+
DumpRake::Dump.should_receive(:list).with(:like => '123', :tags => 'a,b,c', :all => true).and_return([])
|
256
|
+
DumpRake::Dump.should_receive(:list).with(:like => '123', :tags => 'a,b,c').and_return([])
|
257
|
+
DumpRake.cleanup(:like => '123', :tags => 'a,b,c')
|
258
|
+
end
|
259
|
+
|
260
|
+
{
|
261
|
+
{} => [0..4],
|
262
|
+
{:leave => '3'} => [0..6],
|
263
|
+
{:leave => '5'} => [0..4],
|
264
|
+
{:leave => '9'} => [0],
|
265
|
+
{:leave => '10'} => [],
|
266
|
+
{:leave => '15'} => [],
|
267
|
+
{:leave => 'none'} => [0..9],
|
268
|
+
}.each do |options, ids|
|
269
|
+
it "should call delete #{ids} dumps when called with #{options}" do
|
270
|
+
dumps = %w[a b c d e f g h i j].map do |s|
|
271
|
+
mock("dump_#{s}", :ext => 'tgz', :path => mock("dump_#{s}_path"))
|
272
|
+
end
|
273
|
+
tmp_dumps = %w[a b c].map do |s|
|
274
|
+
mock("tmp_dump_#{s}", :ext => 'tmp', :path => mock("tmp_dump_#{s}_path"))
|
275
|
+
end
|
276
|
+
all_dumps = tmp_dumps[0, 1] + dumps[0, 5] + tmp_dumps[1, 1] + dumps[5, 5] + tmp_dumps[2, 1]
|
277
|
+
|
278
|
+
(dumps.values_at(*ids) + [tmp_dumps[0], tmp_dumps[2]]).each do |dump|
|
279
|
+
dump.should_receive(:lock).and_yield
|
280
|
+
dump.path.should_receive(:unlink)
|
281
|
+
end
|
282
|
+
[tmp_dumps[1]].each do |dump|
|
283
|
+
dump.should_receive(:lock)
|
284
|
+
dump.path.should_not_receive(:unlink)
|
285
|
+
end
|
286
|
+
(dumps - dumps.values_at(*ids)).each do |dump|
|
287
|
+
dump.should_not_receive(:lock)
|
288
|
+
dump.path.should_not_receive(:unlink)
|
289
|
+
end
|
290
|
+
|
291
|
+
DumpRake::Dump.should_receive(:list).with(hash_including(:all => true)).and_return(all_dumps)
|
292
|
+
DumpRake::Dump.should_receive(:list).with(hash_not_including(:all => true)).and_return(dumps)
|
293
|
+
grab_output{
|
294
|
+
DumpRake.cleanup({:like => '123', :tags => 'a,b,c'}.merge(options))
|
295
|
+
}
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should print to stderr if can not delete dump" do
|
300
|
+
dumps = %w[a b c d e f g h i j].map do |s|
|
301
|
+
dump = mock("dump_#{s}", :ext => 'tgz', :path => mock("dump_#{s}_path"))
|
302
|
+
dump.stub!(:lock).and_yield
|
303
|
+
dump.path.stub!(:unlink)
|
304
|
+
dump
|
305
|
+
end
|
306
|
+
|
307
|
+
dumps[3].path.should_receive(:unlink).and_raise('Horrible error')
|
308
|
+
|
309
|
+
DumpRake::Dump.stub!(:list).and_return(dumps)
|
310
|
+
grab_output{
|
311
|
+
$stderr.stub!(:puts)
|
312
|
+
$stderr.should_receive(:puts) do |s|
|
313
|
+
s[dumps[3].path.to_s].should_not be_nil
|
314
|
+
s['Horrible error'].should_not be_nil
|
315
|
+
end
|
316
|
+
DumpRake.cleanup
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should raise if called with :leave which is not a number or 'none'" do
|
321
|
+
proc{
|
322
|
+
DumpRake.cleanup(:leave => 'nothing')
|
323
|
+
}.should raise_error
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
@@ -0,0 +1,553 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
describe "cap dump" do
|
5
|
+
before do
|
6
|
+
@cap = Capistrano::Configuration.new
|
7
|
+
Capistrano::Configuration.instance = @cap
|
8
|
+
@cap.load File.dirname(__FILE__) + '/../../recipes/dump.rb'
|
9
|
+
@remote_path = "/home/test/apps/dummy"
|
10
|
+
@cap.set(:current_path, @remote_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all_dictionary_variables
|
14
|
+
DumpRake::Env::DICTIONARY.each_with_object({}) do |(key, value), filled_env|
|
15
|
+
filled_env[key] = value.join(' ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.test_passing_environment_variables(place, command, command_strings, options = {})
|
20
|
+
DumpRake::Env.variable_names_for_command(command).each do |variable|
|
21
|
+
command_string = command_strings[variable]
|
22
|
+
DumpRake::Env::DICTIONARY[variable].each do |name|
|
23
|
+
it "should pass #{variable} if it is set through environment variable #{name}" do
|
24
|
+
violated "command_string not specified" unless command_string
|
25
|
+
full_command_string = command_string
|
26
|
+
full_command_string = "cd #{@remote_path}; #{command_string}" if place == :remote
|
27
|
+
@cap.dump.should_receive(:"run_#{place}").with(full_command_string).and_return(options[:return_value] || '')
|
28
|
+
DumpRake::Env.with_env name => options[:value] || 'some data' do
|
29
|
+
cap_task = options[:cap_task] || "dump:#{place}:#{command}"
|
30
|
+
grab_output{ @cap.find_and_execute_task(cap_task) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "do_transfer" do
|
38
|
+
before do
|
39
|
+
@cap.dump.stub!(:do_transfer_via)
|
40
|
+
end
|
41
|
+
|
42
|
+
[:up, :down].each do |direction|
|
43
|
+
describe direction do
|
44
|
+
describe "if method not set" do
|
45
|
+
|
46
|
+
it "should call got_rsync?" do
|
47
|
+
@cap.dump.should_receive(:got_rsync?)
|
48
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "if got_rsync?" do
|
52
|
+
it "should use rsync" do
|
53
|
+
@cap.dump.stub!(:got_rsync?).and_return(true)
|
54
|
+
@cap.dump.should_receive(:do_transfer_via).with(:rsync, direction, 'a.tgz', 'b.tgz')
|
55
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise if rsync fails" do
|
59
|
+
@cap.dump.stub!(:got_rsync?).and_return(true)
|
60
|
+
@cap.dump.should_receive(:do_transfer_via).with(:rsync, direction, 'a.tgz', 'b.tgz').and_raise('problem using rsync')
|
61
|
+
proc{
|
62
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
63
|
+
}.should raise_error('problem using rsync')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "unless got_rsync?" do
|
68
|
+
it "should try sftp" do
|
69
|
+
@cap.dump.stub!(:got_rsync?).and_return(false)
|
70
|
+
@cap.dump.should_receive(:do_transfer_via).with(:sftp, direction, 'a.tgz', 'b.tgz')
|
71
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should try scp after sftp" do
|
75
|
+
@cap.dump.stub!(:got_rsync?).and_return(false)
|
76
|
+
@cap.dump.should_receive(:do_transfer_via).with(:sftp, direction, 'a.tgz', 'b.tgz').and_raise('problem using sftp')
|
77
|
+
@cap.dump.should_receive(:do_transfer_via).with(:scp, direction, 'a.tgz', 'b.tgz')
|
78
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not rescue if scp also fails" do
|
82
|
+
@cap.dump.stub!(:got_rsync?).and_return(false)
|
83
|
+
@cap.dump.should_receive(:do_transfer_via).with(:sftp, direction, 'a.tgz', 'b.tgz').and_raise('problem using sftp')
|
84
|
+
@cap.dump.should_receive(:do_transfer_via).with(:scp, direction, 'a.tgz', 'b.tgz').and_raise('problem using scp')
|
85
|
+
proc{
|
86
|
+
grab_output{ @cap.dump.do_transfer(direction, 'a.tgz', 'b.tgz') }
|
87
|
+
}.should raise_error('problem using scp')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "local" do
|
96
|
+
describe "versions" do
|
97
|
+
it "should call local rake task" do
|
98
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:versions SHOW_SIZE\\=true").and_return('')
|
99
|
+
@cap.find_and_execute_task("dump:local:versions")
|
100
|
+
end
|
101
|
+
|
102
|
+
test_passing_environment_variables(:local, :versions, {
|
103
|
+
:like => "rake -s dump:versions LIKE\\=some\\ data SHOW_SIZE\\=true",
|
104
|
+
:tags => "rake -s dump:versions SHOW_SIZE\\=true TAGS\\=some\\ data",
|
105
|
+
:summary => "rake -s dump:versions SHOW_SIZE\\=true SUMMARY\\=some\\ data",
|
106
|
+
})
|
107
|
+
|
108
|
+
it "should print result of rake task" do
|
109
|
+
@cap.dump.stub!(:run_local).and_return(" 123M\t123123.tgz\n")
|
110
|
+
grab_output{
|
111
|
+
@cap.find_and_execute_task("dump:local:versions")
|
112
|
+
}[:stdout].should == " 123M\t123123.tgz\n"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "cleanup" do
|
117
|
+
it "should call local rake task" do
|
118
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:cleanup").and_return('')
|
119
|
+
@cap.find_and_execute_task("dump:local:cleanup")
|
120
|
+
end
|
121
|
+
|
122
|
+
test_passing_environment_variables(:local, :cleanup, {
|
123
|
+
:like => "rake -s dump:cleanup LIKE\\=some\\ data",
|
124
|
+
:tags => "rake -s dump:cleanup TAGS\\=some\\ data",
|
125
|
+
:leave => "rake -s dump:cleanup LEAVE\\=some\\ data",
|
126
|
+
})
|
127
|
+
|
128
|
+
it "should print result of rake task" do
|
129
|
+
@cap.dump.stub!(:run_local).and_return("123123.tgz\n")
|
130
|
+
grab_output{
|
131
|
+
@cap.find_and_execute_task("dump:local:cleanup")
|
132
|
+
}[:stdout].should == "123123.tgz\n"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "create" do
|
137
|
+
it "should raise if dump creation fails" do
|
138
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:create TAGS\\=local").and_return('')
|
139
|
+
proc{
|
140
|
+
@cap.find_and_execute_task("dump:local:create")
|
141
|
+
}.should raise_error('Failed creating dump')
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should call local rake task with tag local" do
|
145
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:create TAGS\\=local").and_return('123.tgz')
|
146
|
+
grab_output{
|
147
|
+
@cap.find_and_execute_task("dump:local:create")
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should call local rake task with additional tag local" do
|
152
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:create TAGS\\=local,photos").and_return('123.tgz')
|
153
|
+
grab_output{
|
154
|
+
DumpRake::Env.with_env :tags => 'photos' do
|
155
|
+
@cap.find_and_execute_task("dump:local:create")
|
156
|
+
end
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
test_passing_environment_variables(:local, :create, {
|
161
|
+
:desc => "rake -s dump:create DESC\\=some\\ data TAGS\\=local",
|
162
|
+
:tags => "rake -s dump:create TAGS\\=local,some\\ data",
|
163
|
+
:tables => "rake -s dump:create TABLES\\=some\\ data TAGS\\=local",
|
164
|
+
:assets => "rake -s dump:create ASSETS\\=some\\ data TAGS\\=local",
|
165
|
+
}, :return_value => '123.tgz')
|
166
|
+
|
167
|
+
it "should print result of rake task" do
|
168
|
+
@cap.dump.stub!(:run_local).and_return("123123.tgz\n")
|
169
|
+
grab_output{
|
170
|
+
@cap.find_and_execute_task("dump:local:create")
|
171
|
+
}[:stdout].should == "123123.tgz\n"
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return stripped result of rake task" do
|
175
|
+
@cap.dump.stub!(:run_local).and_return("123123.tgz\n")
|
176
|
+
grab_output{
|
177
|
+
@cap.find_and_execute_task("dump:local:create").should == "123123.tgz"
|
178
|
+
}
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "restore" do
|
183
|
+
it "should call local rake task" do
|
184
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:restore")
|
185
|
+
@cap.find_and_execute_task("dump:local:restore")
|
186
|
+
end
|
187
|
+
|
188
|
+
test_passing_environment_variables(:local, :restore, {
|
189
|
+
:like => "rake -s dump:restore LIKE\\=some\\ data",
|
190
|
+
:tags => "rake -s dump:restore TAGS\\=some\\ data",
|
191
|
+
:migrate_down => "rake -s dump:restore MIGRATE_DOWN\\=some\\ data",
|
192
|
+
:restore_schema => "rake -s dump:restore RESTORE_SCHEMA\\=some\\ data",
|
193
|
+
:restore_tables => "rake -s dump:restore RESTORE_TABLES\\=some\\ data",
|
194
|
+
:restore_assets => "rake -s dump:restore RESTORE_ASSETS\\=some\\ data",
|
195
|
+
})
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "upload" do
|
199
|
+
it "should run rake versions to get avaliable versions" do
|
200
|
+
@cap.dump.should_receive(:run_local).with("rake -s dump:versions").and_return('')
|
201
|
+
@cap.find_and_execute_task("dump:local:upload")
|
202
|
+
end
|
203
|
+
|
204
|
+
test_passing_environment_variables(:local, :transfer, {
|
205
|
+
:like => "rake -s dump:versions LIKE\\=some\\ data",
|
206
|
+
:tags => "rake -s dump:versions TAGS\\=some\\ data",
|
207
|
+
:summary => "rake -s dump:versions", # block sending summary to versions
|
208
|
+
:transfer_via => "rake -s dump:versions", # tranfer_via is used internally
|
209
|
+
}, :cap_task => 'dump:local:upload')
|
210
|
+
|
211
|
+
it "should not upload anything if there are no versions avaliable" do
|
212
|
+
@cap.dump.stub!(:run_local).and_return('')
|
213
|
+
@cap.dump.should_not_receive(:do_transfer)
|
214
|
+
@cap.find_and_execute_task("dump:local:upload")
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should transfer latest version dump" do
|
218
|
+
@cap.dump.stub!(:run_local).and_return("100.tgz\n200.tgz\n300.tgz\n")
|
219
|
+
@cap.dump.should_receive(:do_transfer).with(:up, "dump/300.tgz", "#{@remote_path}/dump/300.tgz")
|
220
|
+
@cap.find_and_execute_task("dump:local:upload")
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should handle extra spaces around file names" do
|
224
|
+
@cap.dump.stub!(:run_local).and_return("\r\n\r\n\r 100.tgz \r\n\r\n\r 200.tgz \r\n\r\n\r 300.tgz \r\n\r\n\r ")
|
225
|
+
@cap.dump.should_receive(:do_transfer).with(:up, "dump/300.tgz", "#{@remote_path}/dump/300.tgz")
|
226
|
+
@cap.find_and_execute_task("dump:local:upload")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "remote" do
|
232
|
+
describe "versions" do
|
233
|
+
it "should call remote rake task" do
|
234
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production SHOW_SIZE\\=true").and_return('')
|
235
|
+
@cap.find_and_execute_task("dump:remote:versions")
|
236
|
+
end
|
237
|
+
|
238
|
+
test_passing_environment_variables(:remote, :versions, {
|
239
|
+
:like => "rake -s dump:versions LIKE\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production SHOW_SIZE\\=true",
|
240
|
+
:tags => "rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production SHOW_SIZE\\=true TAGS\\=some\\ data",
|
241
|
+
:summary => "rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production SHOW_SIZE\\=true SUMMARY\\=some\\ data",
|
242
|
+
})
|
243
|
+
|
244
|
+
it "should print result of rake task" do
|
245
|
+
@cap.dump.stub!(:run_remote).and_return(" 123M\t123123.tgz\n")
|
246
|
+
grab_output{
|
247
|
+
@cap.find_and_execute_task("dump:remote:versions")
|
248
|
+
}[:stdout].should == " 123M\t123123.tgz\n"
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should use custom rake binary" do
|
252
|
+
@cap.dump.should_receive(:fetch_rake).and_return('/custom/rake')
|
253
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; /custom/rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production SHOW_SIZE\\=true").and_return('')
|
254
|
+
@cap.find_and_execute_task("dump:remote:versions")
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "cleanup" do
|
259
|
+
it "should call remote rake task" do
|
260
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:cleanup PROGRESS_TTY\\=\\+ RAILS_ENV\\=production").and_return('')
|
261
|
+
@cap.find_and_execute_task("dump:remote:cleanup")
|
262
|
+
end
|
263
|
+
|
264
|
+
test_passing_environment_variables(:remote, :cleanup, {
|
265
|
+
:like => "rake -s dump:cleanup LIKE\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production",
|
266
|
+
:tags => "rake -s dump:cleanup PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=some\\ data",
|
267
|
+
:leave => "rake -s dump:cleanup LEAVE\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production",
|
268
|
+
})
|
269
|
+
|
270
|
+
it "should print result of rake task" do
|
271
|
+
@cap.dump.stub!(:run_remote).and_return("123123.tgz\n")
|
272
|
+
grab_output{
|
273
|
+
@cap.find_and_execute_task("dump:remote:cleanup")
|
274
|
+
}[:stdout].should == "123123.tgz\n"
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should use custom rake binary" do
|
278
|
+
@cap.dump.should_receive(:fetch_rake).and_return('/custom/rake')
|
279
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; /custom/rake -s dump:cleanup PROGRESS_TTY\\=\\+ RAILS_ENV\\=production").and_return('')
|
280
|
+
@cap.find_and_execute_task("dump:remote:cleanup")
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "create" do
|
285
|
+
it "should raise if dump creation fails" do
|
286
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote").and_return('')
|
287
|
+
proc{
|
288
|
+
@cap.find_and_execute_task("dump:remote:create")
|
289
|
+
}.should raise_error('Failed creating dump')
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should call remote rake task with default rails_env and tag remote" do
|
293
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote").and_return('123.tgz')
|
294
|
+
grab_output{
|
295
|
+
@cap.find_and_execute_task("dump:remote:create")
|
296
|
+
}
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should call remote rake task with default rails_env and additional tag remote" do
|
300
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote,photos").and_return('123.tgz')
|
301
|
+
grab_output{
|
302
|
+
DumpRake::Env.with_env :tags => 'photos' do
|
303
|
+
@cap.find_and_execute_task("dump:remote:create")
|
304
|
+
end
|
305
|
+
}
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should call remote rake task with fetched rails_env and default DESC remote" do
|
309
|
+
@cap.dump.should_receive(:fetch_rails_env).and_return('dev')
|
310
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=dev TAGS\\=remote").and_return('123.tgz')
|
311
|
+
grab_output{
|
312
|
+
@cap.find_and_execute_task("dump:remote:create")
|
313
|
+
}
|
314
|
+
end
|
315
|
+
|
316
|
+
test_passing_environment_variables(:remote, :create, {
|
317
|
+
:desc => "rake -s dump:create DESC\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote",
|
318
|
+
:tags => "rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote,some\\ data",
|
319
|
+
:assets => "rake -s dump:create ASSETS\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote",
|
320
|
+
:tables => "rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TABLES\\=some\\ data TAGS\\=remote",
|
321
|
+
}, :return_value => '123.tgz')
|
322
|
+
|
323
|
+
it "should print result of rake task" do
|
324
|
+
@cap.dump.stub!(:run_remote).and_return("123123.tgz\n")
|
325
|
+
grab_output{
|
326
|
+
@cap.find_and_execute_task("dump:remote:create")
|
327
|
+
}[:stdout].should == "123123.tgz\n"
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should return stripped result of rake task" do
|
331
|
+
@cap.dump.stub!(:run_remote).and_return("123123.tgz\n")
|
332
|
+
grab_output{
|
333
|
+
@cap.find_and_execute_task("dump:remote:create").should == "123123.tgz"
|
334
|
+
}
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should use custom rake binary" do
|
338
|
+
@cap.dump.should_receive(:fetch_rake).and_return('/custom/rake')
|
339
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; /custom/rake -s dump:create PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=remote").and_return('123.tgz')
|
340
|
+
grab_output{
|
341
|
+
@cap.find_and_execute_task("dump:remote:create")
|
342
|
+
}
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
describe "restore" do
|
347
|
+
it "should call remote rake task with default rails_env" do
|
348
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production")
|
349
|
+
@cap.find_and_execute_task("dump:remote:restore")
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should call remote rake task with fetched rails_env" do
|
353
|
+
@cap.dump.should_receive(:fetch_rails_env).and_return('dev')
|
354
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=dev")
|
355
|
+
@cap.find_and_execute_task("dump:remote:restore")
|
356
|
+
end
|
357
|
+
|
358
|
+
test_passing_environment_variables(:remote, :restore, {
|
359
|
+
:like => "rake -s dump:restore LIKE\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production",
|
360
|
+
:tags => "rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=some\\ data",
|
361
|
+
:migrate_down => "rake -s dump:restore MIGRATE_DOWN\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production",
|
362
|
+
:restore_schema => "rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production RESTORE_SCHEMA\\=some\\ data",
|
363
|
+
:restore_tables => "rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production RESTORE_TABLES\\=some\\ data",
|
364
|
+
:restore_assets => "rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production RESTORE_ASSETS\\=some\\ data",
|
365
|
+
})
|
366
|
+
|
367
|
+
it "should use custom rake binary" do
|
368
|
+
@cap.dump.should_receive(:fetch_rake).and_return('/custom/rake')
|
369
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; /custom/rake -s dump:restore PROGRESS_TTY\\=\\+ RAILS_ENV\\=production")
|
370
|
+
@cap.find_and_execute_task("dump:remote:restore")
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe "download" do
|
375
|
+
it "should run rake versions to get avaliable versions" do
|
376
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production").and_return('')
|
377
|
+
@cap.find_and_execute_task("dump:remote:download")
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should block sending summary to versions" do
|
381
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production").and_return('')
|
382
|
+
DumpRake::Env::DICTIONARY[:summary].each do |name|
|
383
|
+
DumpRake::Env.with_env name => 'true' do
|
384
|
+
@cap.find_and_execute_task("dump:remote:download")
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
test_passing_environment_variables(:remote, :transfer, {
|
390
|
+
:like => "rake -s dump:versions LIKE\\=some\\ data PROGRESS_TTY\\=\\+ RAILS_ENV\\=production",
|
391
|
+
:tags => "rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production TAGS\\=some\\ data",
|
392
|
+
:summary => "rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production", # block sending summary to versions
|
393
|
+
:transfer_via => "rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production", # tranfer_via is used internally
|
394
|
+
}, :cap_task => "dump:remote:download")
|
395
|
+
|
396
|
+
it "should not download anything if there are no versions avaliable" do
|
397
|
+
@cap.dump.stub!(:run_remote).and_return('')
|
398
|
+
@cap.dump.should_not_receive(:do_transfer)
|
399
|
+
@cap.find_and_execute_task("dump:remote:download")
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should transfer latest version dump" do
|
403
|
+
@cap.dump.stub!(:run_remote).and_return("100.tgz\n200.tgz\n300.tgz\n")
|
404
|
+
@cap.dump.should_receive(:do_transfer).with(:down, "#{@remote_path}/dump/300.tgz", "dump/300.tgz")
|
405
|
+
FileUtils.stub!(:mkpath)
|
406
|
+
@cap.find_and_execute_task("dump:remote:download")
|
407
|
+
end
|
408
|
+
|
409
|
+
it "should handle extra spaces around file names" do
|
410
|
+
@cap.dump.stub!(:run_remote).and_return("\r\n\r\n\r 100.tgz \r\n\r\n\r 200.tgz \r\n\r\n\r 300.tgz \r\n\r\n\r ")
|
411
|
+
@cap.dump.should_receive(:do_transfer).with(:down, "#{@remote_path}/dump/300.tgz", "dump/300.tgz")
|
412
|
+
FileUtils.stub!(:mkpath)
|
413
|
+
@cap.find_and_execute_task("dump:remote:download")
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should create local dump dir" do
|
417
|
+
@cap.dump.stub!(:run_remote).and_return("100.tgz\n200.tgz\n300.tgz\n")
|
418
|
+
@cap.dump.stub!(:do_transfer)
|
419
|
+
FileUtils.should_receive(:mkpath).with('dump')
|
420
|
+
@cap.find_and_execute_task("dump:remote:download")
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should run rake versions use custom rake binary" do
|
424
|
+
@cap.dump.should_receive(:fetch_rake).and_return('/custom/rake')
|
425
|
+
@cap.dump.should_receive(:run_remote).with("cd #{@remote_path}; /custom/rake -s dump:versions PROGRESS_TTY\\=\\+ RAILS_ENV\\=production").and_return('')
|
426
|
+
@cap.find_and_execute_task("dump:remote:download")
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "mirror" do
|
432
|
+
{"up" => [:local, :remote], "down" => [:remote, :local]}.each do |dir, way|
|
433
|
+
src = way[0]
|
434
|
+
dst = way[1]
|
435
|
+
describe name do
|
436
|
+
it "should create auto-backup with tag auto-backup" do
|
437
|
+
@cap.dump.namespaces[dst].should_receive(:create){ DumpRake::Env[:tags].should == 'auto-backup'; '' }
|
438
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should create auto-backup with additional tag auto-backup" do
|
442
|
+
@cap.dump.namespaces[dst].should_receive(:create){ DumpRake::Env[:tags].should == 'auto-backup,photos'; '' }
|
443
|
+
DumpRake::Env.with_env :tags => 'photos' do
|
444
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
it "should not call local:create if auto-backup fails" do
|
449
|
+
@cap.dump.namespaces[dst].stub!(:create).and_return('')
|
450
|
+
@cap.dump.namespaces[src].should_not_receive(:create)
|
451
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should call local:create if auto-backup succeedes with tags mirror and mirror-#{dir}" do
|
455
|
+
@cap.dump.namespaces[dst].stub!(:create).and_return('123.tgz')
|
456
|
+
@cap.dump.namespaces[src].should_receive(:create){ DumpRake::Env[:tags].should == "mirror"; '' }
|
457
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
458
|
+
end
|
459
|
+
|
460
|
+
it "should call local:create if auto-backup succeedes with additional tags mirror and mirror-#{dir}" do
|
461
|
+
@cap.dump.namespaces[dst].stub!(:create).and_return('123.tgz')
|
462
|
+
@cap.dump.namespaces[src].should_receive(:create){ DumpRake::Env[:tags].should == "mirror,photos"; '' }
|
463
|
+
DumpRake::Env.with_env :tags => 'photos' do
|
464
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should not call local:upload or remote:restore if local:create fails" do
|
469
|
+
@cap.dump.namespaces[dst].stub!(:create).and_return('123.tgz')
|
470
|
+
@cap.dump.namespaces[src].stub!(:create).and_return('')
|
471
|
+
@cap.dump.namespaces[src].should_not_receive(:upload)
|
472
|
+
@cap.dump.namespaces[dst].should_not_receive(:restore)
|
473
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should call local:upload and remote:restore with only varibale ver set to file name if local:create returns file name" do
|
477
|
+
@cap.dump.namespaces[dst].stub!(:create).and_return('123.tgz')
|
478
|
+
@cap.dump.namespaces[src].stub!(:create).and_return('123.tgz')
|
479
|
+
test_env = proc{
|
480
|
+
DumpRake::Env[:like].should == '123.tgz'
|
481
|
+
DumpRake::Env[:tags].should == nil
|
482
|
+
DumpRake::Env[:desc].should == nil
|
483
|
+
}
|
484
|
+
@cap.dump.namespaces[src].should_receive(:"#{dir}load").ordered(&test_env)
|
485
|
+
@cap.dump.namespaces[dst].should_receive(:restore).ordered(&test_env)
|
486
|
+
DumpRake::Env.with_env all_dictionary_variables do
|
487
|
+
@cap.find_and_execute_task("dump:mirror:#{dir}")
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
describe "backup" do
|
495
|
+
it "should call remote:create" do
|
496
|
+
@cap.dump.remote.should_receive(:create).and_return('')
|
497
|
+
@cap.find_and_execute_task("dump:backup")
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should not call remote:download if remote:create returns blank" do
|
501
|
+
@cap.dump.remote.stub!(:create).and_return('')
|
502
|
+
@cap.dump.remote.should_not_receive(:download)
|
503
|
+
@cap.find_and_execute_task("dump:backup")
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should call remote:download if remote:create returns file name" do
|
507
|
+
@cap.dump.remote.stub!(:create).and_return('123.tgz')
|
508
|
+
@cap.dump.remote.should_receive(:download).ordered
|
509
|
+
@cap.find_and_execute_task("dump:backup")
|
510
|
+
end
|
511
|
+
|
512
|
+
it "should call remote:create with tag backup" do
|
513
|
+
def (@cap.dump.remote).create
|
514
|
+
DumpRake::Env[:tags].should == 'backup'
|
515
|
+
''
|
516
|
+
end
|
517
|
+
@cap.find_and_execute_task("dump:backup")
|
518
|
+
end
|
519
|
+
|
520
|
+
it "should call remote:create with additional tag backup" do
|
521
|
+
def (@cap.dump.remote).create
|
522
|
+
DumpRake::Env[:tags].should == 'backup,photos'
|
523
|
+
''
|
524
|
+
end
|
525
|
+
DumpRake::Env.with_env :tags => 'photos' do
|
526
|
+
@cap.find_and_execute_task("dump:backup")
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
it "should pass description if it is set" do
|
531
|
+
def (@cap.dump.remote).create
|
532
|
+
DumpRake::Env[:desc].should == 'remote dump'
|
533
|
+
''
|
534
|
+
end
|
535
|
+
DumpRake::Env.with_env :desc => 'remote dump' do
|
536
|
+
@cap.find_and_execute_task("dump:backup")
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
it "should send only ver variable" do
|
541
|
+
@cap.dump.remote.stub!(:create).and_return('123.tgz')
|
542
|
+
def (@cap.dump.remote).download
|
543
|
+
DumpRake::Env[:like].should == '123.tgz'
|
544
|
+
DumpRake::Env[:tags].should == nil
|
545
|
+
DumpRake::Env[:desc].should == nil
|
546
|
+
''
|
547
|
+
end
|
548
|
+
DumpRake::Env.with_env all_dictionary_variables do
|
549
|
+
@cap.find_and_execute_task("dump:backup")
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
end
|