dump 1.0.5 → 1.0.6

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.
Files changed (42) hide show
  1. checksums.yaml +7 -15
  2. data/.rubocop_todo.yml +1 -1
  3. data/Gemfile +6 -1
  4. data/LICENSE.txt +1 -1
  5. data/README.markdown +2 -2
  6. data/dump.gemspec +2 -2
  7. data/lib/dump.rb +86 -2
  8. data/lib/{dump_rake/archive_tar_minitar_fix.rb → dump/archive_tar_minitar.rb} +0 -0
  9. data/lib/{dump_rake → dump}/assets.rb +6 -4
  10. data/lib/dump/capistrano/v2.rb +34 -34
  11. data/lib/{dump_rake → dump}/continious_timeout.rb +1 -1
  12. data/lib/{dump_rake → dump}/env.rb +4 -4
  13. data/lib/{dump_rake → dump}/env/filter.rb +1 -1
  14. data/lib/dump/rails_root.rb +19 -0
  15. data/lib/{dump_rake/dump_reader.rb → dump/reader.rb} +25 -17
  16. data/lib/{dump_rake/dump.rb → dump/snapshot.rb} +9 -5
  17. data/lib/{dump_rake → dump}/table_manipulation.rb +28 -14
  18. data/lib/{dump_rake/dump_writer.rb → dump/writer.rb} +13 -5
  19. data/lib/tasks/assets.rake +4 -4
  20. data/lib/tasks/dump.rake +10 -10
  21. data/script/update_readme +3 -3
  22. data/spec/cycle_spec.rb +78 -84
  23. data/spec/{lib/dump_rake → dump}/env/filter_spec.rb +14 -14
  24. data/spec/dump/env_spec.rb +139 -0
  25. data/spec/{lib/dump_rake → dump}/rails_root_spec.rb +11 -13
  26. data/spec/{lib/dump_rake/dump_reader_spec.rb → dump/reader_spec.rb} +89 -89
  27. data/spec/dump/snapshot_spec.rb +290 -0
  28. data/spec/{lib/dump_rake → dump}/table_manipulation_spec.rb +54 -55
  29. data/spec/{lib/dump_rake/dump_writer_spec.rb → dump/writer_spec.rb} +41 -42
  30. data/spec/dump_spec.rb +327 -0
  31. data/spec/recipes/dump_spec.rb +92 -93
  32. data/spec/spec_helper.rb +0 -3
  33. data/spec/tasks/assets_spec.rb +16 -15
  34. data/spec/tasks/dump_spec.rb +30 -29
  35. metadata +75 -98
  36. data/.autotest +0 -13
  37. data/lib/dump_rake.rb +0 -94
  38. data/lib/dump_rake/rails_root.rb +0 -13
  39. data/spec/lib/dump_rake/dump_spec.rb +0 -289
  40. data/spec/lib/dump_rake/env_spec.rb +0 -139
  41. data/spec/lib/dump_rake_spec.rb +0 -326
  42. data/spec/spec.opts +0 -4
@@ -1,25 +1,25 @@
1
1
  require 'spec_helper'
2
+ require 'dump/env/filter'
2
3
 
3
- Filter = DumpRake::Env::Filter
4
- describe Filter do
5
- it 'should pass everything if initialized with nil' do
6
- filter = Filter.new(nil)
4
+ describe Dump::Env::Filter do
5
+ it 'passes everything if initialized with nil' do
6
+ filter = described_class.new(nil)
7
7
  expect(filter.pass?('a')).to be_truthy
8
8
  expect(filter.pass?('b')).to be_truthy
9
9
  expect(filter.pass?('c')).to be_truthy
10
10
  expect(filter.pass?('d')).to be_truthy
11
11
  end
12
12
 
13
- it 'should pass only specified values' do
14
- filter = Filter.new('a,c')
13
+ it 'passes only specified values' do
14
+ filter = described_class.new('a,c')
15
15
  expect(filter.pass?('a')).to be_truthy
16
16
  expect(filter.pass?('b')).to be_falsey
17
17
  expect(filter.pass?('c')).to be_truthy
18
18
  expect(filter.pass?('d')).to be_falsey
19
19
  end
20
20
 
21
- it 'should not pass anything if initialized empty' do
22
- filter = Filter.new('')
21
+ it 'does not pass anything if initialized empty' do
22
+ filter = described_class.new('')
23
23
  expect(filter.pass?('a')).to be_falsey
24
24
  expect(filter.pass?('b')).to be_falsey
25
25
  expect(filter.pass?('c')).to be_falsey
@@ -27,16 +27,16 @@ describe Filter do
27
27
  end
28
28
 
29
29
  describe 'when initialized with -' do
30
- it 'should pass everything except specified values' do
31
- filter = Filter.new('-a,c')
30
+ it 'passes everything except specified values' do
31
+ filter = described_class.new('-a,c')
32
32
  expect(filter.pass?('a')).to be_falsey
33
33
  expect(filter.pass?('b')).to be_truthy
34
34
  expect(filter.pass?('c')).to be_falsey
35
35
  expect(filter.pass?('d')).to be_truthy
36
36
  end
37
37
 
38
- it 'should pass everything if initialized empty' do
39
- filter = Filter.new('-')
38
+ it 'passes everything if initialized empty' do
39
+ filter = described_class.new('-')
40
40
  expect(filter.pass?('a')).to be_truthy
41
41
  expect(filter.pass?('b')).to be_truthy
