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