dump 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +53 -0
  3. data/.rubocop_todo.yml +33 -0
  4. data/.travis.yml +12 -3
  5. data/README.markdown +8 -0
  6. data/dump.gemspec +4 -1
  7. data/lib/dump.rb +1 -0
  8. data/lib/dump/capistrano.rb +7 -1
  9. data/lib/dump/capistrano/v2.rb +331 -0
  10. data/lib/dump/railtie.rb +1 -0
  11. data/lib/dump_rake.rb +17 -8
  12. data/lib/dump_rake/archive_tar_minitar_fix.rb +3 -1
  13. data/lib/dump_rake/assets.rb +1 -0
  14. data/lib/dump_rake/continious_timeout.rb +17 -17
  15. data/lib/dump_rake/dump.rb +27 -22
  16. data/lib/dump_rake/dump_reader.rb +62 -63
  17. data/lib/dump_rake/dump_writer.rb +20 -21
  18. data/lib/dump_rake/env.rb +12 -10
  19. data/lib/dump_rake/env/filter.rb +3 -0
  20. data/lib/dump_rake/rails_root.rb +1 -0
  21. data/lib/dump_rake/table_manipulation.rb +23 -20
  22. data/lib/generators/assets_config/assets_config_generator.rb +2 -0
  23. data/lib/tasks/assets.rake +1 -2
  24. data/lib/tasks/dump.rake +5 -6
  25. data/recipes/dump.rb +1 -343
  26. data/script/update_readme +5 -3
  27. data/spec/cycle_spec.rb +33 -30
  28. data/spec/dummy_rails_app.rb +42 -0
  29. data/spec/lib/dump_rake/dump_reader_spec.rb +80 -92
  30. data/spec/lib/dump_rake/dump_spec.rb +56 -58
  31. data/spec/lib/dump_rake/dump_writer_spec.rb +42 -43
  32. data/spec/lib/dump_rake/env/filter_spec.rb +9 -9
  33. data/spec/lib/dump_rake/env_spec.rb +21 -21
  34. data/spec/lib/dump_rake/rails_root_spec.rb +7 -7
  35. data/spec/lib/dump_rake/table_manipulation_spec.rb +57 -63
  36. data/spec/lib/dump_rake_spec.rb +76 -76
  37. data/spec/recipes/dump_spec.rb +241 -217
  38. data/spec/spec_helper.rb +1 -42
  39. data/spec/tasks/assets_spec.rb +18 -18
  40. data/spec/tasks/dump_spec.rb +18 -18
  41. metadata +21 -2
@@ -1,6 +1,8 @@
1
- #!/usr/bin/env ruby -rrubygems
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'bundler/setup'
2
5
 
3
- $: << File.join(File.dirname(__FILE__), '../lib')
4
6
  require 'pathname'
5
7
  require 'dump_rake/env'
6
8
 
@@ -9,7 +11,7 @@ lines = readme.readlines.map(&:rstrip)
9
11
  readme.open('w') do |f|
10
12
  lines.each do |line|
11
13
  line.sub!(/^`(.+?)`.*—.*$/) do
12
- key, names = DumpRake::Env::DICTIONARY.find{ |key, values| values.include?($1) }
14
+ key, names = DumpRake::Env::DICTIONARY.find{ |_key, values| values.include?(Regexp.last_match[1]) }
13
15
  if key
14
16
  names = names.map{ |name| "`#{name}`" }.join(', ')
15
17
  explanation = DumpRake::Env::EXPLANATIONS[key]
@@ -1,11 +1,12 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- require File.dirname(__FILE__) + '/../lib/dump_rake'
4
-
1
+ require 'spec_helper'
2
+ require 'dump_rake'
5
3
  require 'tmpdir'
6
4
 
5
+ class Chicken < ActiveRecord::Base
6
+ end
7
+
7
8
  def database_configs
8
- YAML::load(IO.read(PLUGIN_SPEC_DIR + "/db/database.yml"))
9
+ YAML.load(IO.read(File.expand_path('../db/database.yml', __FILE__)))
9
10
  end
10
11
 
11
12
  def adapters
@@ -18,12 +19,12 @@ def use_adapter(adapter)
18
19
  case config['adapter']
19
20
  when /^mysql/