42
42
  expect(filter.pass?('c')).to be_truthy
@@ -45,8 +45,8 @@ describe Filter do
45
45
  end
46
46
 
47
47
  describe 'custom_pass?' do
48
- it 'should pass only when any call to block returns true' do
49
- filter = Filter.new('a,c')
48
+ it 'passes only when any call to block returns true' do
49
+ filter = described_class.new('a,c')
50
50
  expect(filter.custom_pass?{ |value| value == 'a' }).to be_truthy
51
51
  expect(filter.custom_pass?{ |value| value == 'b' }).to be_falsey
52
52
  expect(filter.custom_pass?{ |value| value == 'c' }).to be_truthy
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+ require 'dump/env'
3
+
4
+ describe Dump::Env do
5
+ def silence_warnings
6
+ old_verbose, $VERBOSE = $VERBOSE, nil
7
+ yield
8
+ ensure
9
+ $VERBOSE = old_verbose
10
+ end
11
+
12
+ before do
13
+ silence_warnings do
14
+ @old_env, ENV = ENV, {}
15
+ end
16
+ end
17
+
18
+ after do
19
+ silence_warnings do
20
+ ENV = @old_env
21
+ end
22
+ end
23
+
24
+ describe 'with_env' do
25
+ it 'sets env to new_value for duration of block' do
26
+ ENV['LIKE'] = 'old_value'
27
+
28
+ expect(ENV['LIKE']).to eq('old_value')
29
+ described_class.with_env('LIKE' => 'new_value') do
30
+ expect(ENV['LIKE']).to eq('new_value')
31
+ end
32
+ expect(ENV['LIKE']).to eq('old_value')
33
+ end
34
+
35
+ it 'uses dictionary' do
36
+ ENV['LIKE'] = 'old_value'
37
+
38
+ expect(ENV['LIKE']).to eq('old_value')
39
+ described_class.with_env(:like => 'new_value') do
40
+ expect(ENV['LIKE']).to eq('new_value')
41
+ end
42
+ expect(ENV['LIKE']).to eq('old_value')
43
+ end
44
+ end
45
+
46
+ describe '[]' do
47
+ it 'mimics ENV' do
48
+ ENV['VERSION'] = 'VERSION_value'
49
+ expect(described_class['VERSION']).to eq(ENV['VERSION'])
50
+ end
51
+
52
+ it 'returns nil on non existing env variable' do
53
+ expect(described_class['DESCRIPTON']).to eq(nil)
54
+ end
55
+
56
+ it 'gets first value that is set' do
57
+ ENV['VERSION'] = 'VERSION_value'
58
+ expect(described_class[:like]).to eq('VERSION_value')
59
+ ENV['VER'] = 'VER_value'
60
+ expect(described_class[:like]).to eq('VER_value')
61
+ ENV['LIKE'] = 'LIKE_value'
62
+ expect(described_class[:like]).to eq('LIKE_value')
63
+ end
64
+
65
+ it 'returns nil for unset variable' do
66
+ expect(described_class[:desc]).to eq(nil)
67
+ end
68
+ end
69
+
70
+ describe 'filter' do
71
+ before do
72
+ described_class.instance_variable_set(:@filters, nil)
73
+ end
74
+
75
+ it 'returns Filter' do
76
+ ENV['TABLES'] = 'a,b,c'
77
+ filter = described_class.filter('TABLES')
78
+ expect(filter).to be_instance_of(described_class::Filter)
79
+ expect(filter.invert).to be_falsey
80
+ expect(filter.values).to eq(%w[a b c])
81
+ end
82
+
83
+ it 'caches created filter' do
84
+ ENV['TABLES'] = 'a,b,c'
85
+ ENV['TABLES2'] = 'a,b,c'
86
+ expect(described_class::Filter).to receive(:new).with('a,b,c', nil).once
87
+ described_class.filter('TABLES')
88
+ described_class.filter('TABLES')
89
+ described_class.filter('TABLES2')
90
+ end
91
+ end
92
+
93
+ describe 'for_command' do
94
+ describe 'when no vars present' do
95
+ it 'returns empty hash for every command' do
96
+ expect(described_class.for_command(:create)).to eq({})
97
+ expect(described_class.for_command(:restore)).to eq({})
98
+ expect(described_class.for_command(:versions)).to eq({})
99
+ expect(described_class.for_command(:bad)).to eq({})
100
+ end
101
+
102
+ it 'returns empty hash for every command when asking for string keys' do
103
+ expect(described_class.for_command(:create, true)).to eq({})
104
+ expect(described_class.for_command(:restore, true)).to eq({})
105
+ expect(described_class.for_command(:versions, true)).to eq({})
106
+ expect(described_class.for_command(:bad, true)).to eq({})
107
+ end
108
+ end
109
+
110
+ describe 'when vars are present' do
111
+ before do
112
+ ENV['LIKE'] = 'Version'
113
+ ENV['DESC'] = 'Description'
114
+ end
115
+
116
+ it 'returns hash with symbol keys for every command' do
117
+ expect(described_class.for_command(:create)).to eq({:desc => 'Description'})
118
+ expect(described_class.for_command(:restore)).to eq({:like => 'Version'})
119
+ expect(described_class.for_command(:versions)).to eq({:like => 'Version'})
120
+ expect(described_class.for_command(:bad)).to eq({})
121
+ end
122
+
123
+ it 'returns hash with symbol keys for every command when asking for string keys' do
124
+ expect(described_class.for_command(:create, true)).to eq({'DESC' => 'Description'})
125
+ expect(described_class.for_command(:restore, true)).to eq({'LIKE' => 'Version'})
126
+ expect(described_class.for_command(:versions, true)).to eq({'LIKE' => 'Version'})
127
+ expect(described_class.for_command(:bad, true)).to eq({})
128
+ end
129
+ end
130
+ end
131
+
132
+ describe 'stringify!' do
133
+ it 'converts keys to strings' do
134
+ @env = {:desc => 'text', :tags => 'a b c', 'LEAVE' => 'none', 'OTHER' => 'data'}
135
+ described_class.stringify!(@env)
136
+ expect(@env).to eq({'DESC' => 'text', 'TAGS' => 'a b c', 'LEAVE' => 'none', 'OTHER' => 'data'})
137
+ end
138
+ end
139
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'dump/rails_root'
2
3
 
