test_data 0.2.2 → 0.3.2
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 +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +42 -42
- data/LICENSE.txt +1 -1
- data/README.md +66 -44
- data/example/Gemfile.lock +142 -123
- data/lib/generators/test_data/webpacker_yaml_generator.rb +25 -11
- data/lib/test_data/configurators/webpacker_yaml.rb +11 -16
- data/lib/test_data/detects_database_existence.rb +19 -0
- data/lib/test_data/determines_databases_associated_dump_time.rb +13 -0
- data/lib/test_data/determines_when_sql_dump_was_made.rb +24 -0
- data/lib/test_data/dumps_database.rb +3 -0
- data/lib/test_data/railtie.rb +4 -0
- data/lib/test_data/rake.rb +40 -10
- data/lib/test_data/records_dump_metadata.rb +9 -0
- data/lib/test_data/version.rb +1 -1
- data/lib/test_data/warns_if_database_is_newer_than_dump.rb +32 -0
- data/lib/test_data/warns_if_dump_is_newer_than_database.rb +36 -0
- data/lib/test_data/wrap/webpacker_config.rb +42 -0
- data/lib/test_data.rb +13 -1
- data/script/test +34 -0
- data/test_data.gemspec +1 -1
- metadata +18 -5
data/example/Gemfile.lock
CHANGED
|
@@ -1,171 +1,194 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
test_data (0.
|
|
5
|
-
railties (
|
|
4
|
+
test_data (0.3.2)
|
|
5
|
+
railties (>= 6.0, < 8.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actioncable (
|
|
11
|
-
actionpack (=
|
|
12
|
-
activesupport (=
|
|
10
|
+
actioncable (7.0.2.3)
|
|
11
|
+
actionpack (= 7.0.2.3)
|
|
12
|
+
activesupport (= 7.0.2.3)
|
|
13
13
|
nio4r (~> 2.0)
|
|
14
14
|
websocket-driver (>= 0.6.1)
|
|
15
|
-
actionmailbox (
|
|
16
|
-
actionpack (=
|
|
17
|
-
activejob (=
|
|
18
|
-
activerecord (=
|
|
19
|
-
activestorage (=
|
|
20
|
-
activesupport (=
|
|
15
|
+
actionmailbox (7.0.2.3)
|
|
16
|
+
actionpack (= 7.0.2.3)
|
|
17
|
+
activejob (= 7.0.2.3)
|
|
18
|
+
activerecord (= 7.0.2.3)
|
|
19
|
+
activestorage (= 7.0.2.3)
|
|
20
|
+
activesupport (= 7.0.2.3)
|
|
21
21
|
mail (>= 2.7.1)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
net-imap
|
|
23
|
+
net-pop
|
|
24
|
+
net-smtp
|
|
25
|
+
actionmailer (7.0.2.3)
|
|
26
|
+
actionpack (= 7.0.2.3)
|
|
27
|
+
actionview (= 7.0.2.3)
|
|
28
|
+
activejob (= 7.0.2.3)
|
|
29
|
+
activesupport (= 7.0.2.3)
|
|
27
30
|
mail (~> 2.5, >= 2.5.4)
|
|
31
|
+
net-imap
|
|
32
|
+
net-pop
|
|
33
|
+
net-smtp
|
|
28
34
|
rails-dom-testing (~> 2.0)
|
|
29
|
-
actionpack (
|
|
30
|
-
actionview (=
|
|
31
|
-
activesupport (=
|
|
32
|
-
rack (~> 2.0, >= 2.0
|
|
35
|
+
actionpack (7.0.2.3)
|
|
36
|
+
actionview (= 7.0.2.3)
|
|
37
|
+
activesupport (= 7.0.2.3)
|
|
38
|
+
rack (~> 2.0, >= 2.2.0)
|
|
33
39
|
rack-test (>= 0.6.3)
|
|
34
40
|
rails-dom-testing (~> 2.0)
|
|
35
41
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
36
|
-
actiontext (
|
|
37
|
-
actionpack (=
|
|
38
|
-
activerecord (=
|
|
39
|
-
activestorage (=
|
|
40
|
-
activesupport (=
|
|
42
|
+
actiontext (7.0.2.3)
|
|
43
|
+
actionpack (= 7.0.2.3)
|
|
44
|
+
activerecord (= 7.0.2.3)
|
|
45
|
+
activestorage (= 7.0.2.3)
|
|
46
|
+
activesupport (= 7.0.2.3)
|
|
47
|
+
globalid (>= 0.6.0)
|
|
41
48
|
nokogiri (>= 1.8.5)
|
|
42
|
-
actionview (
|
|
43
|
-
activesupport (=
|
|
49
|
+
actionview (7.0.2.3)
|
|
50
|
+
activesupport (= 7.0.2.3)
|
|
44
51
|
builder (~> 3.1)
|
|
45
52
|
erubi (~> 1.4)
|
|
46
53
|
rails-dom-testing (~> 2.0)
|
|
47
54
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
48
|
-
activejob (
|
|
49
|
-
activesupport (=
|
|
55
|
+
activejob (7.0.2.3)
|
|
56
|
+
activesupport (= 7.0.2.3)
|
|
50
57
|
globalid (>= 0.3.6)
|
|
51
|
-
activemodel (
|
|
52
|
-
activesupport (=
|
|
53
|
-
activerecord (
|
|
54
|
-
activemodel (=
|
|
55
|
-
activesupport (=
|
|
56
|
-
activestorage (
|
|
57
|
-
actionpack (=
|
|
58
|
-
activejob (=
|
|
59
|
-
activerecord (=
|
|
60
|
-
activesupport (=
|
|
61
|
-
marcel (~> 1.0
|
|
62
|
-
mini_mime (
|
|
63
|
-
activesupport (
|
|
58
|
+
activemodel (7.0.2.3)
|
|
59
|
+
activesupport (= 7.0.2.3)
|
|
60
|
+
activerecord (7.0.2.3)
|
|
61
|
+
activemodel (= 7.0.2.3)
|
|
62
|
+
activesupport (= 7.0.2.3)
|
|
63
|
+
activestorage (7.0.2.3)
|
|
64
|
+
actionpack (= 7.0.2.3)
|
|
65
|
+
activejob (= 7.0.2.3)
|
|
66
|
+
activerecord (= 7.0.2.3)
|
|
67
|
+
activesupport (= 7.0.2.3)
|
|
68
|
+
marcel (~> 1.0)
|
|
69
|
+
mini_mime (>= 1.1.0)
|
|
70
|
+
activesupport (7.0.2.3)
|
|
64
71
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
65
72
|
i18n (>= 1.6, < 2)
|
|
66
73
|
minitest (>= 5.1)
|
|
67
74
|
tzinfo (~> 2.0)
|
|
68
|
-
|
|
69
|
-
addressable (2.7.0)
|
|
75
|
+
addressable (2.8.0)
|
|
70
76
|
public_suffix (>= 2.0.2, < 5.0)
|
|
71
77
|
ast (2.4.2)
|
|
72
|
-
bootsnap (1.
|
|
73
|
-
msgpack (~> 1.
|
|
78
|
+
bootsnap (1.11.1)
|
|
79
|
+
msgpack (~> 1.2)
|
|
74
80
|
builder (3.2.4)
|
|
75
|
-
capybara (3.
|
|
81
|
+
capybara (3.36.0)
|
|
76
82
|
addressable
|
|
83
|
+
matrix
|
|
77
84
|
mini_mime (>= 0.1.3)
|
|
78
85
|
nokogiri (~> 1.8)
|
|
79
86
|
rack (>= 1.6.0)
|
|
80
87
|
rack-test (>= 0.6.3)
|
|
81
88
|
regexp_parser (>= 1.5, < 3.0)
|
|
82
89
|
xpath (~> 3.2)
|
|
83
|
-
childprocess (
|
|
90
|
+
childprocess (4.1.0)
|
|
84
91
|
coderay (1.1.3)
|
|
85
|
-
concurrent-ruby (1.1.
|
|
92
|
+
concurrent-ruby (1.1.10)
|
|
86
93
|
crass (1.0.6)
|
|
87
|
-
diff-lcs (1.
|
|
94
|
+
diff-lcs (1.5.0)
|
|
95
|
+
digest (3.1.0)
|
|
88
96
|
erubi (1.10.0)
|
|
89
|
-
factory_bot (6.2.
|
|
97
|
+
factory_bot (6.2.1)
|
|
90
98
|
activesupport (>= 5.0.0)
|
|
91
99
|
factory_bot_rails (6.2.0)
|
|
92
100
|
factory_bot (~> 6.2.0)
|
|
93
101
|
railties (>= 5.0.0)
|
|
94
|
-
globalid (0.
|
|
95
|
-
activesupport (>=
|
|
96
|
-
i18n (1.
|
|
102
|
+
globalid (1.0.0)
|
|
103
|
+
activesupport (>= 5.0)
|
|
104
|
+
i18n (1.10.0)
|
|
97
105
|
concurrent-ruby (~> 1.0)
|
|
98
|
-
loofah (2.
|
|
106
|
+
loofah (2.16.0)
|
|
99
107
|
crass (~> 1.0.2)
|
|
100
108
|
nokogiri (>= 1.5.9)
|
|
101
109
|
mail (2.7.1)
|
|
102
110
|
mini_mime (>= 0.1.1)
|
|
103
|
-
marcel (1.0.
|
|
111
|
+
marcel (1.0.2)
|
|
112
|
+
matrix (0.4.2)
|
|
104
113
|
method_source (1.0.0)
|
|
105
|
-
mini_mime (1.
|
|
106
|
-
mini_portile2 (2.
|
|
107
|
-
minitest (5.
|
|
108
|
-
msgpack (1.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
mini_mime (1.1.2)
|
|
115
|
+
mini_portile2 (2.8.0)
|
|
116
|
+
minitest (5.15.0)
|
|
117
|
+
msgpack (1.5.1)
|
|
118
|
+
net-imap (0.2.3)
|
|
119
|
+
digest
|
|
120
|
+
net-protocol
|
|
121
|
+
strscan
|
|
122
|
+
net-pop (0.1.1)
|
|
123
|
+
digest
|
|
124
|
+
net-protocol
|
|
125
|
+
timeout
|
|
126
|
+
net-protocol (0.1.3)
|
|
127
|
+
timeout
|
|
128
|
+
net-smtp (0.3.1)
|
|
129
|
+
digest
|
|
130
|
+
net-protocol
|
|
131
|
+
timeout
|
|
132
|
+
nio4r (2.5.8)
|
|
133
|
+
nokogiri (1.13.3)
|
|
134
|
+
mini_portile2 (~> 2.8.0)
|
|
112
135
|
racc (~> 1.4)
|
|
113
136
|
noncommittal (0.2.0)
|
|
114
|
-
parallel (1.
|
|
115
|
-
parser (3.
|
|
137
|
+
parallel (1.22.1)
|
|
138
|
+
parser (3.1.1.0)
|
|
116
139
|
ast (~> 2.4.1)
|
|
117
|
-
pg (1.
|
|
140
|
+
pg (1.3.5)
|
|
118
141
|
pry (0.14.1)
|
|
119
142
|
coderay (~> 1.1)
|
|
120
143
|
method_source (~> 1.0)
|
|
121
144
|
pry-rails (0.3.9)
|
|
122
145
|
pry (>= 0.10.4)
|
|
123
146
|
public_suffix (4.0.6)
|
|
124
|
-
puma (5.
|
|
147
|
+
puma (5.6.4)
|
|
125
148
|
nio4r (~> 2.0)
|
|
126
|
-
racc (1.
|
|
149
|
+
racc (1.6.0)
|
|
127
150
|
rack (2.2.3)
|
|
128
151
|
rack-test (1.1.0)
|
|
129
152
|
rack (>= 1.0, < 3)
|
|
130
|
-
rails (
|
|
131
|
-
actioncable (=
|
|
132
|
-
actionmailbox (=
|
|
133
|
-
actionmailer (=
|
|
134
|
-
actionpack (=
|
|
135
|
-
actiontext (=
|
|
136
|
-
actionview (=
|
|
137
|
-
activejob (=
|
|
138
|
-
activemodel (=
|
|
139
|
-
activerecord (=
|
|
140
|
-
activestorage (=
|
|
141
|
-
activesupport (=
|
|
153
|
+
rails (7.0.2.3)
|
|
154
|
+
actioncable (= 7.0.2.3)
|
|
155
|
+
actionmailbox (= 7.0.2.3)
|
|
156
|
+
actionmailer (= 7.0.2.3)
|
|
157
|
+
actionpack (= 7.0.2.3)
|
|
158
|
+
actiontext (= 7.0.2.3)
|
|
159
|
+
actionview (= 7.0.2.3)
|
|
160
|
+
activejob (= 7.0.2.3)
|
|
161
|
+
activemodel (= 7.0.2.3)
|
|
162
|
+
activerecord (= 7.0.2.3)
|
|
163
|
+
activestorage (= 7.0.2.3)
|
|
164
|
+
activesupport (= 7.0.2.3)
|
|
142
165
|
bundler (>= 1.15.0)
|
|
143
|
-
railties (=
|
|
144
|
-
sprockets-rails (>= 2.0.0)
|
|
166
|
+
railties (= 7.0.2.3)
|
|
145
167
|
rails-dom-testing (2.0.3)
|
|
146
168
|
activesupport (>= 4.2.0)
|
|
147
169
|
nokogiri (>= 1.6)
|
|
148
|
-
rails-html-sanitizer (1.
|
|
170
|
+
rails-html-sanitizer (1.4.2)
|
|
149
171
|
loofah (~> 2.3)
|
|
150
|
-
railties (
|
|
151
|
-
actionpack (=
|
|
152
|
-
activesupport (=
|
|
172
|
+
railties (7.0.2.3)
|
|
173
|
+
actionpack (= 7.0.2.3)
|
|
174
|
+
activesupport (= 7.0.2.3)
|
|
153
175
|
method_source
|
|
154
|
-
rake (>=
|
|
176
|
+
rake (>= 12.2)
|
|
155
177
|
thor (~> 1.0)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
zeitwerk (~> 2.5)
|
|
179
|
+
rainbow (3.1.1)
|
|
180
|
+
rake (13.0.6)
|
|
181
|
+
regexp_parser (2.3.0)
|
|
159
182
|
rexml (3.2.5)
|
|
160
|
-
rspec-core (3.
|
|
161
|
-
rspec-support (~> 3.
|
|
162
|
-
rspec-expectations (3.
|
|
183
|
+
rspec-core (3.11.0)
|
|
184
|
+
rspec-support (~> 3.11.0)
|
|
185
|
+
rspec-expectations (3.11.0)
|
|
163
186
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
164
|
-
rspec-support (~> 3.
|
|
165
|
-
rspec-mocks (3.
|
|
187
|
+
rspec-support (~> 3.11.0)
|
|
188
|
+
rspec-mocks (3.11.1)
|
|
166
189
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
167
|
-
rspec-support (~> 3.
|
|
168
|
-
rspec-rails (5.
|
|
190
|
+
rspec-support (~> 3.11.0)
|
|
191
|
+
rspec-rails (5.1.1)
|
|
169
192
|
actionpack (>= 5.2)
|
|
170
193
|
activesupport (>= 5.2)
|
|
171
194
|
railties (>= 5.2)
|
|
@@ -173,50 +196,46 @@ GEM
|
|
|
173
196
|
rspec-expectations (~> 3.10)
|
|
174
197
|
rspec-mocks (~> 3.10)
|
|
175
198
|
rspec-support (~> 3.10)
|
|
176
|
-
rspec-support (3.
|
|
177
|
-
rubocop (1.
|
|
199
|
+
rspec-support (3.11.0)
|
|
200
|
+
rubocop (1.26.1)
|
|
178
201
|
parallel (~> 1.10)
|
|
179
|
-
parser (>= 3.
|
|
202
|
+
parser (>= 3.1.0.0)
|
|
180
203
|
rainbow (>= 2.2.2, < 4.0)
|
|
181
204
|
regexp_parser (>= 1.8, < 3.0)
|
|
182
205
|
rexml
|
|
183
|
-
rubocop-ast (>= 1.
|
|
206
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
|
184
207
|
ruby-progressbar (~> 1.7)
|
|
185
208
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
186
|
-
rubocop-ast (1.
|
|
187
|
-
parser (>= 3.
|
|
188
|
-
rubocop-performance (1.
|
|
209
|
+
rubocop-ast (1.17.0)
|
|
210
|
+
parser (>= 3.1.1.0)
|
|
211
|
+
rubocop-performance (1.13.3)
|
|
189
212
|
rubocop (>= 1.7.0, < 2.0)
|
|
190
213
|
rubocop-ast (>= 0.4.0)
|
|
191
214
|
ruby-progressbar (1.11.0)
|
|
192
|
-
rubyzip (2.3.
|
|
193
|
-
selenium-webdriver (
|
|
194
|
-
childprocess (>= 0.5, <
|
|
215
|
+
rubyzip (2.3.2)
|
|
216
|
+
selenium-webdriver (4.1.0)
|
|
217
|
+
childprocess (>= 0.5, < 5.0)
|
|
218
|
+
rexml (~> 3.2, >= 3.2.5)
|
|
195
219
|
rubyzip (>= 1.2.2)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
sprockets (>= 3.0.0)
|
|
203
|
-
standard (1.1.1)
|
|
204
|
-
rubocop (= 1.14.0)
|
|
205
|
-
rubocop-performance (= 1.11.2)
|
|
206
|
-
thor (1.1.0)
|
|
220
|
+
standard (1.9.1)
|
|
221
|
+
rubocop (= 1.26.1)
|
|
222
|
+
rubocop-performance (= 1.13.3)
|
|
223
|
+
strscan (3.0.1)
|
|
224
|
+
thor (1.2.1)
|
|
225
|
+
timeout (0.2.0)
|
|
207
226
|
tzinfo (2.0.4)
|
|
208
227
|
concurrent-ruby (~> 1.0)
|
|
209
|
-
unicode-display_width (2.
|
|
210
|
-
webdrivers (
|
|
228
|
+
unicode-display_width (2.1.0)
|
|
229
|
+
webdrivers (5.0.0)
|
|
211
230
|
nokogiri (~> 1.6)
|
|
212
231
|
rubyzip (>= 1.3.0)
|
|
213
|
-
selenium-webdriver (
|
|
232
|
+
selenium-webdriver (~> 4.0)
|
|
214
233
|
websocket-driver (0.7.5)
|
|
215
234
|
websocket-extensions (>= 0.1.0)
|
|
216
235
|
websocket-extensions (0.1.5)
|
|
217
236
|
xpath (3.2.0)
|
|
218
237
|
nokogiri (~> 1.8)
|
|
219
|
-
zeitwerk (2.4
|
|
238
|
+
zeitwerk (2.5.4)
|
|
220
239
|
|
|
221
240
|
PLATFORMS
|
|
222
241
|
ruby
|
|
@@ -237,4 +256,4 @@ DEPENDENCIES
|
|
|
237
256
|
webdrivers
|
|
238
257
|
|
|
239
258
|
BUNDLED WITH
|
|
240
|
-
2.
|
|
259
|
+
2.3.10
|
|
@@ -4,22 +4,36 @@ require_relative "../../test_data/generator_support"
|
|
|
4
4
|
module TestData
|
|
5
5
|
class WebpackerYamlGenerator < Rails::Generators::Base
|
|
6
6
|
AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX = /^development:/
|
|
7
|
+
AFTER_TEST_DATA_WEBPACK_STANZA_REGEX = /^test_data:\n <<: \*development/
|
|
7
8
|
|
|
8
9
|
def call
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
configurator = Configurators::WebpackerYaml.new
|
|
11
|
+
webpacker_config = Wrap::WebpackerConfig.new
|
|
12
|
+
|
|
13
|
+
if configurator.verify.looks_good?
|
|
14
|
+
TestData.log.debug "'test_data' section looks good in `config/webpacker.yml'"
|
|
11
15
|
else
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
unless webpacker_config.user_config.key?("test_data")
|
|
17
|
+
inject_into_file "config/webpacker.yml", after: AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX do
|
|
18
|
+
" &development"
|
|
19
|
+
end
|
|
20
|
+
inject_into_file "config/webpacker.yml", before: BEFORE_TEST_STANZA_REGEX do
|
|
21
|
+
<<~YAML
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
# Used in conjunction with the test_data gem
|
|
24
|
+
test_data:
|
|
25
|
+
<<: *development
|
|
26
|
+
|
|
27
|
+
YAML
|
|
28
|
+
end
|
|
29
|
+
end
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
if (missing_entries = webpacker_config.required_entries_missing_from_test_data_config)
|
|
32
|
+
inject_into_file "config/webpacker.yml", after: /^test_data:\n/ do
|
|
33
|
+
missing_entries.map { |(key, val)|
|
|
34
|
+
" #{key}: #{val.inspect}\n"
|
|
35
|
+
}.join
|
|
36
|
+
end
|
|
23
37
|
end
|
|
24
38
|
end
|
|
25
39
|
end
|
|
@@ -3,21 +3,23 @@ module TestData
|
|
|
3
3
|
class WebpackerYaml
|
|
4
4
|
def initialize
|
|
5
5
|
@generator = WebpackerYamlGenerator.new
|
|
6
|
-
@
|
|
6
|
+
@webpacker_config = Wrap::WebpackerConfig.new
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def verify
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if @webpacker_config.no_user_config_exists?
|
|
11
|
+
ConfigurationVerification.new(looks_good?: true)
|
|
12
|
+
elsif (user_config = @webpacker_config.user_config).nil?
|
|
13
|
+
ConfigurationVerification.new(problems: [
|
|
14
|
+
"`#{@webpacker_config.relative_user_config_path}' is not valid YAML"
|
|
15
|
+
])
|
|
16
|
+
elsif !user_config.key?("test_data")
|
|
15
17
|
ConfigurationVerification.new(problems: [
|
|
16
|
-
"
|
|
18
|
+
"`#{@webpacker_config.relative_user_config_path}' does not contain a `test_data' section"
|
|
17
19
|
])
|
|
18
|
-
elsif
|
|
20
|
+
elsif (entries = @webpacker_config.required_entries_missing_from_test_data_config)
|
|
19
21
|
ConfigurationVerification.new(problems: [
|
|
20
|
-
"'#{
|
|
22
|
+
"`#{@webpacker_config.relative_user_config_path}' is missing #{"entry".pluralize(entries.size)} #{entries.map { |(k, v)| "`#{k}' (default: #{v.inspect})" }.join(", ")} in its `test_data' section"
|
|
21
23
|
])
|
|
22
24
|
else
|
|
23
25
|
ConfigurationVerification.new(looks_good?: true)
|
|
@@ -27,13 +29,6 @@ module TestData
|
|
|
27
29
|
def configure
|
|
28
30
|
@generator.call
|
|
29
31
|
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def load_yaml(pathname)
|
|
34
|
-
YAML.load_file(pathname)
|
|
35
|
-
rescue
|
|
36
|
-
end
|
|
37
32
|
end
|
|
38
33
|
end
|
|
39
34
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module TestData
|
|
2
|
+
class DetectsDatabaseExistence
|
|
3
|
+
def initialize
|
|
4
|
+
@config = TestData.config
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def call
|
|
8
|
+
rows = ActiveRecord::Base.connection.execute <<~SQL
|
|
9
|
+
select datname database_name
|
|
10
|
+
from pg_catalog.pg_database
|
|
11
|
+
SQL
|
|
12
|
+
rows.any? { |row|
|
|
13
|
+
row["database_name"] == @config.database_name
|
|
14
|
+
}
|
|
15
|
+
rescue ActiveRecord::NoDatabaseError
|
|
16
|
+
false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module TestData
|
|
2
|
+
class DeterminesDatabasesAssociatedDumpTime
|
|
3
|
+
def call
|
|
4
|
+
if (last_dumped_at = ActiveRecord::InternalMetadata.find_by(key: "test_data:last_dumped_at")&.value)
|
|
5
|
+
Time.parse(last_dumped_at)
|
|
6
|
+
end
|
|
7
|
+
rescue ActiveRecord::StatementInvalid
|
|
8
|
+
# This will be raised if the DB exists but hasn't been migrated/schema-loaded
|
|
9
|
+
rescue ActiveRecord::NoDatabaseError
|
|
10
|
+
# This will be raised if the DB doesn't exist yet, which we don't need to warn about
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module TestData
|
|
2
|
+
class DeterminesWhenSqlDumpWasMade
|
|
3
|
+
def initialize
|
|
4
|
+
@config = TestData.config
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def call
|
|
8
|
+
if (last_dumped_at = find_last_dumped_value)
|
|
9
|
+
Time.zone.parse(last_dumped_at)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def find_last_dumped_value
|
|
16
|
+
return unless File.exist?(@config.non_test_data_dump_path)
|
|
17
|
+
File.open(@config.non_test_data_dump_path, "r").each_line do |line|
|
|
18
|
+
if (match = line.match(/INSERT INTO public\.ar_internal_metadata VALUES \('test_data:last_dumped_at', '([^']*)'/))
|
|
19
|
+
return match[1]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -6,9 +6,12 @@ module TestData
|
|
|
6
6
|
class DumpsDatabase
|
|
7
7
|
def initialize
|
|
8
8
|
@config = TestData.config
|
|
9
|
+
@records_dump_metadata = RecordsDumpMetadata.new
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def call
|
|
13
|
+
@records_dump_metadata.call
|
|
14
|
+
|
|
12
15
|
dump(
|
|
13
16
|
type: :schema,
|
|
14
17
|
database_name: @config.database_name,
|
data/lib/test_data/railtie.rb
CHANGED
data/lib/test_data/rake.rb
CHANGED
|
@@ -3,24 +3,25 @@ def wrong_env?
|
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
def run_in_test_data_env(task_name)
|
|
6
|
-
command = "RAILS_ENV=test_data #{Rails.root}/bin/rake #{task_name}"
|
|
6
|
+
command = "RAILS_ENV=test_data #{Rails.root}/bin/rake #{task_name} --trace"
|
|
7
7
|
unless system(command)
|
|
8
8
|
fail "An error ocurred when running: #{command}"
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def create_database_or_else_blow_up_if_its_not_empty!
|
|
13
|
+
raise unless Rails.env.test_data?
|
|
14
|
+
|
|
15
|
+
unless TestData::DetectsDatabaseExistence.new.call
|
|
16
|
+
Rake::Task["test_data:create_database"].invoke
|
|
17
|
+
end
|
|
18
|
+
|
|
13
19
|
unless TestData::DetectsDatabaseEmptiness.new.empty?
|
|
14
20
|
raise TestData::Error.new("Database '#{TestData.config.database_name}' already exists and is not empty. To re-initialize it, drop it first (e.g. `rake test_data:drop_database`)")
|
|
15
21
|
end
|
|
16
|
-
rescue TestData::Error => e
|
|
17
|
-
raise e
|
|
18
|
-
rescue
|
|
19
|
-
# Only (anticipated) cause for raise here is DB did not exist
|
|
20
|
-
Rake::Task["test_data:create_database"].invoke
|
|
21
22
|
end
|
|
22
23
|
|
|
23
|
-
desc "Verifies test_data environment looks good"
|
|
24
|
+
desc "Verifies that the test_data environment looks good"
|
|
24
25
|
task "test_data:verify_config" do
|
|
25
26
|
TestData.log.with_plain_writer do
|
|
26
27
|
config = TestData::VerifiesConfiguration.new.call
|
|
@@ -34,12 +35,12 @@ task "test_data:verify_config" do
|
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
desc "
|
|
38
|
+
desc "Installs default configuration files and snippets"
|
|
38
39
|
task "test_data:configure" do
|
|
39
40
|
TestData::InstallsConfiguration.new.call
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
desc "
|
|
43
|
+
desc "Initializes test_data's interactive database"
|
|
43
44
|
task "test_data:initialize" => ["test_data:verify_config", :environment] do
|
|
44
45
|
next run_in_test_data_env("test_data:initialize") if wrong_env?
|
|
45
46
|
|
|
@@ -59,7 +60,36 @@ task "test_data:initialize" => ["test_data:verify_config", :environment] do
|
|
|
59
60
|
MSG
|
|
60
61
|
end
|
|
61
62
|
|
|
62
|
-
desc "
|
|
63
|
+
desc "Re-initializes test_data's interactive database (by dropping and reloading it)"
|
|
64
|
+
task "test_data:reinitialize" => ["test_data:verify_config", :environment] do
|
|
65
|
+
next run_in_test_data_env("test_data:reinitialize") if wrong_env?
|
|
66
|
+
|
|
67
|
+
# Take caution only if the test_data database exists
|
|
68
|
+
if TestData::DetectsDatabaseExistence.new.call
|
|
69
|
+
TestData::WarnsIfDatabaseIsNewerThanDump.new.call
|
|
70
|
+
|
|
71
|
+
unless ENV["TEST_DATA_CONFIRM"].present?
|
|
72
|
+
confirmed = if $stdin.isatty
|
|
73
|
+
puts "This will DROP test_data database '#{TestData.config.database_name}'. Are you sure you want to re-initialize it? [yN]"
|
|
74
|
+
$stdin.gets.chomp.downcase.start_with?("y")
|
|
75
|
+
else
|
|
76
|
+
puts "'#{TestData.config.database_name}' exists. Set TEST_DATA_CONFIRM=true to drop the database and re-initialize it."
|
|
77
|
+
false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
unless confirmed
|
|
81
|
+
puts "Exiting without making any changes"
|
|
82
|
+
exit 1
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Rake::Task["test_data:drop_database"].invoke
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
Rake::Task["test_data:initialize"].invoke
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc "Initializes test_data Rails environment & configure database"
|
|
63
93
|
task "test_data:install" => ["test_data:configure", "test_data:initialize"]
|
|
64
94
|
|
|
65
95
|
desc "Dumps the interactive test_data database"
|
data/lib/test_data/version.rb
CHANGED