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
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym 'RESTful'
|
16
|
+
# end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
3
|
+
# See how all your routes lay out with "rake routes".
|
4
|
+
|
5
|
+
# You can have the root of your site routed with "root"
|
6
|
+
# root 'welcome#index'
|
7
|
+
|
8
|
+
# Example of regular route:
|
9
|
+
# get 'products/:id' => 'catalog#view'
|
10
|
+
|
11
|
+
# Example of named route that can be invoked with purchase_url(id: product.id)
|
12
|
+
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
13
|
+
|
14
|
+
# Example resource route (maps HTTP verbs to controller actions automatically):
|
15
|
+
# resources :products
|
16
|
+
|
17
|
+
# Example resource route with options:
|
18
|
+
# resources :products do
|
19
|
+
# member do
|
20
|
+
# get 'short'
|
21
|
+
# post 'toggle'
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# collection do
|
25
|
+
# get 'sold'
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Example resource route with sub-resources:
|
30
|
+
# resources :products do
|
31
|
+
# resources :comments, :sales
|
32
|
+
# resource :seller
|
33
|
+
# end
|
34
|
+
|
35
|
+
# Example resource route with more complex sub-resources:
|
36
|
+
# resources :products do
|
37
|
+
# resources :comments
|
38
|
+
# resources :sales do
|
39
|
+
# get 'recent', on: :collection
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
|
43
|
+
# Example resource route with concerns:
|
44
|
+
# concern :toggleable do
|
45
|
+
# post 'toggle'
|
46
|
+
# end
|
47
|
+
# resources :posts, concerns: :toggleable
|
48
|
+
# resources :photos, concerns: :toggleable
|
49
|
+
|
50
|
+
# Example resource route within a namespace:
|
51
|
+
# namespace :admin do
|
52
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
53
|
+
# # (app/controllers/admin/products_controller.rb)
|
54
|
+
# resources :products
|
55
|
+
# end
|
56
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 97498ce7962ef78b51283c750ba56fbb1bc7895b8e201b098c67c10954832ad9e4f18943edade5757ed4e47f693bbc0ceb2e3dc71df9f2973a20a3bcf4120b67
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 5460be29a409fb920786367be99a3c8837e1c08c2e4ad4e535fcec4b0cfdf8771658f7fa1ee3a37205bc85a12efd51a85b945a12694d76a4d303092d51359e00
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
File without changes
|
@@ -23,22 +23,22 @@ describe DumpReader do
|
|
23
23
|
describe "restore" do
|
24
24
|
it "should create selves instance and open" do
|
25
25
|
@dump = double('dump')
|
26
|
-
@dump.
|
27
|
-
DumpReader.
|
26
|
+
expect(@dump).to receive(:open)
|
27
|
+
expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
|
28
28
|
DumpReader.restore('/abc/123.tmp')
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should call dump subroutines" do
|
32
32
|
@dump = double('dump')
|
33
|
-
@dump.
|
34
|
-
@dump.
|
35
|
-
DumpReader.
|
33
|
+
allow(@dump).to receive(:open).and_yield(@dump)
|
34
|
+
allow(@dump).to receive(:silence).and_yield
|
35
|
+
allow(DumpReader).to receive(:new).and_return(@dump)
|
36
36
|
|
37
|
-
@dump.
|
38
|
-
@dump.
|
39
|
-
@dump.
|
40
|
-
@dump.
|
41
|
-
@dump.
|
37
|
+
expect(@dump).to receive(:read_config).ordered
|
38
|
+
expect(@dump).to receive(:migrate_down).ordered
|
39
|
+
expect(@dump).to receive(:read_schema).ordered
|
40
|
+
expect(@dump).to receive(:read_tables).ordered
|
41
|
+
expect(@dump).to receive(:read_assets).ordered
|
42
42
|
|
43
43
|
DumpReader.restore('/abc/123.tmp')
|
44
44
|
end
|
@@ -70,20 +70,20 @@ describe DumpReader do
|
|
70
70
|
qqq: 123
|
71
71
|
www: 345
|
72
72
|
TEXT
|
73
|
-
"#{@summary}".
|
73
|
+
expect("#{@summary}").to eq(output.gsub(/#{output[/^\s+/]}/, ' '))
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should pluralize" do
|
77
|
-
Summary.pluralize(0, 'file').
|
78
|
-
Summary.pluralize(1, 'file').
|
79
|
-
Summary.pluralize(10, 'file').
|
77
|
+
expect(Summary.pluralize(0, 'file')).to eq('0 files')
|
78
|
+
expect(Summary.pluralize(1, 'file')).to eq('1 file')
|
79
|
+
expect(Summary.pluralize(10, 'file')).to eq('10 files')
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should create selves instance and open" do
|
84
84
|
@dump = double('dump')
|
85
|
-
@dump.
|
86
|
-
DumpReader.
|
85
|
+
expect(@dump).to receive(:open)
|
86
|
+
expect(DumpReader).to receive(:new).with('/abc/123.tmp').and_return(@dump)
|
87
87
|
DumpReader.summary('/abc/123.tmp')
|
88
88
|
end
|
89
89
|
|
@@ -97,19 +97,19 @@ describe DumpReader do
|
|
97
97
|
formatted_tables = ['a: 10 rows', 'b: 20 rows', 'c: 666 rows']
|
98
98
|
|
99
99
|
@dump = double('dump')
|
100
|
-
@dump.
|
101
|
-
@dump.
|
102
|
-
DumpReader.
|
103
|
-
@dump.
|
100
|
+
allow(@dump).to receive(:config).and_return(:tables => tables, :assets => assets)
|
101
|
+
allow(@dump).to receive(:open).and_yield(@dump)
|
102
|
+
allow(DumpReader).to receive(:new).and_return(@dump)
|
103
|
+
expect(@dump).to receive(:read_config)
|
104
104
|
|
105
105
|
@summary = double('summary')
|
106
|
-
@summary.
|
107
|
-
@summary.
|
108
|
-
@summary.
|
109
|
-
@summary.
|
110
|
-
Summary.
|
106
|
+
expect(@summary).to receive(:header).with('Tables')
|
107
|
+
expect(@summary).to receive(:data).with(formatted_tables)
|
108
|
+
expect(@summary).to receive(:header).with('Assets')
|
109
|
+
expect(@summary).to receive(:data).with(formatted_assets)
|
110
|
+
allow(Summary).to receive(:new).and_return(@summary)
|
111
111
|
|
112
|
-
DumpReader.summary('/abc/123.tmp').
|
112
|
+
expect(DumpReader.summary('/abc/123.tmp')).to eq(@summary)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -120,25 +120,25 @@ describe DumpReader do
|
|
120
120
|
|
121
121
|
schema = double('schema')
|
122
122
|
schema_lines = double('schema_lines')
|
123
|
-
schema.
|
123
|
+
expect(schema).to receive(:split).with("\n").and_return(schema_lines)
|
124
124
|
|
125
125
|
@dump = double('dump')
|
126
|
-
@dump.
|
127
|
-
@dump.
|
128
|
-
@dump.
|
129
|
-
DumpReader.
|
130
|
-
@dump.
|
126
|
+
allow(@dump).to receive(:config).and_return(:tables => tables, :assets => assets)
|
127
|
+
allow(@dump).to receive(:open).and_yield(@dump)
|
128
|
+
allow(@dump).to receive(:schema).and_return(schema)
|
129
|
+
allow(DumpReader).to receive(:new).and_return(@dump)
|
130
|
+
expect(@dump).to receive(:read_config)
|
131
131
|
|
132
132
|
@summary = double('summary')
|
133
|
-
@summary.
|
134
|
-
@summary.
|
135
|
-
@summary.
|
136
|
-
@summary.
|
137
|
-
@summary.
|
138
|
-
@summary.
|
139
|
-
Summary.
|
140
|
-
|
141
|
-
DumpReader.summary('/abc/123.tmp', :schema => true).
|
133
|
+
expect(@summary).to receive(:header).with('Tables')
|
134
|
+
expect(@summary).to receive(:data).with(formatted_tables)
|
135
|
+
expect(@summary).to receive(:header).with('Assets')
|
136
|
+
expect(@summary).to receive(:data).with(formatted_assets)
|
137
|
+
expect(@summary).to receive(:header).with('Schema')
|
138
|
+
expect(@summary).to receive(:data).with(schema_lines)
|
139
|
+
allow(Summary).to receive(:new).and_return(@summary)
|
140
|
+
|
141
|
+
expect(DumpReader.summary('/abc/123.tmp', :schema => true)).to eq(@summary)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -146,13 +146,13 @@ describe DumpReader do
|
|
146
146
|
it "should set stream to gzipped tar reader" do
|
147
147
|
@gzip = double('gzip')
|
148
148
|
@stream = double('stream')
|
149
|
-
Zlib::GzipReader.
|
150
|
-
Archive::Tar::Minitar::Input.
|
149
|
+
expect(Zlib::GzipReader).to receive(:open).with(Pathname("123.tgz")).and_yield(@gzip)
|
150
|
+
expect(Archive::Tar::Minitar::Input).to receive(:open).with(@gzip).and_yield(@stream)
|
151
151
|
|
152
152
|
@dump = DumpReader.new('123.tgz')
|
153
153
|
@dump.open do |dump|
|
154
|
-
dump.
|
155
|
-
dump.stream.
|
154
|
+
expect(dump).to eq(@dump)
|
155
|
+
expect(dump.stream).to eq(@stream)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -164,60 +164,60 @@ describe DumpReader do
|
|
164
164
|
@e3 = double('e3', :full_name => 'second.dump', :read => 'second.dump_data')
|
165
165
|
@stream = [@e1, @e2, @e3]
|
166
166
|
@dump = DumpReader.new('123.tgz')
|
167
|
-
@dump.
|
167
|
+
allow(@dump).to receive(:stream).and_return(@stream)
|
168
168
|
end
|
169
169
|
|
170
170
|
describe "find_entry" do
|
171
171
|
it "should find first entry in stream equal string" do
|
172
172
|
@dump.find_entry('config') do |entry|
|
173
|
-
entry.
|
173
|
+
expect(entry).to eq(@e1)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should find first entry in stream matching regexp" do
|
178
178
|
@dump.find_entry(/\.dump$/) do |entry|
|
179
|
-
entry.
|
179
|
+
expect(entry).to eq(@e2)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should return result of block" do
|
184
|
-
@dump.find_entry(/\.dump$/) do |entry|
|
184
|
+
expect(@dump.find_entry(/\.dump$/) do |entry|
|
185
185
|
'hello'
|
186
|
-
end.
|
186
|
+
end).to eq('hello')
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
190
|
describe "read_entry" do
|
191
191
|
it "should call find_entry" do
|
192
|
-
@dump.
|
192
|
+
expect(@dump).to receive(:find_entry).with('config').and_yield(@e1)
|
193
193
|
@dump.read_entry('config')
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should read entries data" do
|
197
|
-
@dump.read_entry('config').
|
197
|
+
expect(@dump.read_entry('config')).to eq('config_data')
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
201
|
describe "read_entry_to_file" do
|
202
202
|
it "should call find_entry" do
|
203
|
-
@dump.
|
203
|
+
expect(@dump).to receive(:find_entry).with('config')
|
204
204
|
@dump.read_entry_to_file('config')
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should open temp file, write data there, rewind and yield that file" do
|
208
208
|
@entry = double('entry')
|
209
|
-
@dump.
|
209
|
+
allow(@dump).to receive(:find_entry).and_yield(@entry)
|
210
210
|
@temp = double('temp')
|
211
|
-
Tempfile.
|
211
|
+
expect(Tempfile).to receive(:open).and_yield(@temp)
|
212
212
|
|
213
|
-
@entry.
|
214
|
-
@entry.
|
215
|
-
@temp.
|
216
|
-
@temp.
|
217
|
-
@temp.
|
213
|
+
expect(@entry).to receive(:eof?).and_return(false, false, true)
|
214
|
+
expect(@entry).to receive(:read).with(4096).and_return('a' * 4096, 'b' * 1000)
|
215
|
+
expect(@temp).to receive(:write).with('a' * 4096).ordered
|
216
|
+
expect(@temp).to receive(:write).with('b' * 1000).ordered
|
217
|
+
expect(@temp).to receive(:rewind).ordered
|
218
218
|
|
219
219
|
@dump.read_entry_to_file('config') do |f|
|
220
|
-
f.
|
220
|
+
expect(f).to eq(@temp)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
end
|
@@ -227,24 +227,24 @@ describe DumpReader do
|
|
227
227
|
before do
|
228
228
|
@stream = double('stream')
|
229
229
|
@dump = DumpReader.new('123.tgz')
|
230
|
-
@dump.
|
231
|
-
Progress.
|
230
|
+
allow(@dump).to receive(:stream).and_return(@stream)
|
231
|
+
allow(Progress).to receive(:io).and_return(StringIO.new)
|
232
232
|
end
|
233
233
|
|
234
234
|
describe "read_config" do
|
235
235
|
it "should read config" do
|
236
236
|
@data = {:tables => {:first => 1}, :assets => %w[images videos]}
|
237
|
-
@dump.
|
237
|
+
expect(@dump).to receive(:read_entry).with('config').and_return(Marshal.dump(@data))
|
238
238
|
|
239
239
|
@dump.read_config
|
240
|
-
@dump.config.
|
240
|
+
expect(@dump.config).to eq(@data)
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
244
244
|
describe "migrate_down" do
|
245
245
|
it "should not invoke rake tasks or find_entry if migrate_down is 0, no or false" do
|
246
|
-
Rake::Task.
|
247
|
-
@dump.
|
246
|
+
expect(Rake::Task).not_to receive(:[])
|
247
|
+
expect(@dump).not_to receive(:find_entry)
|
248
248
|
|
249
249
|
DumpRake::Env.with_env(:migrate_down => '0') do
|
250
250
|
@dump.migrate_down
|
@@ -260,10 +260,10 @@ describe DumpReader do
|
|
260
260
|
it "should invoke db:drop and db:create if migrate_down is reset" do
|
261
261
|
@load_task = double('drop_task')
|
262
262
|
@dump_task = double('create_task')
|
263
|
-
Rake::Task.
|
264
|
-
Rake::Task.
|
265
|
-
@load_task.
|
266
|
-
@dump_task.
|
263
|
+
expect(Rake::Task).to receive(:[]).with('db:drop').and_return(@load_task)
|
264
|
+
expect(Rake::Task).to receive(:[]).with('db:create').and_return(@dump_task)
|
265
|
+
expect(@load_task).to receive(:invoke)
|
266
|
+
expect(@dump_task).to receive(:invoke)
|
267
267
|
|
268
268
|
DumpRake::Env.with_env(:migrate_down => 'reset') do
|
269
269
|
@dump.migrate_down
|
@@ -273,8 +273,8 @@ describe DumpReader do
|
|
273
273
|
[nil, '1'].each do |migrate_down_value|
|
274
274
|
describe "when migrate_down is #{migrate_down_value.inspect}" do
|
275
275
|
it "should not find_entry if table schema_migrations is not present" do
|
276
|
-
@dump.
|
277
|
-
@dump.
|
276
|
+
allow(@dump).to receive(:avaliable_tables).and_return(%w[first])
|
277
|
+
expect(@dump).not_to receive(:find_entry)
|
278
278
|
|
279
279
|
DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
|
280
280
|
@dump.migrate_down
|
@@ -282,8 +282,8 @@ describe DumpReader do
|
|
282
282
|
end
|
283
283
|
|
284
284
|
it "should find schema_migrations.dump if table schema_migrations is present" do
|
285
|
-
@dump.
|
286
|
-
@dump.
|
285
|
+
allow(@dump).to receive(:avaliable_tables).and_return(%w[schema_migrations first])
|
286
|
+
expect(@dump).to receive(:find_entry).with('schema_migrations.dump')
|
287
287
|
|
288
288
|
DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
|
289
289
|
@dump.migrate_down
|
@@ -298,29 +298,29 @@ describe DumpReader do
|
|
298
298
|
end
|
299
299
|
@entry.rewind
|
300
300
|
|
301
|
-
@dump.
|
302
|
-
@dump.
|
303
|
-
@dump.
|
301
|
+
allow(@dump).to receive(:avaliable_tables).and_return(%w[schema_migrations first])
|
302
|
+
expect(@dump).to receive(:find_entry).with('schema_migrations.dump').and_yield(@entry)
|
303
|
+
expect(@dump).to receive('table_rows').with('schema_migrations').and_return(%w[1 2 4 5 6 7].map{ |version| {'version' => version} })
|
304
304
|
|
305
305
|
@versions = []
|
306
306
|
@migrate_down_task = double('migrate_down_task')
|
307
|
-
@migrate_down_task.
|
307
|
+
expect(@migrate_down_task).to receive('invoke').exactly(3).times do
|
308
308
|
version = DumpRake::Env['VERSION']
|
309
309
|
@versions << version
|
310
310
|
if version == '6'
|
311
311
|
raise ActiveRecord::IrreversibleMigration
|
312
312
|
end
|
313
313
|
end
|
314
|
-
@migrate_down_task.
|
314
|
+
expect(@migrate_down_task).to receive('reenable').exactly(3).times
|
315
315
|
|
316
|
-
$stderr.
|
316
|
+
expect($stderr).to receive('puts').with("Irreversible migration: 6")
|
317
317
|
|
318
|
-
Rake::Task.
|
318
|
+
expect(Rake::Task).to receive(:[]).with('db:migrate:down').exactly(3).times.and_return(@migrate_down_task)
|
319
319
|
|
320
320
|
DumpRake::Env.with_env(:migrate_down => migrate_down_value) do
|
321
321
|
@dump.migrate_down
|
322
322
|
end
|
323
|
-
@versions.
|
323
|
+
expect(@versions).to eq(%w[5 6 7].reverse)
|
324
324
|
end
|
325
325
|
end
|
326
326
|
end
|
@@ -329,33 +329,33 @@ describe DumpReader do
|
|
329
329
|
describe "read_schema" do
|
330
330
|
before do
|
331
331
|
@task = double('task')
|
332
|
-
Rake::Task.
|
333
|
-
@task.
|
332
|
+
allow(Rake::Task).to receive(:[]).and_return(@task)
|
333
|
+
allow(@task).to receive(:invoke)
|
334
334
|
end
|
335
335
|
|
336
336
|
it "should read schema.rb to temp file" do
|
337
|
-
@dump.
|
337
|
+
expect(@dump).to receive(:read_entry_to_file).with('schema.rb')
|
338
338
|
@dump.read_schema
|
339
339
|
end
|
340
340
|
|
341
341
|
it "should set ENV SCHEMA to temp files path" do
|
342
342
|
@file = double('tempfile', :path => '/temp/123-arst')
|
343
|
-
@dump.
|
343
|
+
allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
|
344
344
|
|
345
|
-
DumpRake::Env.
|
345
|
+
expect(DumpRake::Env).to receive(:with_env).with('SCHEMA' => '/temp/123-arst')
|
346
346
|
@dump.read_schema
|
347
347
|
end
|
348
348
|
|
349
349
|
it "should call task db:schema:load and db:schema:dump" do
|
350
350
|
@file = double('tempfile', :path => '/temp/123-arst')
|
351
|
-
@dump.
|
351
|
+
allow(@dump).to receive(:read_entry_to_file).and_yield(@file)
|
352
352
|
|
353
353
|
@load_task = double('load_task')
|
354
354
|
@dump_task = double('dump_task')
|
355
|
-
Rake::Task.
|
356
|
-
Rake::Task.
|
357
|
-
@load_task.
|
358
|
-
@dump_task.
|
355
|
+
expect(Rake::Task).to receive(:[]).with('db:schema:load').and_return(@load_task)
|
356
|
+
expect(Rake::Task).to receive(:[]).with('db:schema:dump').and_return(@dump_task)
|
357
|
+
expect(@load_task).to receive(:invoke)
|
358
|
+
expect(@dump_task).to receive(:invoke)
|
359
359
|
|
360
360
|
@dump.read_schema
|
361
361
|
end
|
@@ -364,51 +364,76 @@ describe DumpReader do
|
|
364
364
|
describe "schema" do
|
365
365
|
it "should read schema" do
|
366
366
|
@data = %q{create table, rows, etc...}
|
367
|
-
@dump.
|
368
|
-
@dump.schema.
|
367
|
+
expect(@dump).to receive(:read_entry).with('schema.rb').and_return(@data)
|
368
|
+
expect(@dump.schema).to eq(@data)
|
369
369
|
end
|
370
370
|
end
|
371
371
|
|
372
372
|
describe "read_tables" do
|
373
373
|
it "should verify connection" do
|
374
|
-
@dump.
|
375
|
-
@dump.
|
374
|
+
allow(@dump).to receive(:config).and_return({:tables => []})
|
375
|
+
expect(@dump).to receive(:verify_connection)
|
376
376
|
@dump.read_tables
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should call read_table for each table in config" do
|
380
|
-
@dump.
|
381
|
-
@dump.
|
380
|
+
allow(@dump).to receive(:verify_connection)
|
381
|
+
allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
|
382
382
|
|
383
|
-
@dump.
|
384
|
-
@dump.
|
383
|
+
expect(@dump).to receive(:read_table).with('first', 1)
|
384
|
+
expect(@dump).to receive(:read_table).with('second', 3)
|
385
385
|
|
386
386
|
@dump.read_tables
|
387
387
|
end
|
388
|
+
|
389
|
+
describe "when called with restore_tables" do
|
390
|
+
it "should verify connection and call read_table for each table in restore_tables" do
|
391
|
+
allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
|
392
|
+
|
393
|
+
expect(@dump).to receive(:verify_connection)
|
394
|
+
expect(@dump).to receive(:read_table).with('first', 1)
|
395
|
+
expect(@dump).not_to receive(:read_table).with('second', 3)
|
396
|
+
|
397
|
+
DumpRake::Env.with_env(:restore_tables => 'first') do
|
398
|
+
@dump.read_tables
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should not verfiy connection or call read_table for empty restore_tables" do
|
403
|
+
allow(@dump).to receive(:config).and_return({:tables => {'first' => 1, 'second' => 3}})
|
404
|
+
|
405
|
+
expect(@dump).not_to receive(:verify_connection)
|
406
|
+
expect(@dump).not_to receive(:read_table)
|
407
|
+
|
408
|
+
DumpRake::Env.with_env(:restore_tables => '') do
|
409
|
+
@dump.read_tables
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
388
413
|
end
|
389
414
|
|
390
415
|
describe "read_table" do
|
391
416
|
it "should not read table if no entry found for table" do
|
392
|
-
@dump.
|
393
|
-
@dump.
|
417
|
+
expect(@dump).to receive(:find_entry).with('first.dump').and_return(nil)
|
418
|
+
expect(@dump).not_to receive(:quote_table_name)
|
394
419
|
@dump.read_table('first', 10)
|
395
420
|
end
|
396
421
|
|
397
422
|
it "should clear table and read table if entry found for table" do
|
398
423
|
@entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
|
399
|
-
@dump.
|
400
|
-
@dump.
|
401
|
-
@dump.
|
402
|
-
@dump.
|
424
|
+
expect(@dump).to receive(:columns_insert_sql).with('data')
|
425
|
+
expect(@dump).to receive(:find_entry).with('first.dump').and_yield(@entry)
|
426
|
+
expect(@dump).to receive(:quote_table_name).with('first').and_return('`first`')
|
427
|
+
expect(@dump).to receive(:clear_table).with('`first`')
|
403
428
|
@dump.read_table('first', 10)
|
404
429
|
end
|
405
430
|
|
406
431
|
it "should clear schema table before writing" do
|
407
432
|
@entry = double('entry', :to_str => Marshal.dump('data'), :eof? => true)
|
408
|
-
@dump.
|
409
|
-
@dump.
|
410
|
-
@dump.
|
411
|
-
@dump.
|
433
|
+
expect(@dump).to receive(:columns_insert_sql).with('data')
|
434
|
+
expect(@dump).to receive(:find_entry).with('schema_migrations.dump').and_yield(@entry)
|
435
|
+
expect(@dump).to receive(:quote_table_name).with('schema_migrations').and_return('`schema_migrations`')
|
436
|
+
expect(@dump).to receive(:clear_table).with('`schema_migrations`')
|
412
437
|
@dump.read_table('schema_migrations', 10)
|
413
438
|
end
|
414
439
|
|
@@ -426,43 +451,43 @@ describe DumpReader do
|
|
426
451
|
end
|
427
452
|
@entry.rewind
|
428
453
|
|
429
|
-
@dump.
|
454
|
+
allow(@dump).to receive(:find_entry).and_yield(@entry)
|
430
455
|
end
|
431
456
|
it "should read to eof" do
|
432
457
|
create_entry(2500)
|
433
|
-
@dump.
|
434
|
-
@dump.
|
458
|
+
allow(@dump).to receive(:clear_table)
|
459
|
+
allow(@dump).to receive(:insert_into_table)
|
435
460
|
@dump.read_table('first', 2500)
|
436
|
-
@entry.eof
|
461
|
+
expect(@entry.eof?).to be_truthy
|
437
462
|
end
|
438
463
|
|
439
464
|
it "should try to insert rows in slices of 1000 rows" do
|
440
465
|
create_entry(2500)
|
441
|
-
@dump.
|
442
|
-
@dump.
|
443
|
-
@dump.
|
466
|
+
allow(@dump).to receive(:clear_table)
|
467
|
+
expect(@dump).to receive(:insert_into_table).with(anything, anything, object_of_length(1000)).twice
|
468
|
+
expect(@dump).to receive(:insert_into_table).with(anything, anything, object_of_length(500)).once
|
444
469
|
|
445
470
|
@dump.read_table('first', 2500)
|
446
471
|
end
|
447
472
|
|
448
473
|
it "should try to insert row by row if slice method fails" do
|
449
474
|
create_entry(2500)
|
450
|
-
@dump.
|
451
|
-
@dump.
|
452
|
-
@dump.
|
475
|
+
allow(@dump).to receive(:clear_table)
|
476
|
+
expect(@dump).to receive(:insert_into_table).with(anything, anything, kind_of(Array)).exactly(3).times.and_raise('sql error')
|
477
|
+
expect(@dump).to receive(:insert_into_table).with(anything, anything, kind_of(String)).exactly(2500).times
|
453
478
|
@dump.read_table('first', 2500)
|
454
479
|
end
|
455
480
|
|
456
481
|
it "should quote table, columns and values and send them to insert_into_table" do
|
457
482
|
create_entry(100)
|
458
|
-
@dump.
|
459
|
-
@dump.
|
460
|
-
@dump.
|
483
|
+
allow(@dump).to receive(:clear_table)
|
484
|
+
expect(@dump).to receive(:quote_table_name).with('first').and_return('`first`')
|
485
|
+
expect(@dump).to receive(:columns_insert_sql).with(@columns).and_return('(`id`, `name`)')
|
461
486
|
@rows.each do |row|
|
462
|
-
@dump.
|
487
|
+
expect(@dump).to receive(:values_insert_sql).with(row){ |vs| vs.inspect }
|
463
488
|
end
|
464
489
|
|
465
|
-
@dump.
|
490
|
+
expect(@dump).to receive(:insert_into_table).with('`first`', '(`id`, `name`)', @rows.map(&:inspect))
|
466
491
|
@dump.read_table('first', 100)
|
467
492
|
end
|
468
493
|
end
|
@@ -471,45 +496,45 @@ describe DumpReader do
|
|
471
496
|
describe "read_assets" do
|
472
497
|
before do
|
473
498
|
@task = double('task')
|
474
|
-
Rake::Task.
|
475
|
-
@task.
|
476
|
-
@dump.
|
499
|
+
allow(Rake::Task).to receive(:[]).with('assets:delete').and_return(@task)
|
500
|
+
allow(@task).to receive(:invoke)
|
501
|
+
allow(@dump).to receive(:assets_root_link).and_yield('/tmp', 'assets')
|
477
502
|
end
|
478
503
|
|
479
504
|
it "should not read assets if config[:assets] is nil" do
|
480
|
-
@dump.
|
481
|
-
@dump.
|
505
|
+
allow(@dump).to receive(:config).and_return({})
|
506
|
+
expect(@dump).not_to receive(:find_entry)
|
482
507
|
@dump.read_assets
|
483
508
|
end
|
484
509
|
|
485
510
|
it "should not read assets if config[:assets] is blank" do
|
486
|
-
@dump.
|
487
|
-
@dump.
|
511
|
+
allow(@dump).to receive(:config).and_return({:assets => []})
|
512
|
+
expect(@dump).not_to receive(:find_entry)
|
488
513
|
@dump.read_assets
|
489
514
|
end
|
490
515
|
|
491
516
|
describe "deleting existing assets" do
|
492
517
|
before do
|
493
|
-
@stream.
|
518
|
+
allow(@stream).to receive(:each)
|
494
519
|
end
|
495
520
|
|
496
521
|
it "should call assets:delete" do
|
497
522
|
@assets = %w[images videos]
|
498
|
-
@dump.
|
499
|
-
@dump.
|
523
|
+
allow(@dump).to receive(:config).and_return({:assets => @assets})
|
524
|
+
allow(@dump).to receive(:find_entry)
|
500
525
|
|
501
|
-
@task.
|
526
|
+
expect(@task).to receive(:invoke)
|
502
527
|
|
503
528
|
@dump.read_assets
|
504
529
|
end
|
505
530
|
|
506
531
|
it "should call assets:delete with ASSETS set to config[:assets] joined with :" do
|
507
532
|
@assets = %w[images videos]
|
508
|
-
@dump.
|
509
|
-
@dump.
|
533
|
+
allow(@dump).to receive(:config).and_return({:assets => @assets})
|
534
|
+
allow(@dump).to receive(:find_entry)
|
510
535
|
|
511
|
-
|
512
|
-
DumpRake::Env[:assets].
|
536
|
+
expect(@task).to receive(:invoke) do
|
537
|
+
expect(DumpRake::Env[:assets]).to eq('images:videos')
|
513
538
|
end
|
514
539
|
|
515
540
|
@dump.read_assets
|
@@ -518,40 +543,57 @@ describe DumpReader do
|
|
518
543
|
describe "when called with restore_assets" do
|
519
544
|
it "should delete files and dirs only in requested paths" do
|
520
545
|
@assets = %w[images videos]
|
521
|
-
@dump.
|
546
|
+
allow(@dump).to receive(:config).and_return({:assets => @assets})
|
522
547
|
|
523
|
-
DumpRake::Assets.
|
524
|
-
DumpRake::Assets.
|
548
|
+
expect(DumpRake::Assets).to receive('glob_asset_children').with('images', '**/*').and_return(%w[images images/a.jpg images/b.jpg])
|
549
|
+
expect(DumpRake::Assets).to receive('glob_asset_children').with('videos', '**/*').and_return(%w[videos videos/a.mov])
|
525
550
|
|
526
|
-
@dump.
|
527
|
-
@dump.
|
528
|
-
@dump.
|
529
|
-
@dump.
|
530
|
-
@dump.
|
551
|
+
expect(@dump).to receive('read_asset?').with('images/b.jpg', DumpRake::RailsRoot).ordered.and_return(false)
|
552
|
+
expect(@dump).to receive('read_asset?').with('images/a.jpg', DumpRake::RailsRoot).ordered.and_return(true)
|
553
|
+
expect(@dump).to receive('read_asset?').with('images', DumpRake::RailsRoot).ordered.and_return(true)
|
554
|
+
expect(@dump).to receive('read_asset?').with('videos/a.mov', DumpRake::RailsRoot).ordered.and_return(false)
|
555
|
+
expect(@dump).to receive('read_asset?').with('videos', DumpRake::RailsRoot).ordered.and_return(false)
|
531
556
|
|
532
|
-
File.
|
533
|
-
File.
|
534
|
-
File.
|
535
|
-
File.
|
536
|
-
File.
|
537
|
-
Dir.
|
557
|
+
expect(File).to receive('file?').with('images/a.jpg').and_return(true)
|
558
|
+
expect(File).to receive('unlink').with('images/a.jpg')
|
559
|
+
expect(File).not_to receive('file?').with('images/b.jpg')
|
560
|
+
expect(File).to receive('file?').with('images').and_return(false)
|
561
|
+
expect(File).to receive('directory?').with('images').and_return(true)
|
562
|
+
expect(Dir).to receive('unlink').with('images').and_raise(Errno::ENOTEMPTY)
|
538
563
|
|
539
564
|
DumpRake::Env.with_env(:restore_assets => 'images/a.*:stylesheets') do
|
540
565
|
@dump.read_assets
|
541
566
|
end
|
542
567
|
end
|
568
|
+
|
569
|
+
it "should not delete any files and dirs for empty list" do
|
570
|
+
@assets = %w[images videos]
|
571
|
+
allow(@dump).to receive(:config).and_return({:assets => @assets})
|
572
|
+
|
573
|
+
expect(DumpRake::Assets).not_to receive('glob_asset_children')
|
574
|
+
|
575
|
+
expect(@dump).not_to receive('read_asset?')
|
576
|
+
|
577
|
+
expect(File).not_to receive('directory?')
|
578
|
+
expect(File).not_to receive('file?')
|
579
|
+
expect(File).not_to receive('unlink')
|
580
|
+
|
581
|
+
DumpRake::Env.with_env(:restore_assets => '') do
|
582
|
+
@dump.read_assets
|
583
|
+
end
|
584
|
+
end
|
543
585
|
end
|
544
586
|
end
|
545
587
|
|
546
588
|
describe "old style" do
|
547
589
|
it "should find assets.tar" do
|
548
590
|
@assets = %w[images videos]
|
549
|
-
@dump.
|
550
|
-
Dir.
|
551
|
-
FileUtils.
|
552
|
-
@stream.
|
591
|
+
allow(@dump).to receive(:config).and_return({:assets => @assets})
|
592
|
+
allow(Dir).to receive(:glob).and_return([])
|
593
|
+
allow(FileUtils).to receive(:remove_entry)
|
594
|
+
allow(@stream).to receive(:each)
|
553
595
|
|
554
|
-
@dump.
|
596
|
+
expect(@dump).to receive(:find_entry).with('assets.tar')
|
555
597
|
@dump.read_assets
|
556
598
|
end
|
557
599
|
|
@@ -561,23 +603,23 @@ describe DumpReader do
|
|
561
603
|
{'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
|
562
604
|
].each do |assets|
|
563
605
|
it "should rewrite rewind method to empty method - to not raise exception, open tar and extract each entry" do
|
564
|
-
@dump.
|
565
|
-
Dir.
|
566
|
-
FileUtils.
|
606
|
+
allow(@dump).to receive(:config).and_return({:assets => assets})
|
607
|
+
allow(Dir).to receive(:glob).and_return([])
|
608
|
+
allow(FileUtils).to receive(:remove_entry)
|
567
609
|
|
568
610
|
@assets_tar = double('assets_tar')
|
569
|
-
@assets_tar.
|
570
|
-
@dump.
|
611
|
+
allow(@assets_tar).to receive(:rewind).and_raise('hehe - we want to rewind to center of gzip')
|
612
|
+
allow(@dump).to receive(:find_entry).and_yield(@assets_tar)
|
571
613
|
|
572
614
|
@inp = double('inp')
|
573
|
-
each_excpectation = @inp.
|
615
|
+
each_excpectation = expect(@inp).to receive(:each)
|
574
616
|
@entries = %w[a b c d].map do |s|
|
575
617
|
file = double("file_#{s}")
|
576
618
|
each_excpectation.and_yield(file)
|
577
|
-
@inp.
|
619
|
+
expect(@inp).to receive(:extract_entry).with(DumpRake::RailsRoot, file)
|
578
620
|
file
|
579
621
|
end
|
580
|
-
Archive::Tar::Minitar.
|
622
|
+
expect(Archive::Tar::Minitar).to receive(:open).with(@assets_tar).and_yield(@inp)
|
581
623
|
|
582
624
|
@dump.read_assets
|
583
625
|
end
|
@@ -586,7 +628,7 @@ describe DumpReader do
|
|
586
628
|
|
587
629
|
describe "new style" do
|
588
630
|
before do
|
589
|
-
@dump.
|
631
|
+
expect(@dump).to receive(:find_entry).with('assets.tar')
|
590
632
|
end
|
591
633
|
|
592
634
|
[
|
@@ -595,21 +637,21 @@ describe DumpReader do
|
|
595
637
|
{'images' => {:files => 0, :total => 0}, 'videos' => {:files => 0, :total => 0}},
|
596
638
|
].each do |assets|
|
597
639
|
it "should extract each entry" do
|
598
|
-
@dump.
|
599
|
-
Dir.
|
600
|
-
FileUtils.
|
640
|
+
allow(@dump).to receive(:config).and_return({:assets => assets})
|
641
|
+
allow(Dir).to receive(:glob).and_return([])
|
642
|
+
allow(FileUtils).to receive(:remove_entry)
|
601
643
|
|
602
|
-
@dump.
|
603
|
-
each_excpectation = @stream.
|
644
|
+
expect(@dump).to receive(:assets_root_link).and_yield('/tmp/abc', 'assets')
|
645
|
+
each_excpectation = expect(@stream).to receive(:each)
|
604
646
|
@entries = %w[a b c d].map do |s|
|
605
647
|
file = double("file_#{s}", :full_name => "assets/#{s}")
|
606
648
|
each_excpectation.and_yield(file)
|
607
|
-
@stream.
|
649
|
+
expect(@stream).to receive(:extract_entry).with('/tmp/abc', file)
|
608
650
|
file
|
609
651
|
end
|
610
652
|
other_file = double('other_file', :full_name => 'other_file')
|
611
653
|
each_excpectation.and_yield(other_file)
|
612
|
-
@stream.
|
654
|
+
expect(@stream).not_to receive(:extract_entry).with('/tmp/abc', other_file)
|
613
655
|
|
614
656
|
@dump.read_assets
|
615
657
|
end
|
@@ -620,18 +662,18 @@ describe DumpReader do
|
|
620
662
|
describe "read_asset?" do
|
621
663
|
it "should create filter and call custom_pass? on it" do
|
622
664
|
@filter = double('filter')
|
623
|
-
@filter.
|
665
|
+
allow(@filter).to receive('custom_pass?')
|
624
666
|
|
625
|
-
DumpRake::Env.
|
667
|
+
expect(DumpRake::Env).to receive('filter').with(:restore_assets, DumpRake::Assets::SPLITTER).and_return(@filter)
|
626
668
|
|
627
669
|
@dump.read_asset?('a', 'b')
|
628
670
|
end
|
629
671
|
|
630
672
|
it "should test path usint fnmatch" do
|
631
673
|
DumpRake::Env.with_env(:restore_assets => '[a-b]') do
|
632
|
-
@dump.read_asset?('x/a', 'x').
|
633
|
-
@dump.read_asset?('x/b/file', 'x').
|
634
|
-
@dump.read_asset?('x/c', 'x').
|
674
|
+
expect(@dump.read_asset?('x/a', 'x')).to be_truthy
|
675
|
+
expect(@dump.read_asset?('x/b/file', 'x')).to be_truthy
|
676
|
+
expect(@dump.read_asset?('x/c', 'x')).to be_falsey
|
635
677
|
end
|
636
678
|
end
|
637
679
|
end
|