3
4
  def temp_remove_const(where, which)
4
5
  around do |example|
@@ -14,32 +15,29 @@ def temp_remove_const(where, which)
14
15
  end
15
16
  end
16
17
 
17
- describe 'RailsRoot' do
18
+ describe Dump::RailsRoot do
19
+ include described_class
20
+
18
21
  before do
19
22
  @root = double('root')
20
- expect(@root).to receive(:to_s).and_return(@root)
23
+ allow(@root).to receive(:to_s).and_return(@root)
21
24
  end
22
25
 
23
26
  temp_remove_const Object, :Rails
24
27
  temp_remove_const Object, :RAILS_ROOT
25
- temp_remove_const DumpRake, :RailsRoot
26
28
 
27
- it 'should use Rails if it is present' do
29
+ it 'uses Rails if it is present' do
28
30
  Object.const_set('Rails', double('rails'))
29
31
  expect(Rails).to receive(:root).and_return(@root)
30
- load 'dump_rake/rails_root.rb'
31
- expect(DumpRake::RailsRoot).to equal(@root)
32
+ expect(rails_root).to equal(@root)
32
33
  end
33
34
 
34
- it 'should use RAILS_ROOT if it is present' do
35
+ it 'uses RAILS_ROOT if it is present' do
35
36
  Object.const_set('RAILS_ROOT', @root)
36
- load 'dump_rake/rails_root.rb'
37
- expect(DumpRake::RailsRoot).to equal(@root)
37
+ expect(rails_root).to equal(@root)
38
38
  end
39
39
 
40
- it 'should use Dir.pwd else' do
41
- expect(Dir).to receive(:pwd).and_return(@root)
42
- load 'dump_rake/rails_root.rb'
43
- expect(DumpRake::RailsRoot).to equal(@root)
40
+ it 'fails otherwaise' do
41
+ expect{ rails_root }.to raise_error
44
42
  end
45
43
  end
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
- require 'dump_rake'
2
+ require 'dump/reader'
3
3
  require 'active_record/migration'
4
4
 
5
- DumpReader = DumpRake::DumpReader
6
- describe DumpReader do
5
+ Reader = Dump::Reader
6
+ describe Reader do
7
7
  describe 'restore' do
8
- it 'should create selves instance and open' do
8
+ it 'creates instance and opens' do
9
9
  @dump = double('dump')
10
10
  expect(@dump).to receive(:open)
11
- expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
12
- DumpReader.restore('/abc/123.tmp')
11
+ expect(described_class).to receive(:new).with('/abc/123.tmp').and_return(@dump)
12
+ described_class.restore('/abc/123.tmp')
13
13
  end
14
14
 
15
- it 'should call dump subroutines' do
15
+ it 'calls dump subroutines' do
16
16
  @dump = double('dump')
17
17
  allow(@dump).to receive(:open).and_yield(@dump)
18
18
  allow(@dump).to receive(:silence).and_yield
19
- allow(DumpReader).to receive(:new).and_return(@dump)
19
+ allow(described_class).to receive(:new).and_return(@dump)
20
20
 
21
21
  expect(@dump).to receive(:read_config).ordered
22
22
  expect(@dump).to receive(:migrate_down).ordered
@@ -24,14 +24,14 @@ describe DumpReader do
24
24
  expect(@dump).to receive(:read_tables).ordered
25
25
  expect(@dump).to receive(:read_assets).ordered
26
26
 
27
- DumpReader.restore('/abc/123.tmp')
27
+ described_class.restore('/abc/123.tmp')
28
28
  end
29
29
  end
30
30
 
31
31
  describe 'summary' do
32
- Summary = DumpReader::Summary
32
+ Summary = Reader::Summary
33
33
  describe Summary do
34
- it 'should format text' do
34
+ it 'formats text' do
35
35
  @summary = Summary.new
36
36
  @summary.header 'One'
37
37
  @summary.data(%w[fff ggg jjj ppp qqq www])
