test_data 0.2.1 → 0.3.1

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.
data/example/Gemfile.lock CHANGED
@@ -1,171 +1,196 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- test_data (0.2.1)
5
- railties (~> 6.0)
4
+ test_data (0.3.1)
5
+ railties (>= 6.0, < 8.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.1.3.2)
11
- actionpack (= 6.1.3.2)
12
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
16
- actionpack (= 6.1.3.2)
17
- activejob (= 6.1.3.2)
18
- activerecord (= 6.1.3.2)
19
- activestorage (= 6.1.3.2)
20
- activesupport (= 6.1.3.2)
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
- actionmailer (6.1.3.2)
23
- actionpack (= 6.1.3.2)
24
- actionview (= 6.1.3.2)
25
- activejob (= 6.1.3.2)
26
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
30
- actionview (= 6.1.3.2)
31
- activesupport (= 6.1.3.2)
32
- rack (~> 2.0, >= 2.0.9)
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 (6.1.3.2)
37
- actionpack (= 6.1.3.2)
38
- activerecord (= 6.1.3.2)
39
- activestorage (= 6.1.3.2)
40
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
43
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
49
- activesupport (= 6.1.3.2)
55
+ activejob (7.0.2.3)
56
+ activesupport (= 7.0.2.3)
50
57
  globalid (>= 0.3.6)
51
- activemodel (6.1.3.2)
52
- activesupport (= 6.1.3.2)
53
- activerecord (6.1.3.2)
54
- activemodel (= 6.1.3.2)
55
- activesupport (= 6.1.3.2)
56
- activestorage (6.1.3.2)
57
- actionpack (= 6.1.3.2)
58
- activejob (= 6.1.3.2)
59
- activerecord (= 6.1.3.2)
60
- activesupport (= 6.1.3.2)
61
- marcel (~> 1.0.0)
62
- mini_mime (~> 1.0.2)
63
- activesupport (6.1.3.2)
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
- zeitwerk (~> 2.3)
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.7.5)
73
- msgpack (~> 1.0)
78
+ bootsnap (1.11.1)
79
+ msgpack (~> 1.2)
74
80
  builder (3.2.4)
75
- capybara (3.35.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 (3.0.0)
90
+ childprocess (4.1.0)
84
91
  coderay (1.1.3)
85
- concurrent-ruby (1.1.9)
92
+ concurrent-ruby (1.1.10)
86
93
  crass (1.0.6)
87
- diff-lcs (1.4.4)
94
+ diff-lcs (1.5.0)
95
+ digest (3.1.0)
88
96
  erubi (1.10.0)
89
- factory_bot (6.2.0)
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.4.2)
95
- activesupport (>= 4.2.0)
96
- i18n (1.8.10)
102
+ globalid (1.0.0)
103
+ activesupport (>= 5.0)
104
+ i18n (1.10.0)
97
105
  concurrent-ruby (~> 1.0)
98
- loofah (2.10.0)
106
+ io-wait (0.2.1)
107
+ loofah (2.15.0)
99
108
  crass (~> 1.0.2)
100
109
  nokogiri (>= 1.5.9)
101
110
  mail (2.7.1)
102
111
  mini_mime (>= 0.1.1)
103
- marcel (1.0.1)
112
+ marcel (1.0.2)
113
+ matrix (0.4.2)
104
114
  method_source (1.0.0)
105
- mini_mime (1.0.3)
106
- mini_portile2 (2.5.3)
107
- minitest (5.14.4)
108
- msgpack (1.4.2)
109
- nio4r (2.5.7)
110
- nokogiri (1.11.7)
111
- mini_portile2 (~> 2.5.0)
115
+ mini_mime (1.1.2)
116
+ mini_portile2 (2.8.0)
117
+ minitest (5.15.0)
118
+ msgpack (1.4.5)
119
+ net-imap (0.2.3)
120
+ digest
121
+ net-protocol
122
+ strscan
123
+ net-pop (0.1.1)
124
+ digest
125
+ net-protocol
126
+ timeout
127
+ net-protocol (0.1.2)
128
+ io-wait
129
+ timeout
130
+ net-smtp (0.3.1)
131
+ digest
132
+ net-protocol
133
+ timeout
134
+ nio4r (2.5.8)
135
+ nokogiri (1.13.3)
136
+ mini_portile2 (~> 2.8.0)
112
137
  racc (~> 1.4)
