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
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DumpRake::Dump do
|
4
4
|
def dump_path(file_name)
|
@@ -9,22 +9,20 @@ describe DumpRake::Dump do
|
|
9
9
|
DumpRake::Dump.new(dump_path(file_name))
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe 'lock' do
|
13
13
|
before do
|
14
14
|
@yield_receiver = double('yield_receiver')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should not yield if file does not exist' do
|
18
18
|
expect(@yield_receiver).not_to receive(:fire)
|
19
19
|
|
20
|
-
expect(File).to receive(:open).and_return(nil)
|
21
|
-
|
22
20
|
DumpRake::Dump.new('hello').lock do
|
23
21
|
@yield_receiver.fire
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
it
|
25
|
+
it 'should not yield if file can not be locked' do
|
28
26
|
expect(@yield_receiver).not_to receive(:fire)
|
29
27
|
|
30
28
|
@file = double('file')
|
@@ -38,7 +36,7 @@ describe DumpRake::Dump do
|
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
it
|
39
|
+
it 'should yield if file can not be locked' do
|
42
40
|
expect(@yield_receiver).to receive(:fire)
|
43
41
|
|
44
42
|
@file = double('file')
|
@@ -53,16 +51,16 @@ describe DumpRake::Dump do
|
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
describe
|
57
|
-
it
|
54
|
+
describe 'new' do
|
55
|
+
it 'should init with path if String sent' do
|
58
56
|
expect(DumpRake::Dump.new('hello').path).to eq(Pathname('hello'))
|
59
57
|
end
|
60
58
|
|
61
|
-
it
|
59
|
+
it 'should init with path if Pathname sent' do
|
62
60
|
expect(DumpRake::Dump.new(Pathname('hello')).path).to eq(Pathname('hello'))
|
63
61
|
end
|
64
62
|
|
65
|
-
describe
|
63
|
+
describe 'with options' do
|
66
64
|
before do
|
67
65
|
@time = double('time')
|
68
66
|
allow(@time).to receive(:utc).and_return(@time)
|
@@ -70,30 +68,30 @@ describe DumpRake::Dump do
|
|
70
68
|
allow(Time).to receive(:now).and_return(@time)
|
71
69
|
end
|
72
70
|
|
73
|
-
it
|
71
|
+
it 'should generate path with no options' do
|
74
72
|
expect(DumpRake::Dump.new.path).to eq(Pathname('19650414065945.tgz'))
|
75
73
|
end
|
76
74
|
|
77
|
-
it
|
75
|
+
it 'should generate with dir' do
|
78
76
|
expect(DumpRake::Dump.new(:dir => 'dump_dir').path).to eq(Pathname('dump_dir/19650414065945.tgz'))
|
79
77
|
end
|
80
78
|
|
81
|
-
it
|
79
|
+
it 'should generate path with description' do
|
82
80
|
expect(DumpRake::Dump.new(:dir => 'dump_dir', :desc => 'hello world').path).to eq(Pathname('dump_dir/19650414065945-hello world.tgz'))
|
83
81
|
end
|
84
82
|
|
85
|
-
it
|
83
|
+
it 'should generate path with tags' do
|
86
84
|
expect(DumpRake::Dump.new(:dir => 'dump_dir', :tags => ' mirror, hello world ').path).to eq(Pathname('dump_dir/19650414065945@hello world,mirror.tgz'))
|
87
85
|
end
|
88
86
|
|
89
|
-
it
|
87
|
+
it 'should generate path with description and tags' do
|
90
88
|
expect(DumpRake::Dump.new(:dir => 'dump_dir', :desc => 'Anniversary backup', :tags => ' mirror, hello world ').path).to eq(Pathname('dump_dir/19650414065945-Anniversary backup@hello world,mirror.tgz'))
|
91
89
|
end
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
95
|
-
describe
|
96
|
-
describe
|
93
|
+
describe 'versions' do
|
94
|
+
describe 'list' do
|
97
95
|
def stub_glob
|
98
96
|
paths = %w[123 345 567].map do |name|
|
99
97
|
path = dump_path("#{name}.tgz")
|
@@ -103,23 +101,23 @@ describe DumpRake::Dump do
|
|
103
101
|
allow(Dir).to receive(:[]).and_return(paths)
|
104
102
|
end
|
105
103
|
|
106
|
-
it
|
104
|
+
it 'should search for files in dump dir when asked for list' do
|
107
105
|
expect(Dir).to receive(:[]).with(dump_path('*.tgz')).and_return([])
|
108
106
|
DumpRake::Dump.list
|
109
107
|
end
|
110
108
|
|
111
|
-
it
|
109
|
+
it 'should return selves instances for each found file' do
|
112
110
|
stub_glob
|
113
111
|
DumpRake::Dump.list.all?{ |dump| expect(dump).to be_a(DumpRake::Dump) }
|
114
112
|
end
|
115
113
|
|
116
|
-
it
|
114
|
+
it 'should return dumps with name containting :like' do
|
117
115
|
stub_glob
|
118
116
|
expect(DumpRake::Dump.list(:like => '3')).to eq(DumpRake::Dump.list.values_at(0, 1))
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
122
|
-
describe
|
120
|
+
describe 'with tags' do
|
123
121
|
before do
|
124
122
|
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
125
123
|
dumps_tags = [''] + %w[a a,d a,d,o a,d,s a,d,s,o a,o a,s a,s,o d d,o d,s d,s,o o s s,o z]
|
@@ -131,7 +129,7 @@ describe DumpRake::Dump do
|
|
131
129
|
allow(Dir).to receive(:[]).and_return(paths)
|
132
130
|
end
|
133
131
|
|
134
|
-
it
|
132
|
+
it 'should return all dumps if no tags send' do
|
135
133
|
expect(DumpRake::Dump.list(:tags => '')).to eq(DumpRake::Dump.list)
|
136
134
|
end
|
137
135
|
|
@@ -153,13 +151,13 @@ describe DumpRake::Dump do
|
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
156
|
-
describe
|
157
|
-
it
|
158
|
-
expect(new_dump(
|
154
|
+
describe 'name' do
|
155
|
+
it 'should return file name' do
|
156
|
+
expect(new_dump('19650414065945.tgz').name).to eq('19650414065945.tgz')
|
159
157
|
end
|
160
158
|
end
|
161
159
|
|
162
|
-
describe
|
160
|
+
describe 'parts' do
|
163
161
|
before do
|
164
162
|
@time = Time.utc(1965, 4, 14, 6, 59, 45)
|
165
163
|
end
|
@@ -170,14 +168,14 @@ describe DumpRake::Dump do
|
|
170
168
|
end
|
171
169
|
|
172
170
|
%w[tmp tgz].each do |ext|
|
173
|
-
it
|
171
|
+
it 'should return empty results for dump with wrong name' do
|
174
172
|
expect(dump_name_parts("196504140659.#{ext}")).to eq([nil, '', [], nil])
|
175
173
|
expect(dump_name_parts("196504140659-lala.#{ext}")).to eq([nil, '', [], nil])
|
176
174
|
expect(dump_name_parts("196504140659@lala.#{ext}")).to eq([nil, '', [], nil])
|
177
|
-
expect(dump_name_parts(
|
175
|
+
expect(dump_name_parts('19650414065945.ops')).to eq([nil, '', [], nil])
|
178
176
|
end
|
179
177
|
|
180
|
-
it
|
178
|
+
it 'should return tags for dump with tags' do
|
181
179
|
expect(dump_name_parts("19650414065945.#{ext}")).to eq([@time, '', [], ext])
|
182
180
|
expect(dump_name_parts("19650414065945- Hello world &&& .#{ext}")).to eq([@time, 'Hello world _', [], ext])
|
183
181
|
expect(dump_name_parts("19650414065945- Hello world &&& @ test , hello world , bad tag ~~~~.#{ext}")).to eq([@time, 'Hello world _', ['bad tag _', 'hello world', 'test'], ext])
|
@@ -187,44 +185,44 @@ describe DumpRake::Dump do
|
|
187
185
|
end
|
188
186
|
end
|
189
187
|
|
190
|
-
describe
|
191
|
-
it
|
192
|
-
expect(new_dump(
|
188
|
+
describe 'path' do
|
189
|
+
it 'should return path' do
|
190
|
+
expect(new_dump('19650414065945.tgz').path).to eq(Pathname(File.join(DumpRake::RailsRoot, 'dump', '19650414065945.tgz')))
|
193
191
|
end
|
194
192
|
end
|
195
193
|
|
196
|
-
describe
|
197
|
-
it
|
198
|
-
expect(new_dump(
|
194
|
+
describe 'tgz_path' do
|
195
|
+
it 'should return path if extension is already tgz' do
|
196
|
+
expect(new_dump('19650414065945.tgz').tgz_path).to eq(new_dump('19650414065945.tgz').path)
|
199
197
|
end
|
200
198
|
|
201
|
-
it
|
202
|
-
expect(new_dump(
|
199
|
+
it 'should return path with tgz extension' do
|
200
|
+
expect(new_dump('19650414065945.tmp').tgz_path).to eq(new_dump('19650414065945.tgz').path)
|
203
201
|
end
|
204
202
|
end
|
205
203
|
|
206
|
-
describe
|
207
|
-
it
|
208
|
-
expect(new_dump(
|
204
|
+
describe 'tmp_path' do
|
205
|
+
it 'should return path if extension is already tmp' do
|
206
|
+
expect(new_dump('19650414065945.tmp').tmp_path).to eq(new_dump('19650414065945.tmp').path)
|
209
207
|
end
|
210
208
|
|
211
|
-
it
|
212
|
-
expect(new_dump(
|
209
|
+
it 'should return path with tmp extension' do
|
210
|
+
expect(new_dump('19650414065945.tgz').tmp_path).to eq(new_dump('19650414065945.tmp').path)
|
213
211
|
end
|
214
212
|
end
|
215
213
|
|
216
|
-
describe
|
214
|
+
describe 'clean_description' do
|
217
215
|
it "should shorten string to 50 chars and replace special symblos with '-'" do
|
218
216
|
expect(DumpRake::Dump.new('').send(:clean_description, 'Special Dump #12837192837 (before fixind *&^*&^ photos)')).to eq('Special Dump #12837192837 (before fixind _ photos)')
|
219
217
|
expect(DumpRake::Dump.new('').send(:clean_description, "To#{'o' * 100} long description")).to eq("T#{'o' * 49}")
|
220
218
|
end
|
221
219
|
|
222
|
-
it
|
220
|
+
it 'should accept non string' do
|
223
221
|
expect(DumpRake::Dump.new('').send(:clean_description, nil)).to eq('')
|
224
222
|
end
|
225
223
|
end
|
226
224
|
|
227
|
-
describe
|
225
|
+
describe 'clean_tag' do
|
228
226
|
it "should shorten string to 20 chars and replace special symblos with '-'" do
|
229
227
|
expect(DumpRake::Dump.new('').send(:clean_tag, 'Very special tag #12837192837 (fixind *&^*&^)')).to eq('very special tag _12')
|
230
228
|
expect(DumpRake::Dump.new('').send(:clean_tag, "To#{'o' * 100} long tag")).to eq("t#{'o' * 19}")
|
@@ -238,24 +236,24 @@ describe DumpRake::Dump do
|
|
238
236
|
expect(DumpRake::Dump.new('').send(:clean_tag, '+++++++++++')).to eq('_')
|
239
237
|
end
|
240
238
|
|
241
|
-
it
|
239
|
+
it 'should accept non string' do
|
242
240
|
expect(DumpRake::Dump.new('').send(:clean_tag, nil)).to eq('')
|
243
241
|
end
|
244
242
|
end
|
245
243
|
|
246
|
-
describe
|
247
|
-
it
|
244
|
+
describe 'clean_tags' do
|
245
|
+
it 'should split string and return uniq non blank sorted tags' do
|
248
246
|
expect(DumpRake::Dump.new('').send(:clean_tags, ' perfect tag , hello,Hello,this is (*^(*&')).to eq(['hello', 'perfect tag', 'this is _'])
|
249
247
|
expect(DumpRake::Dump.new('').send(:clean_tags, "l#{'o' * 100}ng tag")).to eq(["l#{'o' * 19}"])
|
250
248
|
end
|
251
249
|
|
252
|
-
it
|
250
|
+
it 'should accept non string' do
|
253
251
|
expect(DumpRake::Dump.new('').send(:clean_tags, nil)).to eq([])
|
254
252
|
end
|
255
253
|
end
|
256
254
|
|
257
|
-
describe
|
258
|
-
it
|
255
|
+
describe 'get_filter_tags' do
|
256
|
+
it 'should split string and return uniq non blank sorted tags' do
|
259
257
|
expect(DumpRake::Dump.new('').send(:get_filter_tags, 'a,+b,+c,-d')).to eq({:simple => %w[a], :mandatory => %w[b c], :forbidden => %w[d]})
|
260
258
|
expect(DumpRake::Dump.new('').send(:get_filter_tags, ' a , + b , + c , - d ')).to eq({:simple => %w[a], :mandatory => %w[b c], :forbidden => %w[d]})
|
261
259
|
expect(DumpRake::Dump.new('').send(:get_filter_tags, ' a , + c , + b , - d ')).to eq({:simple => %w[a], :mandatory => %w[b c], :forbidden => %w[d]})
|
@@ -266,25 +264,25 @@ describe DumpRake::Dump do
|
|
266
264
|
expect{ DumpRake::Dump.new('').send(:get_filter_tags, '+a,-a') }.to raise_error
|
267
265
|
end
|
268
266
|
|
269
|
-
it
|
267
|
+
it 'should accept non string' do
|
270
268
|
expect(DumpRake::Dump.new('').send(:get_filter_tags, nil)).to eq({:simple => [], :mandatory => [], :forbidden => []})
|
271
269
|
end
|
272
270
|
end
|
273
271
|
|
274
|
-
describe
|
275
|
-
it
|
272
|
+
describe 'assets_root_link' do
|
273
|
+
it 'should create tem dir, chdir there, symlink rails app root to assets, yield and unlink assets ever if something raised' do
|
276
274
|
expect(Dir).to receive(:mktmpdir).and_yield('/tmp/abc')
|
277
275
|
expect(Dir).to receive(:chdir).with('/tmp/abc').and_yield
|
278
276
|
expect(File).to receive(:symlink).with(DumpRake::RailsRoot, 'assets')
|
279
277
|
expect(File).to receive(:unlink).with('assets')
|
280
|
-
expect
|
278
|
+
expect do
|
281
279
|
DumpRake::Dump.new('').send(:assets_root_link) do |dir, prefix|
|
282
280
|
expect(dir).to eq('/tmp/abc')
|
283
281
|
expect(prefix).to eq('assets')
|
284
282
|
@yielded = true
|
285
|
-
|
283
|
+
fail 'just test'
|
286
284
|
end
|
287
|
-
|
285
|
+
end.to raise_error('just test')
|
288
286
|
expect(@yielded).to eq(true)
|
289
287
|
end
|
290
288
|
end
|
@@ -1,18 +1,17 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../../../lib/dump_rake'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dump_rake'
|
4
3
|
|
5
4
|
DumpWriter = DumpRake::DumpWriter
|
6
5
|
describe DumpWriter do
|
7
|
-
describe
|
8
|
-
it
|
6
|
+
describe 'create' do
|
7
|
+
it 'should create selves instance and open' do
|
9
8
|
@dump = double('dump')
|
10
9
|
expect(@dump).to receive(:open)
|
11
10
|
expect(DumpWriter).to receive(:new).with('/abc/123.tmp').and_return(@dump)
|
12
11
|
DumpWriter.create('/abc/123.tmp')
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
14
|
+
it 'should call dump subroutines' do
|
16
15
|
@dump = double('dump')
|
17
16
|
allow(@dump).to receive(:open).and_yield(@dump)
|
18
17
|
allow(@dump).to receive(:silence).and_yield
|
@@ -27,18 +26,18 @@ describe DumpWriter do
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
describe
|
31
|
-
it
|
29
|
+
describe 'open' do
|
30
|
+
it 'should create dir for dump' do
|
32
31
|
allow(Zlib::GzipWriter).to receive(:open)
|
33
32
|
expect(FileUtils).to receive(:mkpath).with('/abc/def/ghi')
|
34
33
|
DumpWriter.new('/abc/def/ghi/123.tgz').open
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
36
|
+
it 'should set stream to gzipped tar writer' do
|
38
37
|
allow(FileUtils).to receive(:mkpath)
|
39
38
|
@gzip = double('gzip')
|
40
39
|
@stream = double('stream')
|
41
|
-
expect(Zlib::GzipWriter).to receive(:open).with(Pathname(
|
40
|
+
expect(Zlib::GzipWriter).to receive(:open).with(Pathname('123.tgz')).and_yield(@gzip)
|
42
41
|
expect(Archive::Tar::Minitar::Output).to receive(:open).with(@gzip).and_yield(@stream)
|
43
42
|
expect(@gzip).to receive(:mtime=).with(Time.utc(2000))
|
44
43
|
|
@@ -51,7 +50,7 @@ describe DumpWriter do
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
describe
|
53
|
+
describe 'subroutines' do
|
55
54
|
before do
|
56
55
|
@tar = double('tar')
|
57
56
|
@stream = double('stream', :tar => @tar)
|
@@ -62,8 +61,8 @@ describe DumpWriter do
|
|
62
61
|
allow(Progress).to receive(:io).and_return(StringIO.new)
|
63
62
|
end
|
64
63
|
|
65
|
-
describe
|
66
|
-
it
|
64
|
+
describe 'create_file' do
|
65
|
+
it 'should create temp file, yield it for writing, create file in tar and write it there' do
|
67
66
|
@temp = double('temp', :open => true, :length => 6, :read => 'qwfpgj')
|
68
67
|
expect(@temp).to receive(:write).with('qwfpgj')
|
69
68
|
allow(@temp).to receive(:eof?).and_return(false, true)
|
@@ -81,20 +80,20 @@ describe DumpWriter do
|
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
84
|
-
describe
|
85
|
-
it
|
83
|
+
describe 'write_schema' do
|
84
|
+
it 'should create file schema.rb' do
|
86
85
|
expect(@dump).to receive(:create_file).with('schema.rb')
|
87
86
|
@dump.write_schema
|
88
87
|
end
|
89
88
|
|
90
|
-
it
|
89
|
+
it 'should set ENV[SCHEMA] to path of returned file' do
|
91
90
|
@file = double('file', :path => 'db/schema.rb')
|
92
91
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
93
92
|
expect(DumpRake::Env).to receive(:with_env).with('SCHEMA' => 'db/schema.rb')
|
94
93
|
@dump.write_schema
|
95
94
|
end
|
96
95
|
|
97
|
-
it
|
96
|
+
it 'should call rake task db:schema:dump' do
|
98
97
|
@file = double('file', :path => 'db/schema.rb')
|
99
98
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
100
99
|
@task = double('task')
|
@@ -104,14 +103,14 @@ describe DumpWriter do
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
describe
|
108
|
-
it
|
106
|
+
describe 'write_tables' do
|
107
|
+
it 'should verify connection' do
|
109
108
|
allow(@dump).to receive(:tables_to_dump).and_return([])
|
110
109
|
expect(@dump).to receive(:verify_connection)
|
111
110
|
@dump.write_tables
|
112
111
|
end
|
113
112
|
|
114
|
-
it
|
113
|
+
it 'should call write_table for each table returned by tables_to_dump' do
|
115
114
|
allow(@dump).to receive(:verify_connection)
|
116
115
|
allow(@dump).to receive(:tables_to_dump).and_return(%w[first second])
|
117
116
|
|
@@ -122,25 +121,25 @@ describe DumpWriter do
|
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
125
|
-
describe
|
126
|
-
it
|
124
|
+
describe 'write_table' do
|
125
|
+
it 'should get row count and store it to config' do
|
127
126
|
expect(@dump).to receive(:table_row_count).with('first').and_return(666)
|
128
127
|
allow(@dump).to receive(:create_file)
|
129
128
|
@dump.write_table('first')
|
130
129
|
expect(@config[:tables]['first']).to eq(666)
|
131
130
|
end
|
132
131
|
|
133
|
-
it
|
132
|
+
it 'should create_file' do
|
134
133
|
allow(@dump).to receive(:table_row_count).and_return(666)
|
135
134
|
expect(@dump).to receive(:create_file)
|
136
135
|
@dump.write_table('first')
|
137
136
|
end
|
138
137
|
|
139
|
-
it
|
138
|
+
it 'should dump column names and values of each row' do
|
140
139
|
@column_definitions = [
|
141
140
|
double('column', :name => 'id'),
|
142
141
|
double('column', :name => 'name'),
|
143
|
-
double('column', :name => 'associated_id')
|
142
|
+
double('column', :name => 'associated_id'),
|
144
143
|
]
|
145
144
|
allow(ActiveRecord::Base.connection).to receive(:columns).and_return(@column_definitions)
|
146
145
|
@rows = [
|
@@ -167,17 +166,17 @@ describe DumpWriter do
|
|
167
166
|
end
|
168
167
|
end
|
169
168
|
|
170
|
-
describe
|
169
|
+
describe 'write_assets' do
|
171
170
|
before do
|
172
171
|
allow(@dump).to receive(:assets_root_link).and_yield('/tmp', 'assets')
|
173
172
|
end
|
174
173
|
|
175
|
-
it
|
174
|
+
it 'should call assets_to_dump' do
|
176
175
|
expect(@dump).to receive(:assets_to_dump).and_return([])
|
177
176
|
@dump.write_assets
|
178
177
|
end
|
179
178
|
|
180
|
-
it
|
179
|
+
it 'should change root to rails app root' do
|
181
180
|
@file = double('file')
|
182
181
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[images videos])
|
183
182
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -186,7 +185,7 @@ describe DumpWriter do
|
|
186
185
|
@dump.write_assets
|
187
186
|
end
|
188
187
|
|
189
|
-
it
|
188
|
+
it 'should put assets to config' do
|
190
189
|
@file = double('file')
|
191
190
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[images/* videos])
|
192
191
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -201,7 +200,7 @@ describe DumpWriter do
|
|
201
200
|
expect(@config[:assets]).to eq({'images/a' => counts, 'images/b' => counts, 'videos' => counts})
|
202
201
|
end
|
203
202
|
|
204
|
-
it
|
203
|
+
it 'should use glob to find files' do
|
205
204
|
@file = double('file')
|
206
205
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[images/* videos])
|
207
206
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -217,7 +216,7 @@ describe DumpWriter do
|
|
217
216
|
@dump.write_assets
|
218
217
|
end
|
219
218
|
|
220
|
-
it
|
219
|
+
it 'should pack each file from assets_root_link' do
|
221
220
|
@file = double('file')
|
222
221
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[images/* videos])
|
223
222
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -235,7 +234,7 @@ describe DumpWriter do
|
|
235
234
|
@dump.write_assets
|
236
235
|
end
|
237
236
|
|
238
|
-
it
|
237
|
+
it 'should pack each file' do
|
239
238
|
@file = double('file')
|
240
239
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[images/* videos])
|
241
240
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -255,7 +254,7 @@ describe DumpWriter do
|
|
255
254
|
@dump.write_assets
|
256
255
|
end
|
257
256
|
|
258
|
-
it
|
257
|
+
it 'should not raise if something fails when packing' do
|
259
258
|
@file = double('file')
|
260
259
|
allow(@dump).to receive(:assets_to_dump).and_return(%w[videos])
|
261
260
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
@@ -269,20 +268,20 @@ describe DumpWriter do
|
|
269
268
|
expect(Archive::Tar::Minitar).to receive(:pack_file).with('assets/a.mov', @stream).and_raise('file not found')
|
270
269
|
expect(Archive::Tar::Minitar).to receive(:pack_file).with('assets/b.mov', @stream)
|
271
270
|
|
272
|
-
grab_output
|
271
|
+
grab_output do
|
273
272
|
@dump.write_assets
|
274
|
-
|
273
|
+
end
|
275
274
|
end
|
276
275
|
|
277
276
|
end
|
278
277
|
|
279
|
-
describe
|
280
|
-
it
|
278
|
+
describe 'write_config' do
|
279
|
+
it 'should create file config' do
|
281
280
|
expect(@dump).to receive(:create_file).with('config')
|
282
281
|
@dump.write_config
|
283
282
|
end
|
284
283
|
|
285
|
-
it
|
284
|
+
it 'should dump column names and values of each row' do
|
286
285
|
@file = double('file')
|
287
286
|
allow(@dump).to receive(:create_file).and_yield(@file)
|
288
287
|
@config.replace({:tables => {'first' => 1, 'second' => 2}, :assets => %w[images videos]})
|
@@ -292,15 +291,15 @@ describe DumpWriter do
|
|
292
291
|
end
|
293
292
|
end
|
294
293
|
|
295
|
-
describe
|
296
|
-
it
|
294
|
+
describe 'assets_to_dump' do
|
295
|
+
it 'should call rake task assets' do
|
297
296
|
@task = double('task')
|
298
297
|
expect(Rake::Task).to receive(:[]).with('assets').and_return(@task)
|
299
298
|
expect(@task).to receive(:invoke)
|
300
299
|
@dump.assets_to_dump
|
301
300
|
end
|
302
301
|
|
303
|
-
it
|
302
|
+
it 'should return array of assets if separator is colon' do
|
304
303
|
@task = double('task')
|
305
304
|
allow(Rake::Task).to receive(:[]).and_return(@task)
|
306
305
|
allow(@task).to receive(:invoke)
|
@@ -309,7 +308,7 @@ describe DumpWriter do
|
|
309
308
|
end
|
310
309
|
end
|
311
310
|
|
312
|
-
it
|
311
|
+
it 'should return array of assets if separator is comma' do
|
313
312
|
@task = double('task')
|
314
313
|
allow(Rake::Task).to receive(:[]).and_return(@task)
|
315
314
|
allow(@task).to receive(:invoke)
|
@@ -318,7 +317,7 @@ describe DumpWriter do
|
|
318
317
|
end
|
319
318
|
end
|
320
319
|
|
321
|
-
it
|
320
|
+
it 'should return empty array if calling rake task assets raises an exception' do
|
322
321
|
allow(Rake::Task).to receive(:[]).and_raise('task assets not found')
|
323
322
|
DumpRake::Env.with_env(:assets => 'images:videos') do
|
324
323
|
expect(@dump.assets_to_dump).to eq([])
|