@@ -57,18 +57,18 @@ describe DumpReader do
57
57
  expect("#{@summary}").to eq(output.gsub(/#{output[/^\s+/]}/, ' '))
58
58
  end
59
59
 
60
- it 'should pluralize' do
60
+ it 'pluralizes' do
61
61
  expect(Summary.pluralize(0, 'file')).to eq('0 files')
62
62
  expect(Summary.pluralize(1, 'file')).to eq('1 file')
63
63
  expect(Summary.pluralize(10, 'file')).to eq('10 files')
64
64
  end
65
65
  end
66
66
 
67
- it 'should create selves instance and open' do
67
+ it 'creates instance and opens' do
68
68
  @dump = double('dump')
69
69
  expect(@dump).to receive(:open)
70
- expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
71
- DumpReader.summary('/abc/123.tmp')
70
+ expect(described_class).to receive(:new).with('/abc/123.tmp').and_return(@dump)
71
+ described_class.summary('/abc/123.tmp')
72
72
  end
73
73
 
74
74
  {
@@ -76,14 +76,14 @@ describe DumpReader do
76
76
  {'path/a' => 10, 'path/b' => 20} => ['path/a: 10 entries', 'path/b: 20 entries'],
77
77
  %w[path/a path/b] => %w[path/a path/b],
78
78
  }.each do |assets, formatted_assets|
79
- it 'should call dump subroutines and create summary' do
79
+ it 'calls dump subroutines and creates summary' do
80
80
  tables = {'a' => 10, 'b' => 20, 'c' => 666}
81
81
  formatted_tables = ['a: 10 rows', 'b: 20 rows', 'c: 666 rows']
82
82
 
83
83
  @dump = double('dump')
84
84
  allow(@dump).to receive(:config).and_return(:tables => tables, :assets => assets)
85
85
  allow(@dump).to receive(:open).and_yield(@dump)
86
- allow(DumpReader).to receive(:new).and_return(@dump)
86
+ allow(described_class).to receive(:new).and_return(@dump)
87
87
  expect(@dump).to receive(:read_config)
88
88
 
89
89
  @summary = double('summary')
@@ -93,11 +93,11 @@ describe DumpReader do
93
93
  expect(@summary).to receive(:data).with(formatted_assets)
94
94
  allow(Summary).to receive(:new).and_return(@summary)
95
95
 
96
- expect(DumpReader.summary('/abc/123.tmp')).to eq(@summary)
96
+ expect(described_class.summary('/abc/123.tmp')).to eq(@summary)
97
97
  end
98
98
  end
99
99
 
100
- it 'should call dump subroutines and create summary with schema' do
100
+ it 'calls dump subroutines and creates summary with schema' do
101
101
  tables = {'a' => 10, 'b' => 20, 'c' => 666}
102
102
  formatted_tables = ['a: 10 rows', 'b: 20 rows', 'c: 666 rows']
103
103
  assets = formatted_assets = %w[path/a path/b]
@@ -110,7 +110,7 @@ describe DumpReader do
110
110
  allow(@dump).to receive(:config).and_return(:tables => tables, :assets => assets)
111
111
  allow(@dump).to receive(:open).and_yield(@dump)
112
112
  allow(@dump).to receive(:schema).and_return(schema)
113
- allow(DumpReader).to receive(:new).and_return(@dump)
113
+ allow(described_class).to receive(:new).and_return(@dump)
114
114
  expect(@dump).to receive(:read_config)
115
115
 
116
116
  @summary = double('summary')
@@ -122,18 +122,18 @@ describe DumpReader do
122
122
  expect(@summary).to receive(:data).with(schema_lines)
123
123
  allow(Summary).to receive(:new).and_return(@summary)
124
124
 
125
- expect(DumpReader.summary('/abc/123.tmp', :schema => true)).to eq(@summary)
125
+ expect(described_class.summary('/abc/123.tmp', :schema => true)).to eq(@summary)
126
126
  end
127
127
  end
128
128
 
129
129
  describe 'open' do
130
- it 'should set stream to gzipped tar reader' do
130
+ it 'sets stream to gzipped tar reader' do
131
131
  @gzip = double('gzip')
132
132
  @stream = double('stream')
133
133
  expect(Zlib::GzipReader).to receive(:open).with(Pathname('123.tgz')).and_yield(@gzip)
134
134
  expect(Archive::Tar::Minitar::Input).to receive(:open).with(@gzip).and_yield(@stream)
135
135
 
136
- @dump = DumpReader.new('123.tgz')
136
+ @dump = described_class.new('123.tgz')
137
137
  @dump.open do |dump|
138
138
  expect(dump).to eq(@dump)
139
139
  expect(dump.stream).to eq(@stream)
@@ -147,24 +147,24 @@ describe DumpReader do
147
147
  @e2 = double('e2', :full_name => 'first.dump', :read => 'first.dump_data')
148
148
  @e3 = double('e3', :full_name => 'second.dump', :read => 'second.dump_data')
149
149
  @stream = [@e1, @e2, @e3]
150
- @dump = DumpReader.new('123.tgz')
150
+ @dump = described_class.new('123.tgz')
151
151
  allow(@dump).to receive(:stream).and_return(@stream)
152
152
  end
153
153
 
154
154
  describe 'find_entry' do
155
- it 'should find first entry in stream equal string' do
155
+ it 'finds first entry in stream equal string' do
156
156
  @dump.find_entry('config') do |entry|
157
157
  expect(entry).to eq(@e1)
158
158
  end
159
159
  end
160
160
 
161
- it 'should find first entry in stream matching regexp' do
161
+ it 'finds first entry in stream matching regexp' do
162
162
  @dump.find_entry(/\.dump$/) do |entry|
163
163
  expect(entry).to eq(@e2)
164
164
  end
165
165
  end
166
166
 
167
- it 'should return result of block' do
167
+ it 'returns result of block' do
168
168
  expect(@dump.find_entry(/\.dump$/) do |_entry|
169
169
  'hello'
170
170
  end).to eq('hello')
@@ -172,23 +172,23 @@ describe DumpReader do
172
172
  end
173
173
 
174
174
  describe 'read_entry' do
175
- it 'should call find_entry' do
175
+ it 'calls find_entry' do
176
176
  expect(@dump).to receive(:find_entry).with('config').and_yield(@e1)
177
177
  @dump.read_entry('config')
178
178
  end
179
179
 
180
- it 'should read entries data' do
180
+ it 'reads entries data' do
181
181
  expect(@dump.read_entry('config')).to eq('config_data')
182
182
  end
183
183
  end
184
184
 
185
185
  describe 'read_entry_to_file' do
186
- it 'should call find_entry' do
186
+ it 'calls find_entry' do
187
187
  expect(@dump).to receive(:find_entry).with('config')
188
188
  @dump.read_entry_to_file('config')
189
189
  end
190
190
 
191
- it 'should open temp file, write data there, rewind and yield that file' do
191
+ it 'opens temp file, writes data there, rewinds and yields that file' do
192
192
  @entry = double('entry')
193
193
  allow(@dump).to receive(:find_entry).and_yield(@entry)
194
194
  @temp = double('temp')
@@ -210,13 +210,13 @@ describe DumpReader do
210
210
  describe 'subroutines' do
211
211
  before do
212
212
  @stream = double('stream')
213
- @dump = DumpReader.new('123.tgz')
213
+ @dump = described_class.new('123.tgz')
214
214
  allow(@dump).to receive(:stream).and_return(@stream)
215
215
  allow(Progress).to receive(:io).and_return(StringIO.new)
216
216
  end
217
217
 
218
218
  describe 'read_config' do
219
- it 'should read config' do
219
+ it 'reads config' do
220
220
  @data = {:tables => {:first => 1}, :assets => %w[images videos]}
221
221
  expect(@dump).to receive(:read_entry).with('config').and_return(Marshal.dump(@data))
222
222
 
@@ -226,22 +226,22 @@ describe DumpReader do
226
226
  end
227
227
 
228
228
  describe 'migrate_down' do
229
- it 'should not invoke rake tasks or find_entry if migrate_down is 0, no or false' do
229
+ it 'does not invoke rake tasks or find_entry if migrate_down is 0, no or false' do
230
230
  expect(Rake::Task).not_to receive(:[])
231
231
  expect(@dump).not_to receive(:find_entry)
232
232
 
233
- DumpRake::Env.with_env(:migrate_down => '0') do
233
+ Dump::Env.with_env(:migrate_down => '0') do
234
234
  @dump.migrate_down
235
235
  end
236
- DumpRake::Env.with_env(:migrate_down => 'no') do
236
+ Dump::Env.with_env(:migrate_down => 'no') do
237
237
  @dump.migrate_down
238
238
  end
239
- DumpRake::Env.with_env(:migrate_down => 'false') do
239
+ Dump::Env.with_env(:migrate_down => 'false') do
240
240
  @dump.migrate_down
241
241
  end
242
242
  end
243
243
 
244
- it 'should invoke db:drop and db:create if migrate_down is reset' do
244
+ it 'invokes db:drop and db:create if migrate_down is reset' do
245
245
  @load_task = double('drop_task')
246
246
  @dump_task = double('create_task')
247
247
  expect(Rake::Task).to receive(:[]).with('db:drop').and_return(@load_task)
@@ -249,32 +249,32 @@ describe DumpReader do
249
249
  expect(@load_task).to receive(:invoke)
250
250
  expect(@dump_task).to receive(:invoke)
251
251
 
252
- DumpRake::Env.with_env(:migrate_down => 'reset') do
252
+ Dump::Env.with_env(:migrate_down => 'reset') do
253
253
  @dump.migrate_down
254
254
  end
255
255
  end
256
256
 
257
257
  [nil, '1'].each do |migrate_down_value|
258
258
  describe "when migrate_down is #{migrate_down_value.inspect}" do
259
- it 'should not find_entry if table schema_migrations is not present' do
259
+ it 'does not find_entry if table schema_migrations is not present' do
260
260
  allow(@dump).to receive(:avaliable_tables).and_return(%w[first])
261
261
  expect(@dump).not_to receive(:find_entry)
262
262
 
263
- DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
263
+ Dump::Env.with_env(:migrate_down => migrate_down_value) do
264
264
  @dump.migrate_down
265
265
  end
266
266
  end
267
267
 
268
- it 'should find schema_migrations.dump if table schema_migrations is present' do
268
+ it 'finds schema_migrations.dump if table schema_migrations is present' do
269
269
  allow(@dump).to receive(:avaliable_tables).and_return(%w[schema_migrations first])
270
270
  expect(@dump).to receive(:find_entry).with('schema_migrations.dump')
271
271
 
272
- DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
272
+ Dump::Env.with_env(:migrate_down => migrate_down_value) do
273
273
  @dump.migrate_down
274
274
  end
275
275
  end
276
276
 
277
- it 'should call migrate down for each version not present in schema_migrations table' do
277
+ it 'calls migrate down for each version not present in schema_migrations table' do
278
278
  @entry = StringIO.new
279
279
  Marshal.dump(['version'], @entry)
280
280
  %w[1 2 3 4].each do |i|
@@ -289,7 +289,7 @@ describe DumpReader do
289
289
  @versions = []
290
290
  @migrate_down_task = double('migrate_down_task')
291
291
  expect(@migrate_down_task).to receive('invoke').exactly(3).times do
292
- version = DumpRake::Env['VERSION']
292
+ version = Dump::Env['VERSION']
293
293
  @versions << version
294
294
  if version == '6'
295
295
  fail ActiveRecord::IrreversibleMigration
@@ -301,7 +301,7 @@ describe DumpReader do
301
301
 
302
302
  expect(Rake::Task).to receive(:[]).with('db:migrate:down').exactly(3).times.and_return(@migrate_down_task)
303
303
 
304
- DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
304
+ Dump::Env.with_env(:migrate_down => migrate_down_value) do
305
305
  @dump.migrate_down
306
306
  end
307
307
  expect(@versions).to eq(%w[5 6 7].reverse)
@@ -317,20 +317,20 @@ describe DumpReader do
317
317
  allow(@task).to receive(:invoke)
318
318
  end
319
319
 
320
- it 'should read schema.rb to temp file' do
320
+ it 'reads schema.rb to temp file' do
321
321
  expect(@dump).to receive(:read_entry_to_file).with('schema.rb')
322
322
  @dump.read_schema
323
323
  end
324
324
 
325
- it 'should set ENV SCHEMA to temp files path' do
325
+ it 'sets ENV SCHEMA to temp files path' do
326
326
  @file = double('tempfile', :path => '/temp/123-arst')
327
327
  allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
328
328
 
329
- expect(DumpRake::Env).to receive(:with_env).with('SCHEMA' => '/temp/123-arst')
329
+ expect(Dump::Env).to receive(:with_env).with('SCHEMA' => '/temp/123-arst')
330
330
  @dump.read_schema
331
331
  end
332
332
 
333
- it 'should call task db:schema:load and db:schema:dump' do
333
+ it 'calls task db:schema:load and db:schema:dump' do
334
334
  @file = double('tempfile', :path => '/temp/123-arst')
335
335
  allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
336
336
 
@@ -346,7 +346,7 @@ describe DumpReader do
346
346
  end
347
347
 
348
348
  describe 'schema' do
349
- it 'should read schema' do
349
+ it 'reads schema' do
350
350
  @data = 'create table, rows, etc...'
351
351
  expect(@dump).to receive(:read_entry).with('schema.rb').and_return(@data)
352
352
  expect(@dump.schema).to eq(@data)
@@ -354,13 +354,13 @@ describe DumpReader do
354
354
  end
355
355
 
356
356
  describe 'read_tables' do
357
- it 'should verify connection' do
357
+ it 'verifies connection' do
358
358
  allow(@dump).to receive(:config).and_return({:tables => []})
359
359
  expect(@dump).to receive(:verify_connection)
360
360
  @dump.read_tables
361
361
  end
362
362
 
363
- it 'should call read_table for each table in config' do
363
+ it 'calls read_table for each table in config' do
364
364
  allow(@dump).to receive(:verify_connection)
365
365
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
366
366
 
@@ -371,25 +371,25 @@ describe DumpReader do
371
371
  end
372
372
 
373
373
  describe 'when called with restore_tables' do
374
- it 'should verify connection and call read_table for each table in restore_tables' do
374
+ it 'verifies connection and calls read_table for each table in restore_tables' do
375
375
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
376
376
 
377
377
  expect(@dump).to receive(:verify_connection)
378
378
  expect(@dump).to receive(:read_table).with('first', 1)
379
379
  expect(@dump).not_to receive(:read_table).with('second', 3)
380
380
 
381
- DumpRake::Env.with_env(:restore_tables => 'first') do
381
+ Dump::Env.with_env(:restore_tables => 'first') do
382
382
  @dump.read_tables
383
383
  end
384
384
  end
385
385
 
386
- it 'should not verfiy connection or call read_table for empty restore_tables' do
386
+ it 'does not verfiy connection or call read_table for empty restore_tables' do
387
387
  allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
388
388
 
389
389
  expect(@dump).not_to receive(:verify_connection)
390
390
  expect(@dump).not_to receive(:read_table)
391
391
 
392
- DumpRake::Env.with_env(:restore_tables => '') do
392
+ Dump::Env.with_env(:restore_tables => '') do
393
393
  @dump.read_tables
394
394
  end
395
395
  end
@@ -397,13 +397,13 @@ describe DumpReader do
397
397
  end
398
398
 
399
399
  describe 'read_table' do
400
- it 'should not read table if no entry found for table' do
400
+ it 'does not read table if no entry found for table' do
401
401
  expect(@dump).to receive(:find_entry).with('first.dump').and_return(nil)
402
402
  expect(@dump).not_to receive(:quote_table_name)
403
403
  @dump.read_table('first', 10)
404
404
  end
405
405
 
406
- it 'should clear table and read table if entry found for table' do
406
+ it 'clears table and reads table if entry found for table' do
407
407
  @entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
408
408
  expect(@dump).to receive(:columns_insert_sql).with('data')
409
409
  expect(@dump).to receive(:find_entry).with('first.dump').and_yield(@entry)
@@ -412,7 +412,7 @@ describe DumpReader do
412
412
  @dump.read_table('first', 10)
413
413
  end
414
414
 
415
- it 'should clear schema table before writing' do
415
+ it 'clears schema table before writing' do
416
416
  @entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
417
417
  expect(@dump).to receive(:columns_insert_sql).with('data')
418
418
  expect(@dump).to receive(:find_entry).with('schema_migrations.dump').and_yield(@entry)
@@ -437,7 +437,7 @@ describe DumpReader do
437
437
 
438
438
  allow(@dump).to receive(:find_entry).and_yield(@entry)
439
439
  end
440
- it 'should read to eof' do
440
+ it 'reads to eof' do
441
441
  create_entry(2500)
442
442
  allow(@dump).to receive(:clear_table)
443
443
  allow(@dump).to receive(:insert_into_table)
@@ -449,7 +449,7 @@ describe DumpReader do
449
449
  match{ |actual| actual.length == n }
450
450
  end
451
451
 
452
- it 'should try to insert rows in slices of 1000 rows' do
452
+ it 'tries to insert rows in slices of 1000 rows' do
453
453
  create_entry(2500)
454
454
  allow(@dump).to receive(:clear_table)
455
455
  expect(@dump).to receive(:insert_into_table).with(anything, anything, object_of_length(1000)).twice
@@ -458,7 +458,7 @@ describe DumpReader do
458
458
  @dump.read_table('first', 2500)
459
459
  end
460
460
 
461
- it 'should try to insert row by row if slice method fails' do
461
+ it 'tries to insert row by row if slice method fails' do
462
462
  create_entry(2500)
463
463
  allow(@dump).to receive(:clear_table)
464
464
  expect(@dump).to receive(:insert_into_table).with(anything, anything, kind_of(Array)).exactly(3).times.and_raise('sql error')
@@ -466,7 +466,7 @@ describe DumpReader do
466
466
  @dump.read_table('first', 2500)
467
467
  end
468
468
 
469
- it 'should quote table, columns and values and send them to insert_into_table' do
469
+ it 'quotes table, columns and values and sends them to insert_into_table' do
470
470
  create_entry(100)
471
471
  allow(@dump).to receive(:clear_table)
472
472
  expect(@dump).to receive(:quote_table_name).with('first').and_return('`first`')
@@ -489,13 +489,13 @@ describe DumpReader do
489
489
  allow(@dump).to receive(:assets_root_link).and_yield('/tmp', 'assets')
490
490
  end
491
491
 
492
- it 'should not read assets if config[:assets] is nil' do
492
+ it 'does not read assets if config[:assets] is nil' do
493
493
  allow(@dump).to receive(:config).and_return({})
494
494
  expect(@dump).not_to receive(:find_entry)
495
495
  @dump.read_assets
496
496
  end
497
497
 
498
- it 'should not read assets if config[:assets] is blank' do
498
+ it 'does not read assets if config[:assets] is blank' do
499
499
  allow(@dump).to receive(:config).and_return({:assets => []})
500
500
  expect(@dump).not_to receive(:find_entry)
501
501
  @dump.read_assets
@@ -506,7 +506,7 @@ describe DumpReader do
506
506
  allow(@stream).to receive(:each)
507
507
  end
508
508
 
509
- it 'should call assets:delete' do
509
+ it 'calls assets:delete' do
510
510
  @assets = %w[images videos]
511
511
  allow(@dump).to receive(:config).and_return({:assets => @assets})
512
512
  allow(@dump).to receive(:find_entry)
@@ -516,31 +516,31 @@ describe DumpReader do
516
516
  @dump.read_assets
517
517
  end
518
518
 
519
- it 'should call assets:delete with ASSETS set to config[:assets] joined with :' do
519
+ it 'calls assets:delete with ASSETS set to config[:assets] joined with :' do
520
520
  @assets = %w[images videos]
521
521
  allow(@dump).to receive(:config).and_return({:assets => @assets})
522
522
  allow(@dump).to receive(:find_entry)
523
523
 
524
524
  expect(@task).to receive(:invoke) do
525
- expect(DumpRake::Env[:assets]).to eq('images:videos')
525
+ expect(Dump::Env[:assets]).to eq('images:videos')
526
526
  end
527
527
 
528
528
  @dump.read_assets
529
529
  end
530
530
 
531
531
  describe 'when called with restore_assets' do
532
- it 'should delete files and dirs only in requested paths' do
532
+ it 'deletes files and dirs only in requested paths' do
533
533
  @assets = %w[images videos]
534
534
  allow(@dump).to receive(:config).and_return({:assets => @assets})
535
535
 
536
- expect(DumpRake::Assets).to receive('glob_asset_children').with('images', '**/*').and_return(%w[images images/a.jpg images/b.jpg])
537
- expect(DumpRake::Assets).to receive('glob_asset_children').with('videos', '**/*').and_return(%w[videos videos/a.mov])
536
+ expect(Dump::Assets).to receive('glob_asset_children').with('images', '**/*').and_return(%w[images images/a.jpg images/b.jpg])
537
+ expect(Dump::Assets).to receive('glob_asset_children').with('videos', '**/*').and_return(%w[videos videos/a.mov])
538
538
 
539
- expect(@dump).to receive('read_asset?').with('images/b.jpg', DumpRake::RailsRoot).ordered.and_return(false)
540
- expect(@dump).to receive('read_asset?').with('images/a.jpg', DumpRake::RailsRoot).ordered.and_return(true)
541
- expect(@dump).to receive('read_asset?').with('images', DumpRake::RailsRoot).ordered.and_return(true)
542
- expect(@dump).to receive('read_asset?').with('videos/a.mov', DumpRake::RailsRoot).ordered.and_return(false)
543
- expect(@dump).to receive('read_asset?').with('videos', DumpRake::RailsRoot).ordered.and_return(false)
539
+ expect(@dump).to receive('read_asset?').with('images/b.jpg', Dump.rails_root).ordered.and_return(false)
540
+ expect(@dump).to receive('read_asset?').with('images/a.jpg', Dump.rails_root).ordered.and_return(true)
541
+ expect(@dump).to receive('read_asset?').with('images', Dump.rails_root).ordered.and_return(true)
542
+ expect(@dump).to receive('read_asset?').with('videos/a.mov', Dump.rails_root).ordered.and_return(false)
543
+ expect(@dump).to receive('read_asset?').with('videos', Dump.rails_root).ordered.and_return(false)
544
544
 
545
545
  expect(File).to receive('file?').with('images/a.jpg').and_return(true)
546
546
  expect(File).to receive('unlink').with('images/a.jpg')
@@ -549,16 +549,16 @@ describe DumpReader do
549
549
  expect(File).to receive('directory?').with('images').and_return(true)
550
550
  expect(Dir).to receive('unlink').with('images').and_raise(Errno::ENOTEMPTY)
551
551
 
552
- DumpRake::Env.with_env(:restore_assets => 'images/a.*:stylesheets') do
552
+ Dump::Env.with_env(:restore_assets => 'images/a.*:stylesheets') do
553
553
  @dump.read_assets
554
554
  end
555
555
  end
556
556
 
557
- it 'should not delete any files and dirs for empty list' do
557
+ it 'does not delete any files and dirs for empty list' do
558
558
  @assets = %w[images videos]
559
559
  allow(@dump).to receive(:config).and_return({:assets => @assets})
560
560
 
561
- expect(DumpRake::Assets).not_to receive('glob_asset_children')
561
+ expect(Dump::Assets).not_to receive('glob_asset_children')
562
562
 
563
563
  expect(@dump).not_to receive('read_asset?')
564
564
 
@@ -566,7 +566,7 @@ describe DumpReader do
566
566
  expect(File).not_to receive('file?')
567
567
  expect(File).not_to receive('unlink')
568
568
 
569
- DumpRake::Env.with_env(:restore_assets => '') do
569
+ Dump::Env.with_env(:restore_assets => '') do
570
570
  @dump.read_assets
571
571
  end
572
572
  end
@@ -574,7 +574,7 @@ describe DumpReader do
574
574
  end
575
575
 
576
576
  describe 'old style' do
577
- it 'should find assets.tar' do
577
+ it 'finds assets.tar' do
578
578
  @assets = %w[images videos]
579
579
  allow(@dump).to receive(:config).and_return({:assets => @assets})
580
580
  allow(Dir).to receive(:glob).and_return([])
@@ -590,7 +590,7 @@ describe DumpReader do
590
590
  {'images' => 0, 'videos' => 0},
591
591
  {'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
592
592
  ].each do |assets|
593
- it 'should rewrite rewind method to empty method - to not raise exception, open tar and extract each entry' do
593
+ it 'rewrites rewind method to empty method - to not raise exception, opens tar and extracts each entry' do
594
594
  allow(@dump).to receive(:config).and_return({:assets => assets})
595
595
  allow(Dir).to receive(:glob).and_return([])
596
596
  allow(FileUtils).to receive(:remove_entry)
@@ -604,7 +604,7 @@ describe DumpReader do
604
604
  @entries = %w[a b c d].map do |s|
605
605
  file = double("file_#{s}")
606
606
  each_excpectation.and_yield(file)
607
- expect(@inp).to receive(:extract_entry).with(DumpRake::RailsRoot, file)
607
+ expect(@inp).to receive(:extract_entry).with(Dump.rails_root, file)
608
608
  file
609
609
  end
610
610
  expect(Archive::Tar::Minitar).to receive(:open).with(@assets_tar).and_yield(@inp)
@@ -624,7 +624,7 @@ describe DumpReader do
624
624
  {'images' => 0, 'videos' => 0},
625
625
  {'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
626
626
  ].each do |assets|
627
- it 'should extract each entry' do
627
+ it 'extracts each entry' do
628
628
  allow(@dump).to receive(:config).and_return({:assets => assets})
629
629
  allow(Dir).to receive(:glob).and_return([])
630
630
  allow(FileUtils).to receive(:remove_entry)
@@ -648,17 +648,17 @@ describe DumpReader do
648
648
  end
649
649
 
650
650
  describe 'read_asset?' do
651
- it 'should create filter and call custom_pass? on it' do
651
+ it 'creates filter and call custom_pass? on it' do
652
652
  @filter = double('filter')
653
653
  allow(@filter).to receive('custom_pass?')
654
654
 
655
- expect(DumpRake::Env).to receive('filter').with(:restore_assets, DumpRake::Assets::SPLITTER).and_return(@filter)
655
+ expect(Dump::Env).to receive('filter').with(:restore_assets, Dump::Assets::SPLITTER).and_return(@filter)
656
656
 
657
657
  @dump.read_asset?('a', 'b')
658
658
  end
659
659
 
660
- it 'should test path usint fnmatch' do
661
- DumpRake::Env.with_env(:restore_assets => '[a-b]') do
660
+ it 'tests path usint fnmatch' do
661
+ Dump::Env.with_env(:restore_assets => '[a-b]') do
662
662
  expect(@dump.read_asset?('x/a', 'x')).to be_truthy
663
663
  expect(@dump.read_asset?('x/b/file', 'x')).to be_truthy
664
664
  expect(@dump.read_asset?('x/c', 'x')).to be_falsey