113
138
  noncommittal (0.2.0)
114
- parallel (1.20.1)
115
- parser (3.0.1.1)
139
+ parallel (1.22.1)
140
+ parser (3.1.1.0)
116
141
  ast (~> 2.4.1)
117
- pg (1.2.3)
142
+ pg (1.3.4)
118
143
  pry (0.14.1)
119
144
  coderay (~> 1.1)
120
145
  method_source (~> 1.0)
121
146
  pry-rails (0.3.9)
122
147
  pry (>= 0.10.4)
123
148
  public_suffix (4.0.6)
124
- puma (5.3.2)
149
+ puma (5.6.2)
125
150
  nio4r (~> 2.0)
126
- racc (1.5.2)
151
+ racc (1.6.0)
127
152
  rack (2.2.3)
128
153
  rack-test (1.1.0)
129
154
  rack (>= 1.0, < 3)
130
- rails (6.1.3.2)
131
- actioncable (= 6.1.3.2)
132
- actionmailbox (= 6.1.3.2)
133
- actionmailer (= 6.1.3.2)
134
- actionpack (= 6.1.3.2)
135
- actiontext (= 6.1.3.2)
136
- actionview (= 6.1.3.2)
137
- activejob (= 6.1.3.2)
138
- activemodel (= 6.1.3.2)
139
- activerecord (= 6.1.3.2)
140
- activestorage (= 6.1.3.2)
141
- activesupport (= 6.1.3.2)
155
+ rails (7.0.2.3)
156
+ actioncable (= 7.0.2.3)
157
+ actionmailbox (= 7.0.2.3)
158
+ actionmailer (= 7.0.2.3)
159
+ actionpack (= 7.0.2.3)
160
+ actiontext (= 7.0.2.3)
161
+ actionview (= 7.0.2.3)
162
+ activejob (= 7.0.2.3)
163
+ activemodel (= 7.0.2.3)
164
+ activerecord (= 7.0.2.3)
165
+ activestorage (= 7.0.2.3)
166
+ activesupport (= 7.0.2.3)
142
167
  bundler (>= 1.15.0)
143
- railties (= 6.1.3.2)
144
- sprockets-rails (>= 2.0.0)
168
+ railties (= 7.0.2.3)
145
169
  rails-dom-testing (2.0.3)
146
170
  activesupport (>= 4.2.0)
147
171
  nokogiri (>= 1.6)
148
- rails-html-sanitizer (1.3.0)
172
+ rails-html-sanitizer (1.4.2)
149
173
  loofah (~> 2.3)
150
- railties (6.1.3.2)
151
- actionpack (= 6.1.3.2)
152
- activesupport (= 6.1.3.2)
174
+ railties (7.0.2.3)
175
+ actionpack (= 7.0.2.3)
176
+ activesupport (= 7.0.2.3)
153
177
  method_source
154
- rake (>= 0.8.7)
178
+ rake (>= 12.2)
155
179
  thor (~> 1.0)
156
- rainbow (3.0.0)
157
- rake (13.0.3)
158
- regexp_parser (2.1.1)
180
+ zeitwerk (~> 2.5)
181
+ rainbow (3.1.1)
182
+ rake (13.0.6)
183
+ regexp_parser (2.2.1)
159
184
  rexml (3.2.5)
160
- rspec-core (3.10.1)
161
- rspec-support (~> 3.10.0)
162
- rspec-expectations (3.10.1)
185
+ rspec-core (3.11.0)
186
+ rspec-support (~> 3.11.0)
187
+ rspec-expectations (3.11.0)
163
188
  diff-lcs (>= 1.2.0, < 2.0)
164
- rspec-support (~> 3.10.0)
165
- rspec-mocks (3.10.2)
189
+ rspec-support (~> 3.11.0)
190
+ rspec-mocks (3.11.0)
166
191
  diff-lcs (>= 1.2.0, < 2.0)
167
- rspec-support (~> 3.10.0)
168
- rspec-rails (5.0.1)
192
+ rspec-support (~> 3.11.0)
193
+ rspec-rails (5.1.1)
169
194
  actionpack (>= 5.2)
