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