20
21
  ActiveRecord::Base.establish_connection(config.merge('database' => nil))
21
- ActiveRecord::Base.connection.drop_database config['database'] rescue nil
22
+ ActiveRecord::Base.connection.drop_database config['database']
22
23
  ActiveRecord::Base.connection.create_database(config['database'])
23
24
  ActiveRecord::Base.establish_connection(config)
24
25
  when /^postgresql/
25
26
  ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
26
- ActiveRecord::Base.connection.drop_database config['database'] rescue nil
27
+ ActiveRecord::Base.connection.drop_database config['database']
27
28
  ActiveRecord::Base.connection.create_database(config['database'])
28
29
  ActiveRecord::Base.establish_connection(config)
29
30
  else
@@ -45,10 +46,14 @@ ensure
45
46
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
46
47
  end
47
48
 
49
+ def schema_path
50
+ File.expand_path('../db/schema.rb', __FILE__)
51
+ end
52
+
48
53
  def load_schema
49
- grab_output{
50
- load(DUMMY_SCHEMA_PATH)
51
- }
54
+ grab_output do
55
+ load(schema_path)
56
+ end
52
57
  end
53
58
 
54
59
  def in_temp_rails_app
@@ -63,7 +68,7 @@ ensure
63
68
  end
64
69
 
65
70
  def create_chickens!(options = {})