170
195
  activesupport (>= 5.2)
171
196
  railties (>= 5.2)
@@ -173,50 +198,46 @@ GEM
173
198
  rspec-expectations (~> 3.10)
174
199
  rspec-mocks (~> 3.10)
175
200
  rspec-support (~> 3.10)
176
- rspec-support (3.10.2)
177
- rubocop (1.14.0)
201
+ rspec-support (3.11.0)
202
+ rubocop (1.26.0)
178
203
  parallel (~> 1.10)
179
- parser (>= 3.0.0.0)
204
+ parser (>= 3.1.0.0)
180
205
  rainbow (>= 2.2.2, < 4.0)
181
206
  regexp_parser (>= 1.8, < 3.0)
182
207
  rexml
183
- rubocop-ast (>= 1.5.0, < 2.0)
208
+ rubocop-ast (>= 1.16.0, < 2.0)
184
209
  ruby-progressbar (~> 1.7)
185
210
  unicode-display_width (>= 1.4.0, < 3.0)
186
- rubocop-ast (1.7.0)
187
- parser (>= 3.0.1.1)
188
- rubocop-performance (1.11.2)
211
+ rubocop-ast (1.16.0)
212
+ parser (>= 3.1.1.0)
213
+ rubocop-performance (1.13.3)
189
214
  rubocop (>= 1.7.0, < 2.0)
190
215
  rubocop-ast (>= 0.4.0)
191
216
  ruby-progressbar (1.11.0)
192
- rubyzip (2.3.0)
193
- selenium-webdriver (3.142.7)
194
- childprocess (>= 0.5, < 4.0)
217
+ rubyzip (2.3.2)
218
+ selenium-webdriver (4.1.0)
219
+ childprocess (>= 0.5, < 5.0)
220
+ rexml (~> 3.2, >= 3.2.5)
195
221
  rubyzip (>= 1.2.2)
196
- sprockets (4.0.2)
197
- concurrent-ruby (~> 1.0)
198
- rack (> 1, < 3)
199
- sprockets-rails (3.2.2)
200
- actionpack (>= 4.0)
201
- activesupport (>= 4.0)
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)
222
+ standard (1.9.0)
223
+ rubocop (= 1.26.0)
224
+ rubocop-performance (= 1.13.3)
225
+ strscan (3.0.1)
226
+ thor (1.2.1)
227
+ timeout (0.2.0)
207
228
  tzinfo (2.0.4)
208
229
  concurrent-ruby (~> 1.0)
209
- unicode-display_width (2.0.0)
210
- webdrivers (4.6.0)
230
+ unicode-display_width (2.1.0)
231
+ webdrivers (5.0.0)
211
232
  nokogiri (~> 1.6)
212
233
  rubyzip (>= 1.3.0)
213
- selenium-webdriver (>= 3.0, < 4.0)
234
+ selenium-webdriver (~> 4.0)
214
235
  websocket-driver (0.7.5)
215
236
  websocket-extensions (>= 0.1.0)
216
237
  websocket-extensions (0.1.5)
217
238
  xpath (3.2.0)
218
239
  nokogiri (~> 1.8)
219
- zeitwerk (2.4.2)
240
+ zeitwerk (2.5.4)
220
241
 
221
242
  PLATFORMS
222
243
  ruby
@@ -237,4 +258,4 @@ DEPENDENCIES
237
258
  webdrivers
238
259
 
239
260
  BUNDLED WITH
240
- 2.2.15
261
+ 2.3.10
@@ -0,0 +1,82 @@
1
+ # Regression test to make sure we don't load fixtures too many times
2
+
3
+ class HookCounter
4
+ def self.count
5
+ @call_count || 0
6
+ end
7
+
8
+ def self.count!
9
+ @call_count ||= 0
10
+ @call_count += 1
11
+ end
12
+ end
13
+ at_exit do
14
+ if TestData.statistics.load_rails_fixtures_count > 2 # could be 1 if :all runs first, 2 if :boops only does
15
+ raise "Rails fixture load was called #{TestData.statistics.load_rails_fixtures_count} times, shouldn't be more than 2!"
16
+ end
17
+ if HookCounter.count > 2
18
+ raise "Rails fixture load hook was called #{HookCounter.count} times, shouldn't be more than 2!"
19
+ end
20
+ end
21
+
22
+ require "test_helper"
23
+
24
+ TestData.prevent_rails_fixtures_from_loading_automatically!
25
+
26
+ TestData.config do |config|
27
+ config.after_rails_fixture_load {
28
+ HookCounter.count!
29
+ }
30
+ end
31
+
32
+ class PartialFixtureTest < ActiveSupport::TestCase
33
+ fixtures :boops
34
+
35
+ setup do
36
+ TestData.uses_rails_fixtures(self)
37
+ end
38
+
39
+ def test_has_only_boops
40
+ assert boops(:boop_1)
41
+ assert_raises(NameError) { method(:pants) }
42
+ end
43
+ end
44
+
45
+ class AllFixtureTest < ActiveSupport::TestCase
46
+ fixtures :all
47
+
48
+ setup do
49
+ TestData.uses_rails_fixtures(self)
50
+ end
51
+
52
+ def test_has_both
53
+ assert boops(:boop_1)
54
+ assert pants(:pant_1)
55
+ end
56
+ end
57
+
58
+ class AllFixtureTest2 < ActiveSupport::TestCase
59
+ fixtures :all
60
+
61
+ setup do
62
+ TestData.uses_rails_fixtures(self)
63
+ end
64
+
65
+ def test_has_both
66
+ assert boops(:boop_1)
67
+ assert pants(:pant_1)
68
+ end
69
+ end
70
+
71
+ class AllFixtureTest3 < ActiveSupport::TestCase
72
+ fixtures :all
73
+
74
+ setup do
75
+ TestData.uses_rails_fixtures(self)
76
+ end
77
+
78
+ def test_has_both
79
+ assert boops(:boop_1)
80
+ assert pants(:pant_1)
81
+ end
82
+ end
@@ -21,19 +21,22 @@ module TestData
21
21
 
22
22
  def load_requested(test_instance:)
23
23
  ActiveRecord::FixtureSet.reset_cache
24
- test_instance.instance_variable_set(:@loaded_fixtures, @already_loaded_rails_fixtures[test_instance.class])
24
+ test_instance.instance_variable_set(:@loaded_fixtures,
25
+ @already_loaded_rails_fixtures.slice(*test_instance.class.fixture_table_names))
25
26
  test_instance.instance_variable_set(:@fixture_cache, {})
26
27
  end
27
28
 
28
29
  def loaded?(test_instance:)
29
- @already_loaded_rails_fixtures[test_instance.class].present?
30
+ test_instance.class.fixture_table_names.all? { |table_name|
31
+ @already_loaded_rails_fixtures.key?(table_name)
32
+ }
30
33
  end
31
34
 
32
35
  def load(test_instance:)
33
36
  test_instance.pre_loaded_fixtures = false
34
37
  test_instance.use_transactional_tests = false
35
38
  test_instance.__test_data_gem_setup_fixtures
36
- @already_loaded_rails_fixtures[test_instance.class] = test_instance.instance_variable_get(:@loaded_fixtures)
39
+ @already_loaded_rails_fixtures = test_instance.instance_variable_get(:@loaded_fixtures)
37
40
  @statistics.count_load_rails_fixtures!
38
41
  @config.after_rails_fixture_load_hook.call
39
42
  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,
@@ -8,5 +8,9 @@ module TestData
8
8
  rake_tasks do
9
9
  load Pathname.new(__dir__).join("rake.rb")
10
10
  end
11
+
12
+ initializer "test_data.validate_data_up_to_date" do
13
+ WarnsIfDumpIsNewerThanDatabase.new.call
14
+ end
11
15
  end
12
16
  end
@@ -10,17 +10,18 @@ def run_in_test_data_env(task_name)
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 "Install default configuration files and snippets"
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 "Initialize test_data's interactive database"
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 "Initialize test_data Rails environment & configure database"
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"
@@ -0,0 +1,9 @@
1
+ module TestData
2
+ class RecordsDumpMetadata
3
+ def call
4
+ ActiveRecord::InternalMetadata
5
+ .find_or_initialize_by(key: "test_data:last_dumped_at")
6
+ .update!(value: Time.now.utc.inspect)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module TestData
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end