66
- time = Time.local(2000,"jan",1,20,15,1)
71
+ time = Time.local(2000, 'jan', 1, 20, 15, 1)
67
72
  data = {
68
73
  :string => ['', 'lala'],
69
74
  :text => ['', 'lala', 'lala' * 100],
@@ -84,12 +89,10 @@ def create_chickens!(options = {})
84
89
  end
85
90
  end
86
91
  end
87
- if options[:random]
88
- options[:random].to_i.times do
89
- Chicken.create! do |chicken|
90
- data.each do |type, values|
91
- chicken["#{type}_col"] = values[rand(values.length)] if rand > 0.5
92
- end
92
+ options[:random].to_i.times do
93
+ Chicken.create! do |chicken|
94
+ data.each do |type, values|
95
+ chicken["#{type}_col"] = values[rand(values.length)] if rand > 0.5
93
96
  end
94
97
  end
95
98
  end
@@ -102,11 +105,11 @@ end
102
105
  def reset_rake!
103
106
  @rake = Rake::Application.new
104
107
  Rake.application = @rake
105
- load File.dirname(__FILE__) + '/../lib/tasks/assets.rake'
106
- load File.dirname(__FILE__) + '/../lib/tasks/dump.rake'
108
+ load 'tasks/assets.rake'
109
+ load 'tasks/dump.rake'
107
110
  Rake::Task.define_task('environment')
108
111
  Rake::Task.define_task('db:schema:dump') do
109
- File.open(DUMMY_SCHEMA_PATH, 'r') do |r|
112
+ File.open(schema_path, 'r') do |r|
110
113
  if ENV['SCHEMA']
111
114
  File.open(ENV['SCHEMA'], 'w') do |w|
112
115
  w.write(r.read)
@@ -121,21 +124,21 @@ end
121
124
 
122
125
  def call_rake
123
126
  reset_rake!
124
- grab_output{
127
+ grab_output do
125
128
  yield
126
- }
129
+ end
127
130
  end
128
131
 
129
132
  def call_rake_create(*args)
130
- call_rake{
133
+ call_rake do
131
134
  DumpRake.create(*args)
132
- }
135
+ end
133
136
  end
134
137
 
135
138
  def call_rake_restore(*args)
136
- call_rake{
139
+ call_rake do
137
140
  DumpRake.restore(*args)
138
- }
141
+ end
139
142
  end
140
143
 
141
144
  describe 'full cycle' do
@@ -146,16 +149,16 @@ describe 'full cycle' do
146
149
  it "should dump and restore using #{adapter}" do
147
150
  in_temp_rails_app do
148
151
  use_adapter(adapter) do
149
- #add chickens store their attributes and create dump
152
+ # add chickens store their attributes and create dump
150
153
  create_chickens!(:random => 100)
151
154
  saved_chicken_data = chicken_data
152
155
  call_rake_create(:description => 'chickens')
153
156
 
154
- #clear database
157
+ # clear database
155
158
  load_schema
156
159
  expect(Chicken.all).to eq([])
157
160
 
158
- #restore dump and verify equality
161
+ # restore dump and verify equality
159
162
  call_rake_restore(:version => 'chickens')
160
163
  expect(chicken_data).to eq(saved_chicken_data)
161
164
 
@@ -206,7 +209,7 @@ describe 'full cycle' do
206
209
  end
207
210
  end
208
211
 
209
- it "should create same dump for all adapters" do
212
+ it 'should create same dump for all adapters' do
210
213
  in_temp_rails_app do
211
214
  dumps = []
212
215
  adapters.each do |adapter|
@@ -0,0 +1,42 @@
1
+ require 'rails/version'
2
+
3
+ version = Rails::VERSION::STRING
4
+
5
+ if version < '3' && !Gem.respond_to?(:source_index)
6
+ # Add Gem.source_index for rails < 3
7
+ module Gem
8
+ def self.source_index
9
+ sources
10
+ end
11
+ SourceIndex = Specification
12
+ end
13
+ end
14
+
15
+ # Construct possible paths for config/environment.rb in dummy-X.X.X,
16
+ # dummy-X.X, dummy-X
17
+ version_parts = version.split('.')
18
+ environment_paths = version_parts.length.downto(1).map do |count|
19
+ version_part = version_parts.take(count).join('.')
20
+ File.expand_path("../dummy-#{version_part}/config/environment.rb", __FILE__)
21
+ end
22
+
23
+ # Require environment if any dummy app exists, otherwise abort with instructions
24
+ if (environment_path = environment_paths.find(&File.method(:exist?)))
25
+ require environment_path
26
+ else
27
+ app_path = "spec/dummy-#{version_parts.take(2).join('.')}"
28
+
29
+ rails_command = if version < '3'
30
+ "rails #{app_path}"
31
+ else
32
+ "rails new #{app_path} -TSJ --skip-bundle"
33
+ end
34
+
35
+ command = "RAILS_VERSION=#{version} bundle exec #{rails_command}"
36
+
37
+ abort [
38
+ "No dummy app for rails #{version}",
39
+ "Create using `#{command}`",
40
+ 'Tried:', *environment_paths
41
+ ].join("\n")
42
+ end
@@ -1,34 +1,18 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- require File.dirname(__FILE__) + '/../../../lib/dump_rake'
4
-
1
+ require 'spec_helper'
2
+ require 'dump_rake'
5
3
  require 'active_record/migration'
6
4
 
7
- def object_of_length(required_length)
8
- LengthConstraint.new(required_length)
9
- end
10
-
11
- class LengthConstraint
12
- def initialize(required_length)
13
- @required_length = required_length
14
- end
15
-
16
- def ==(value)
17
- @required_length == value.length
18
- end
19
- end
20
-
21
5
  DumpReader = DumpRake::DumpReader
22
6
  describe DumpReader do
23
- describe "restore" do
24
- it "should create selves instance and open" do
7
+ describe 'restore' do
8
+ it 'should create selves instance and open' do
25
9
  @dump = double('dump')
26
10
  expect(@dump).to receive(:open)
27
11
  expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
28
12
  DumpReader.restore('/abc/123.tmp')
29
13
  end
30
14
 
31
- it "should call dump subroutines" do
15
+ it 'should call dump subroutines' do
32
16
  @dump = double('dump')
33
17
  allow(@dump).to receive(:open).and_yield(@dump)
34
18
  allow(@dump).to receive(:silence).and_yield
@@ -44,10 +28,10 @@ describe DumpReader do
44
28
  end
45
29
  end
46
30
 
47
- describe "summary" do
31
+ describe 'summary' do
48
32
  Summary = DumpReader::Summary
49
33
  describe Summary do
50
- it "should format text" do
34
+ it 'should format text' do
51
35
  @summary = Summary.new
52
36
  @summary.header 'One'
53
37
  @summary.data(%w[fff ggg jjj ppp qqq www])
@@ -73,14 +57,14 @@ describe DumpReader do
73
57
  expect("#{@summary}").to eq(output.gsub(/#{output[/^\s+/]}/, ' '))
74
58
  end
75
59
 
76
- it "should pluralize" do
60
+ it 'should pluralize' do
77
61
  expect(Summary.pluralize(0, 'file')).to eq('0 files')
78
62
  expect(Summary.pluralize(1, 'file')).to eq('1 file')
79
63
  expect(Summary.pluralize(10, 'file')).to eq('10 files')
80
64
  end
81
65
  end
82
66
 
83
- it "should create selves instance and open" do
67
+ it 'should create selves instance and open' do
84
68
  @dump = double('dump')
85
69
  expect(@dump).to receive(:open)
86
70
  expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
@@ -92,7 +76,7 @@ describe DumpReader do
92
76
  {'path/a' => 10, 'path/b' => 20} => ['path/a: 10 entries', 'path/b: 20 entries'],
93
77
  %w[path/a path/b] => %w[path/a path/b],
94
78
  }.each do |assets, formatted_assets|
95
- it "should call dump subroutines and create summary" do
79
+ it 'should call dump subroutines and create summary' do
96
80
  tables = {'a' => 10, 'b' => 20, 'c' => 666}
97
81
  formatted_tables = ['a: 10 rows', 'b: 20 rows', 'c: 666 rows']
98
82
 
@@ -113,7 +97,7 @@ describe DumpReader do
113
97
  end
114
98
  end
115
99
 
116
- it "should call dump subroutines and create summary with schema" do
100
+ it 'should call dump subroutines and create summary with schema' do
117
101
  tables = {'a' => 10, 'b' => 20, 'c' => 666}
118
102
  formatted_tables = ['a: 10 rows', 'b: 20 rows', 'c: 666 rows']
119
103
  assets = formatted_assets = %w[path/a path/b]
@@ -142,11 +126,11 @@ describe DumpReader do
142
126
  end
143
127
  end
144
128
 
145
- describe "open" do
146
- it "should set stream to gzipped tar reader" do
129
+ describe 'open' do
130
+ it 'should set stream to gzipped tar reader' do
147
131
  @gzip = double('gzip')
148
132
  @stream = double('stream')
149
- expect(Zlib::GzipReader).to receive(:open).with(Pathname("123.tgz")).and_yield(@gzip)
133
+ expect(Zlib::GzipReader).to receive(:open).with(Pathname('123.tgz')).and_yield(@gzip)
150
134
  expect(Archive::Tar::Minitar::Input).to receive(:open).with(@gzip).and_yield(@stream)
151
135
 
152
136
  @dump = DumpReader.new('123.tgz')
@@ -157,7 +141,7 @@ describe DumpReader do
157
141
  end
158
142
  end
159
143
 
160
- describe "low level" do
144
+ describe 'low level' do
161
145
  before do
162
146
  @e1 = double('e1', :full_name => 'config', :read => 'config_data')
163
147
  @e2 = double('e2', :full_name => 'first.dump', :read => 'first.dump_data')
@@ -167,44 +151,44 @@ describe DumpReader do
167
151
  allow(@dump).to receive(:stream).and_return(@stream)
168
152
  end
169
153
 
170
- describe "find_entry" do
171
- it "should find first entry in stream equal string" do
154
+ describe 'find_entry' do
155
+ it 'should find first entry in stream equal string' do
172
156
  @dump.find_entry('config') do |entry|
173
157
  expect(entry).to eq(@e1)
174
158
  end
175
159
  end
176
160
 
177
- it "should find first entry in stream matching regexp" do
161
+ it 'should find first entry in stream matching regexp' do
178
162
  @dump.find_entry(/\.dump$/) do |entry|
179
163
  expect(entry).to eq(@e2)
180
164
  end
181
165
  end
182
166
 
183
- it "should return result of block" do
184
- expect(@dump.find_entry(/\.dump$/) do |entry|
167
+ it 'should return result of block' do
168
+ expect(@dump.find_entry(/\.dump$/) do |_entry|
185
169
  'hello'
186
170
  end).to eq('hello')
187
171
  end
188
172
  end
189
173
 
190
- describe "read_entry" do
191
- it "should call find_entry" do
174
+ describe 'read_entry' do
175
+ it 'should call find_entry' do
192
176
  expect(@dump).to receive(:find_entry).with('config').and_yield(@e1)
193
177
  @dump.read_entry('config')
194
178
  end
195
179
 
196
- it "should read entries data" do
180
+ it 'should read entries data' do
197
181
  expect(@dump.read_entry('config')).to eq('config_data')
198
182
  end
199
183
  end
200
184
 
201
- describe "read_entry_to_file" do
202
- it "should call find_entry" do
185
+ describe 'read_entry_to_file' do
186
+ it 'should call find_entry' do
203
187
  expect(@dump).to receive(:find_entry).with('config')
204
188
  @dump.read_entry_to_file('config')
205
189
  end
206
190
 
207
- it "should open temp file, write data there, rewind and yield that file" do
191
+ it 'should open temp file, write data there, rewind and yield that file' do
208
192
  @entry = double('entry')
209
193
  allow(@dump).to receive(:find_entry).and_yield(@entry)
210
194
  @temp = double('temp')
@@ -223,7 +207,7 @@ describe DumpReader do
223
207
  end
224
208
  end
225
209
 
226
- describe "subroutines" do
210
+ describe 'subroutines' do
227
211
  before do
228
212
  @stream = double('stream')
229
213
  @dump = DumpReader.new('123.tgz')
@@ -231,8 +215,8 @@ describe DumpReader do
231
215
  allow(Progress).to receive(:io).and_return(StringIO.new)
232
216
  end
233
217
 
234
- describe "read_config" do
235
- it "should read config" do
218
+ describe 'read_config' do
219
+ it 'should read config' do
236
220
  @data = {:tables => {:first => 1}, :assets => %w[images videos]}
237
221
  expect(@dump).to receive(:read_entry).with('config').and_return(Marshal.dump(@data))
238
222
 
@@ -241,8 +225,8 @@ describe DumpReader do
241
225
  end
242
226
  end
243
227
 
244
- describe "migrate_down" do
245
- it "should not invoke rake tasks or find_entry if migrate_down is 0, no or false" do
228
+ describe 'migrate_down' do
229
+ it 'should not invoke rake tasks or find_entry if migrate_down is 0, no or false' do
246
230
  expect(Rake::Task).not_to receive(:[])
247
231
  expect(@dump).not_to receive(:find_entry)
248
232
 
@@ -257,7 +241,7 @@ describe DumpReader do
257
241
  end
258
242
  end
259
243
 
260
- it "should invoke db:drop and db:create if migrate_down is reset" do
244
+ it 'should invoke db:drop and db:create if migrate_down is reset' do
261
245
  @load_task = double('drop_task')
262
246
  @dump_task = double('create_task')
263
247
  expect(Rake::Task).to receive(:[]).with('db:drop').and_return(@load_task)
@@ -272,7 +256,7 @@ describe DumpReader do
272
256
 
273
257
  [nil, '1'].each do |migrate_down_value|
274
258
  describe "when migrate_down is #{migrate_down_value.inspect}" do
275
- it "should not find_entry if table schema_migrations is not present" do
259
+ it 'should not find_entry if table schema_migrations is not present' do
276
260
  allow(@dump).to receive(:avaliable_tables).and_return(%w[first])
277
261
  expect(@dump).not_to receive(:find_entry)
278
262
 
@@ -281,7 +265,7 @@ describe DumpReader do
281
265
  end
282
266
  end
283
267
 
284
- it "should find schema_migrations.dump if table schema_migrations is present" do
268
+ it 'should find schema_migrations.dump if table schema_migrations is present' do
285
269
  allow(@dump).to receive(:avaliable_tables).and_return(%w[schema_migrations first])
286
270
  expect(@dump).to receive(:find_entry).with('schema_migrations.dump')
287
271
 
@@ -290,7 +274,7 @@ describe DumpReader do
290
274
  end
291
275
  end
292
276
 
293
- it "should call migrate down for each version not present in schema_migrations table" do
277
+ it 'should call migrate down for each version not present in schema_migrations table' do
294
278
  @entry = StringIO.new
295
279
  Marshal.dump(['version'], @entry)
296
280
  %w[1 2 3 4].each do |i|
@@ -308,12 +292,12 @@ describe DumpReader do
308
292
  version = DumpRake::Env['VERSION']
309
293
  @versions << version
310
294
  if version == '6'
311
- raise ActiveRecord::IrreversibleMigration
295
+ fail ActiveRecord::IrreversibleMigration
312
296
  end
313
297
  end
314
298
  expect(@migrate_down_task).to receive('reenable').exactly(3).times
315
299
 
316
- expect($stderr).to receive('puts').with("Irreversible migration: 6")
300
+ expect($stderr).to receive('puts').with('Irreversible migration: 6')
317
301
 
318
302
  expect(Rake::Task).to receive(:[]).with('db:migrate:down').exactly(3).times.and_return(@migrate_down_task)
319
303
 
@@ -326,19 +310,19 @@ describe DumpReader do
326
310
  end
327
311
  end
328
312
 
329
- describe "read_schema" do
313
+ describe 'read_schema' do
330
314
  before do
331
315
  @task = double('task')
332
316
  allow(Rake::Task).to receive(:[]).and_return(@task)
333
317
  allow(@task).to receive(:invoke)
334
318
  end
335
319
 
336
- it "should read schema.rb to temp file" do
320
+ it 'should read schema.rb to temp file' do
337
321
  expect(@dump).to receive(:read_entry_to_file).with('schema.rb')
338
322
  @dump.read_schema
339
323
  end
340
324
 
341
- it "should set ENV SCHEMA to temp files path" do
325
+ it 'should set ENV SCHEMA to temp files path' do
342
326
  @file = double('tempfile', :path => '/temp/123-arst')
343
327
  allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
344
328
 
@@ -346,7 +330,7 @@ describe DumpReader do
346
330
  @dump.read_schema
347
331
  end
348
332
 
349
- it "should call task db:schema:load and db:schema:dump" do
333
+ it 'should call task db:schema:load and db:schema:dump' do
350
334
  @file = double('tempfile', :path => '/temp/123-arst')
351
335
  allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
352
336
 
@@ -361,22 +345,22 @@ describe DumpReader do
361
345
  end
362
346
  end
363
347
 
364
- describe "schema" do
365
- it "should read schema" do
366
- @data = %q{create table, rows, etc...}
348
+ describe 'schema' do
349
+ it 'should read schema' do
350
+ @data = 'create table, rows, etc...'
367
351
  expect(@dump).to receive(:read_entry).with('schema.rb').and_return(@data)
368
352
  expect(@dump.schema).to eq(@data)
369
353
  end
370
354
  end
371
355
 
372
- describe "read_tables" do
373
- it "should verify connection" do
356
+ describe 'read_tables' do
357
+ it 'should verify connection' do
374
358
  allow(@dump).to receive(:config).and_return({:tables => []})
375
359
  expect(@dump).to receive(:verify_connection)
376
360
  @dump.read_tables
377
361
  end
378
362
 
379
- it "should call read_table for each table in config" do
363
+ it 'should call read_table for each table in config' do
380
364
  allow(@dump).to receive(:verify_connection)
381
365
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
382
366
 
@@ -386,8 +370,8 @@ describe DumpReader do
386
370
  @dump.read_tables
387
371
  end
388
372
 
389
- describe "when called with restore_tables" do
390
- it "should verify connection and call read_table for each table in restore_tables" do
373
+ describe 'when called with restore_tables' do
374
+ it 'should verify connection and call read_table for each table in restore_tables' do
391
375
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
392
376
 
393
377
  expect(@dump).to receive(:verify_connection)
@@ -399,7 +383,7 @@ describe DumpReader do
399
383
  end
400
384
  end
401
385
 
402
- it "should not verfiy connection or call read_table for empty restore_tables" do
386
+ it 'should not verfiy connection or call read_table for empty restore_tables' do
403
387
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
404
388
 
405
389
  expect(@dump).not_to receive(:verify_connection)
@@ -412,14 +396,14 @@ describe DumpReader do
412
396
  end
413
397
  end
414
398
 
415
- describe "read_table" do
416
- it "should not read table if no entry found for table" do
399
+ describe 'read_table' do
400
+ it 'should not read table if no entry found for table' do
417
401
  expect(@dump).to receive(:find_entry).with('first.dump').and_return(nil)
418
402
  expect(@dump).not_to receive(:quote_table_name)
419
403
  @dump.read_table('first', 10)
420
404
  end
421
405
 
422
- it "should clear table and read table if entry found for table" do
406
+ it 'should clear table and read table if entry found for table' do
423
407
  @entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
424
408
  expect(@dump).to receive(:columns_insert_sql).with('data')
425
409
  expect(@dump).to receive(:find_entry).with('first.dump').and_yield(@entry)
@@ -428,7 +412,7 @@ describe DumpReader do
428
412
  @dump.read_table('first', 10)
429
413
  end
430
414
 
431
- it "should clear schema table before writing" do
415
+ it 'should clear schema table before writing' do
432
416
  @entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
433
417
  expect(@dump).to receive(:columns_insert_sql).with('data')
434
418
  expect(@dump).to receive(:find_entry).with('schema_migrations.dump').and_yield(@entry)
@@ -437,7 +421,7 @@ describe DumpReader do
437
421
  @dump.read_table('schema_migrations', 10)
438
422
  end
439
423
 
440
- describe "reading/writing data" do
424
+ describe 'reading/writing data' do
441
425
  def create_entry(rows_count)
442
426
  @entry = StringIO.new
443
427
 
@@ -453,7 +437,7 @@ describe DumpReader do
453
437
 
454
438
  allow(@dump).to receive(:find_entry).and_yield(@entry)
455
439
  end
456
- it "should read to eof" do
440
+ it 'should read to eof' do
457
441
  create_entry(2500)
458
442
  allow(@dump).to receive(:clear_table)
459
443
  allow(@dump).to receive(:insert_into_table)
@@ -461,7 +445,11 @@ describe DumpReader do
461
445
  expect(@entry.eof?).to be_truthy
462
446
  end
463
447
 
464
- it "should try to insert rows in slices of 1000 rows" do
448
+ define :object_of_length do |n|
449
+ match{ |actual| actual.length == n }
450
+ end
451
+
452
+ it 'should try to insert rows in slices of 1000 rows' do
465
453
  create_entry(2500)
466
454
  allow(@dump).to receive(:clear_table)
467
455
  expect(@dump).to receive(:insert_into_table).with(anything, anything, object_of_length(1000)).twice
@@ -470,7 +458,7 @@ describe DumpReader do
470
458
  @dump.read_table('first', 2500)
471
459
  end
472
460
 
473
- it "should try to insert row by row if slice method fails" do
461
+ it 'should try to insert row by row if slice method fails' do
474
462
  create_entry(2500)
475
463
  allow(@dump).to receive(:clear_table)
476
464
  expect(@dump).to receive(:insert_into_table).with(anything, anything, kind_of(Array)).exactly(3).times.and_raise('sql error')
@@ -478,7 +466,7 @@ describe DumpReader do
478
466
  @dump.read_table('first', 2500)
479
467
  end
480
468
 
481
- it "should quote table, columns and values and send them to insert_into_table" do
469
+ it 'should quote table, columns and values and send them to insert_into_table' do
482
470
  create_entry(100)
483
471
  allow(@dump).to receive(:clear_table)
484
472
  expect(@dump).to receive(:quote_table_name).with('first').and_return('`first`')
@@ -493,7 +481,7 @@ describe DumpReader do
493
481
  end
494
482
  end
495
483
 
496
- describe "read_assets" do
484
+ describe 'read_assets' do
497
485
  before do
498
486
  @task = double('task')
499
487
  allow(Rake::Task).to receive(:[]).with('assets:delete').and_return(@task)
@@ -501,24 +489,24 @@ describe DumpReader do
501
489
  allow(@dump).to receive(:assets_root_link).and_yield('/tmp', 'assets')
502
490
  end
503
491
 
504
- it "should not read assets if config[:assets] is nil" do
492
+ it 'should not read assets if config[:assets] is nil' do
505
493
  allow(@dump).to receive(:config).and_return({})
506
494
  expect(@dump).not_to receive(:find_entry)
507
495
  @dump.read_assets
508
496
  end
509
497
 
510
- it "should not read assets if config[:assets] is blank" do
498
+ it 'should not read assets if config[:assets] is blank' do
511
499
  allow(@dump).to receive(:config).and_return({:assets => []})
512
500
  expect(@dump).not_to receive(:find_entry)
513
501
  @dump.read_assets
514
502
  end
515
503
 
516
- describe "deleting existing assets" do
504
+ describe 'deleting existing assets' do
517
505
  before do
518
506
  allow(@stream).to receive(:each)
519
507
  end
520
508
 
521
- it "should call assets:delete" do
509
+ it 'should call assets:delete' do
522
510
  @assets = %w[images videos]
523
511
  allow(@dump).to receive(:config).and_return({:assets => @assets})
524
512
  allow(@dump).to receive(:find_entry)
@@ -528,7 +516,7 @@ describe DumpReader do
528
516
  @dump.read_assets
529
517
  end
530
518
 
531
- it "should call assets:delete with ASSETS set to config[:assets] joined with :" do
519
+ it 'should call assets:delete with ASSETS set to config[:assets] joined with :' do
532
520
  @assets = %w[images videos]
533
521
  allow(@dump).to receive(:config).and_return({:assets => @assets})
534
522
  allow(@dump).to receive(:find_entry)
@@ -540,8 +528,8 @@ describe DumpReader do
540
528
  @dump.read_assets
541
529
  end
542
530
 
543
- describe "when called with restore_assets" do
544
- it "should delete files and dirs only in requested paths" do
531
+ describe 'when called with restore_assets' do
532
+ it 'should delete files and dirs only in requested paths' do
545
533
  @assets = %w[images videos]
546
534
  allow(@dump).to receive(:config).and_return({:assets => @assets})
547
535
 
@@ -566,7 +554,7 @@ describe DumpReader do
566
554
  end
567
555
  end
568
556
 
569
- it "should not delete any files and dirs for empty list" do
557
+ it 'should not delete any files and dirs for empty list' do
570
558
  @assets = %w[images videos]
571
559
  allow(@dump).to receive(:config).and_return({:assets => @assets})
572
560
 
@@ -585,8 +573,8 @@ describe DumpReader do
585
573
  end
586
574
  end
587
575
 
588
- describe "old style" do
589
- it "should find assets.tar" do
576
+ describe 'old style' do
577
+ it 'should find assets.tar' do
590
578
  @assets = %w[images videos]
591
579
  allow(@dump).to receive(:config).and_return({:assets => @assets})
592
580
  allow(Dir).to receive(:glob).and_return([])
@@ -602,7 +590,7 @@ describe DumpReader do
602
590
  {'images' => 0, 'videos' => 0},
603
591
  {'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
604
592
  ].each do |assets|
605
- it "should rewrite rewind method to empty method - to not raise exception, open tar and extract each entry" do
593
+ it 'should rewrite rewind method to empty method - to not raise exception, open tar and extract each entry' do
606
594
  allow(@dump).to receive(:config).and_return({:assets => assets})
607
595
  allow(Dir).to receive(:glob).and_return([])
608
596
  allow(FileUtils).to receive(:remove_entry)
@@ -626,7 +614,7 @@ describe DumpReader do
626
614
  end
627
615
  end
628
616
 
629
- describe "new style" do
617
+ describe 'new style' do
630
618
  before do
631
619
  expect(@dump).to receive(:find_entry).with('assets.tar')
632
620
  end
@@ -636,7 +624,7 @@ describe DumpReader do
636
624
  {'images' => 0, 'videos' => 0},
637
625
  {'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
638
626
  ].each do |assets|
639
- it "should extract each entry" do
627
+ it 'should extract each entry' do
640
628
  allow(@dump).to receive(:config).and_return({:assets => assets})
641
629
  allow(Dir).to receive(:glob).and_return([])
642
630
  allow(FileUtils).to receive(:remove_entry)
@@ -659,8 +647,8 @@ describe DumpReader do
659
647
  end
660
648
  end
661
649
 
662
- describe "read_asset?" do
663
- it "should create filter and call custom_pass? on it" do
650
+ describe 'read_asset?' do
651
+ it 'should create filter and call custom_pass? on it' do
664
652
  @filter = double('filter')
665
653
  allow(@filter).to receive('custom_pass?')
666
654
 
@@ -669,7 +657,7 @@ describe DumpReader do
669
657
  @dump.read_asset?('a', 'b')
670
658
  end
671
659
 
672
- it "should test path usint fnmatch" do
660
+ it 'should test path usint fnmatch' do
673
661
  DumpRake::Env.with_env(:restore_assets => '[a-b]') do
674
662
  expect(@dump.read_asset?('x/a', 'x')).to be_truthy
675
663
  expect(@dump.read_asset?('x/b/file', 'x')).to be_truthy