test_data 0.0.2 → 0.1.0

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile.lock +15 -15
  4. data/LICENSE.txt +1 -6
  5. data/README.md +652 -276
  6. data/example/Gemfile.lock +73 -73
  7. data/example/test/integration/better_mode_switching_demo_test.rb +4 -0
  8. data/example/test/integration/parallel_boops_with_fixtures_test.rb +2 -2
  9. data/example/test/integration/parallel_boops_without_fixtures_test.rb +2 -2
  10. data/example/test/integration/rails_fixtures_double_load_test.rb +10 -0
  11. data/example/test/integration/rails_fixtures_override_test.rb +127 -0
  12. data/example/test/integration/transaction_committing_boops_test.rb +14 -3
  13. data/example/test/test_helper.rb +2 -2
  14. data/lib/generators/test_data/cable_yaml_generator.rb +18 -0
  15. data/lib/generators/test_data/database_yaml_generator.rb +2 -3
  16. data/lib/generators/test_data/environment_file_generator.rb +3 -0
  17. data/lib/generators/test_data/initializer_generator.rb +7 -0
  18. data/lib/generators/test_data/secrets_yaml_generator.rb +19 -0
  19. data/lib/generators/test_data/webpacker_yaml_generator.rb +3 -2
  20. data/lib/test_data.rb +5 -0
  21. data/lib/test_data/active_record_ext.rb +11 -0
  22. data/lib/test_data/config.rb +14 -2
  23. data/lib/test_data/configurators.rb +2 -0
  24. data/lib/test_data/configurators/cable_yaml.rb +25 -0
  25. data/lib/test_data/configurators/environment_file.rb +3 -2
  26. data/lib/test_data/configurators/initializer.rb +3 -2
  27. data/lib/test_data/configurators/secrets_yaml.rb +25 -0
  28. data/lib/test_data/configurators/webpacker_yaml.rb +4 -3
  29. data/lib/test_data/dumps_database.rb +24 -1
  30. data/lib/test_data/generator_support.rb +3 -0
  31. data/lib/test_data/loads_database_dumps.rb +1 -1
  32. data/lib/test_data/log.rb +19 -1
  33. data/lib/test_data/rake.rb +16 -6
  34. data/lib/test_data/statistics.rb +6 -1
  35. data/lib/test_data/transactional_data_loader.rb +156 -46
  36. data/lib/test_data/version.rb +1 -1
  37. data/script/test +11 -0
  38. data/test_data.gemspec +1 -1
  39. metadata +11 -3
data/example/Gemfile.lock CHANGED
@@ -7,60 +7,60 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.1.3.1)
11
- actionpack (= 6.1.3.1)
12
- activesupport (= 6.1.3.1)
10
+ actioncable (6.1.3.2)
11
+ actionpack (= 6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.1.3.1)
16
- actionpack (= 6.1.3.1)
17
- activejob (= 6.1.3.1)
18
- activerecord (= 6.1.3.1)
19
- activestorage (= 6.1.3.1)
20
- activesupport (= 6.1.3.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)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.1.3.1)
23
- actionpack (= 6.1.3.1)
24
- actionview (= 6.1.3.1)
25
- activejob (= 6.1.3.1)
26
- activesupport (= 6.1.3.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)
27
27
  mail (~> 2.5, >= 2.5.4)
28
28
  rails-dom-testing (~> 2.0)
29
- actionpack (6.1.3.1)
30
- actionview (= 6.1.3.1)
31
- activesupport (= 6.1.3.1)
29
+ actionpack (6.1.3.2)
30
+ actionview (= 6.1.3.2)
31
+ activesupport (= 6.1.3.2)
32
32
  rack (~> 2.0, >= 2.0.9)
33
33
  rack-test (>= 0.6.3)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.1.3.1)
37
- actionpack (= 6.1.3.1)
38
- activerecord (= 6.1.3.1)
39
- activestorage (= 6.1.3.1)
40
- activesupport (= 6.1.3.1)
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)
41
41
  nokogiri (>= 1.8.5)
42
- actionview (6.1.3.1)
43
- activesupport (= 6.1.3.1)
42
+ actionview (6.1.3.2)
43
+ activesupport (= 6.1.3.2)
44
44
  builder (~> 3.1)
45
45
  erubi (~> 1.4)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.1.3.1)
49
- activesupport (= 6.1.3.1)
48
+ activejob (6.1.3.2)
49
+ activesupport (= 6.1.3.2)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.1.3.1)
52
- activesupport (= 6.1.3.1)
53
- activerecord (6.1.3.1)
54
- activemodel (= 6.1.3.1)
55
- activesupport (= 6.1.3.1)
56
- activestorage (6.1.3.1)
57
- actionpack (= 6.1.3.1)
58
- activejob (= 6.1.3.1)
59
- activerecord (= 6.1.3.1)
60
- activesupport (= 6.1.3.1)
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
61
  marcel (~> 1.0.0)
62
62
  mini_mime (~> 1.0.2)
63
- activesupport (6.1.3.1)
63
+ activesupport (6.1.3.2)
64
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
65
65
  i18n (>= 1.6, < 2)
66
66
  minitest (>= 5.1)
@@ -69,7 +69,7 @@ GEM
69
69
  addressable (2.7.0)
70
70
  public_suffix (>= 2.0.2, < 5.0)
71
71
  ast (2.4.2)
72
- bootsnap (1.7.3)
72
+ bootsnap (1.7.5)
73
73
  msgpack (~> 1.0)
74
74
  builder (3.2.4)
75
75
  capybara (3.35.3)
@@ -82,20 +82,20 @@ GEM
82
82
  xpath (~> 3.2)
83
83
  childprocess (3.0.0)
84
84
  coderay (1.1.3)
85
- concurrent-ruby (1.1.8)
85
+ concurrent-ruby (1.1.9)
86
86
  crass (1.0.6)
87
87
  diff-lcs (1.4.4)
88
88
  erubi (1.10.0)
89
- factory_bot (6.1.0)
89
+ factory_bot (6.2.0)
90
90
  activesupport (>= 5.0.0)
91
- factory_bot_rails (6.1.0)
92
- factory_bot (~> 6.1.0)
91
+ factory_bot_rails (6.2.0)
92
+ factory_bot (~> 6.2.0)
93
93
  railties (>= 5.0.0)
94
94
  globalid (0.4.2)
95
95
  activesupport (>= 4.2.0)
96
96
  i18n (1.8.10)
97
97
  concurrent-ruby (~> 1.0)
98
- loofah (2.9.1)
98
+ loofah (2.10.0)
99
99
  crass (~> 1.0.2)
100
100
  nokogiri (>= 1.5.9)
101
101
  mail (2.7.1)
@@ -103,16 +103,16 @@ GEM
103
103
  marcel (1.0.1)
104
104
  method_source (1.0.0)
105
105
  mini_mime (1.0.3)
106
- mini_portile2 (2.5.0)
106
+ mini_portile2 (2.5.3)
107
107
  minitest (5.14.4)
108
108
  msgpack (1.4.2)
109
109
  nio4r (2.5.7)
110
- nokogiri (1.11.3)
110
+ nokogiri (1.11.7)
111
111
  mini_portile2 (~> 2.5.0)
112
112
  racc (~> 1.4)
113
113
  noncommittal (0.2.0)
114
114
  parallel (1.20.1)
115
- parser (3.0.1.0)
115
+ parser (3.0.1.1)
116
116
  ast (~> 2.4.1)
117
117
  pg (1.2.3)
118
118
  pry (0.14.1)
@@ -121,35 +121,35 @@ GEM
121
121
  pry-rails (0.3.9)
122
122
  pry (>= 0.10.4)
123
123
  public_suffix (4.0.6)
124
- puma (5.2.2)
124
+ puma (5.3.2)
125
125
  nio4r (~> 2.0)
126
126
  racc (1.5.2)
127
127
  rack (2.2.3)
128
128
  rack-test (1.1.0)
129
129
  rack (>= 1.0, < 3)
130
- rails (6.1.3.1)
131
- actioncable (= 6.1.3.1)
132
- actionmailbox (= 6.1.3.1)
133
- actionmailer (= 6.1.3.1)
134
- actionpack (= 6.1.3.1)
135
- actiontext (= 6.1.3.1)
136
- actionview (= 6.1.3.1)
137
- activejob (= 6.1.3.1)
138
- activemodel (= 6.1.3.1)
139
- activerecord (= 6.1.3.1)
140
- activestorage (= 6.1.3.1)
141
- activesupport (= 6.1.3.1)
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)
142
142
  bundler (>= 1.15.0)
143
- railties (= 6.1.3.1)
143
+ railties (= 6.1.3.2)
144
144
  sprockets-rails (>= 2.0.0)
145
145
  rails-dom-testing (2.0.3)
146
146
  activesupport (>= 4.2.0)
147
147
  nokogiri (>= 1.6)
148
148
  rails-html-sanitizer (1.3.0)
149
149
  loofah (~> 2.3)
150
- railties (6.1.3.1)
151
- actionpack (= 6.1.3.1)
152
- activesupport (= 6.1.3.1)
150
+ railties (6.1.3.2)
151
+ actionpack (= 6.1.3.2)
152
+ activesupport (= 6.1.3.2)
153
153
  method_source
154
154
  rake (>= 0.8.7)
155
155
  thor (~> 1.0)
@@ -174,19 +174,19 @@ GEM
174
174
  rspec-mocks (~> 3.10)
175
175
  rspec-support (~> 3.10)
176
176
  rspec-support (3.10.2)
177
- rubocop (1.12.1)
177
+ rubocop (1.14.0)
178
178
  parallel (~> 1.10)
179
179
  parser (>= 3.0.0.0)
180
180
  rainbow (>= 2.2.2, < 4.0)
181
181
  regexp_parser (>= 1.8, < 3.0)
182
182
  rexml
183
- rubocop-ast (>= 1.2.0, < 2.0)
183
+ rubocop-ast (>= 1.5.0, < 2.0)
184
184
  ruby-progressbar (~> 1.7)
185
185
  unicode-display_width (>= 1.4.0, < 3.0)
186
- rubocop-ast (1.4.1)
187
- parser (>= 2.7.1.5)
188
- rubocop-performance (1.10.1)
189
- rubocop (>= 0.90.0, < 2.0)
186
+ rubocop-ast (1.7.0)
187
+ parser (>= 3.0.1.1)
188
+ rubocop-performance (1.11.2)
189
+ rubocop (>= 1.7.0, < 2.0)
190
190
  rubocop-ast (>= 0.4.0)
191
191
  ruby-progressbar (1.11.0)
192
192
  rubyzip (2.3.0)
@@ -200,9 +200,9 @@ GEM
200
200
  actionpack (>= 4.0)
201
201
  activesupport (>= 4.0)
202
202
  sprockets (>= 3.0.0)
203
- standard (1.0.5)
204
- rubocop (= 1.12.1)
205
- rubocop-performance (= 1.10.1)
203
+ standard (1.1.1)
204
+ rubocop (= 1.14.0)
205
+ rubocop-performance (= 1.11.2)
206
206
  thor (1.1.0)
207
207
  tzinfo (2.0.4)
208
208
  concurrent-ruby (~> 1.0)
@@ -211,7 +211,7 @@ GEM
211
211
  nokogiri (~> 1.6)
212
212
  rubyzip (>= 1.3.0)
213
213
  selenium-webdriver (>= 3.0, < 4.0)
214
- websocket-driver (0.7.3)
214
+ websocket-driver (0.7.5)
215
215
  websocket-extensions (>= 0.1.0)
216
216
  websocket-extensions (0.1.5)
217
217
  xpath (3.2.0)
@@ -42,4 +42,8 @@ class SomeTestDataUsingTest < ActionDispatch::IntegrationTest
42
42
  def test_boops
43
43
  assert_equal 10, Boop.count
44
44
  end
45
+
46
+ def test_factory_bot_method_is_not_on_this_class
47
+ assert_raises(NameError) { method(:create) }
48
+ end
45
49
  end
@@ -5,11 +5,11 @@ class ParallelizedTransactionalFixturefullTestCase < ActiveSupport::TestCase
5
5
  self.use_transactional_tests = true
6
6
  fixtures :all
7
7
 
8
- def setup
8
+ setup do
9
9
  TestData.load
10
10
  end
11
11
 
12
- def teardown
12
+ teardown do
13
13
  TestData.rollback
14
14
  end
15
15
  end
@@ -4,11 +4,11 @@ class ParallelizedNonTransactionalFixturelessTestCase < ActiveSupport::TestCase
4
4
  parallelize(workers: :number_of_processors)
5
5
  self.use_transactional_tests = false
6
6
 
7
- def setup
7
+ setup do
8
8
  TestData.load
9
9
  end
10
10
 
11
- def teardown
11
+ teardown do
12
12
  TestData.rollback
13
13
  end
14
14
  end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ class FixturesUsingTest < ActiveSupport::TestCase
4
+ def test_tries_to_load_rails_fixtures_with_test_data
5
+ error = assert_raises(TestData::Error) do
6
+ TestData.load_rails_fixtures(self)
7
+ end
8
+ assert_match "'TestData.load_rails_fixtures' depends on Rails' default fixture-loading behavior being disabled by calling 'TestData.prevent_rails_fixtures_from_loading_automatically!' as early as possible (e.g. near the top of your test_helper.rb), but it looks like it was never called", error.message
9
+ end
10
+ end
@@ -0,0 +1,127 @@
1
+ require "test_helper"
2
+
3
+ TestData.prevent_rails_fixtures_from_loading_automatically!
4
+
5
+ class FixtureFreeTestData < ActiveSupport::TestCase
6
+ fixtures :boops # why not
7
+
8
+ setup do
9
+ TestData.load
10
+ end
11
+
12
+ def test_has_no_fixture_boops
13
+ assert_equal 15, Boop.count
14
+ end
15
+
16
+ teardown do
17
+ TestData.rollback
18
+ end
19
+ end
20
+
21
+ class FixturesUsingTest < ActiveSupport::TestCase
22
+ fixtures :boops
23
+
24
+ setup do
25
+ TestData.load_rails_fixtures(self)
26
+ end
27
+
28
+ def test_has_fixture_boops
29
+ assert_equal 2, Boop.count
30
+ end
31
+
32
+ def test_does_not_get_the_other_fixture_accessor
33
+ assert_raises(NameError) { method(:pants) }
34
+ end
35
+
36
+ def test_even_explicitly_loading_test_data_will_truncate_and_then_load_fixtures
37
+ TestData.load
38
+ TestData.load_rails_fixtures(self)
39
+
40
+ assert_equal 2, Boop.count
41
+ end
42
+
43
+ def test_load_and_rollback_leaves_them_as_is
44
+ boop = Boop.first
45
+ original_created_at_time = boop.created_at
46
+ a_year_ago = 1.year.ago
47
+
48
+ boop.update!(created_at: a_year_ago)
49
+
50
+ assert_equal Boop.find(boop.id).created_at, a_year_ago
51
+
52
+ # Now after rollback
53
+ TestData.rollback(:after_load_rails_fixtures)
54
+
55
+ assert_equal Boop.find(boop.id).created_at, original_created_at_time
56
+ end
57
+
58
+ teardown do
59
+ TestData.rollback(:after_load_rails_fixtures)
60
+ end
61
+ end
62
+
63
+ class SomeFixturesAndSomeTestDataInOneClassTest < ActiveSupport::TestCase
64
+ i_suck_and_my_tests_are_order_dependent!
65
+ fixtures :all
66
+
67
+ def test_fixtures_work
68
+ TestData.load_rails_fixtures(self)
69
+
70
+ assert_equal Date.civil(2020, 1, 1), boops(:boop_1).updated_at.to_date
71
+ assert_equal "Levi", pants(:pant_1).brand
72
+
73
+ TestData.rollback(:after_load_rails_fixtures)
74
+ end
75
+
76
+ def test_that_rewinds_to_test_data
77
+ TestData.load
78
+
79
+ assert_equal 15, Boop.count
80
+
81
+ TestData.rollback
82
+ end
83
+
84
+ def test_that_rewinds_to_the_very_start
85
+ TestData.rollback(:before_data_load)
86
+
87
+ assert_equal 0, Boop.count
88
+ end
89
+
90
+ def test_fixtures_get_reloaded_because_cache_is_cleared
91
+ TestData.load_rails_fixtures(self)
92
+
93
+ assert_equal Date.civil(2019, 1, 1), boops(:boop_2).updated_at.to_date
94
+ assert_equal "Wrangler", pants(:pant_2).brand
95
+
96
+ TestData.rollback(:after_load_rails_fixtures)
97
+ end
98
+ end
99
+
100
+ class PantsFixturesTest < ActiveSupport::TestCase
101
+ fixtures :pants
102
+
103
+ setup do
104
+ TestData.load_rails_fixtures(self)
105
+ end
106
+
107
+ teardown do
108
+ TestData.rollback(:after_load_rails_fixtures)
109
+ end
110
+
111
+ def test_has_fixture_pants
112
+ assert_equal 2, Pant.count
113
+ end
114
+
115
+ def test_does_not_get_the_other_fixture_accessor
116
+ assert_raises(NameError) { method(:boops) }
117
+ end
118
+ end
119
+
120
+ class FixtureTestPassingTheWrongThingTest < ActiveSupport::TestCase
121
+ def test_doing_it_wrong
122
+ error = assert_raises(TestData::Error) do
123
+ TestData.load_rails_fixtures(ActiveRecord::Base)
124
+ end
125
+ assert_match "'TestData.load_rails_fixtures' must be passed a test instance that has had ActiveRecord::TestFixtures mixed-in (e.g. `TestData.load_rails_fixtures(self)` in an ActiveSupport::TestCase `setup` block), but the provided argument does not respond to 'setup_fixtures'", error.message
126
+ end
127
+ end
@@ -1,20 +1,24 @@
1
1
  require "test_helper"
2
2
 
3
+ TestData.config.use_transactional_data_loader = false
4
+
3
5
  class TransactionCommittingTestCase < ActiveSupport::TestCase
4
6
  self.use_transactional_tests = false
5
7
 
6
- def setup
8
+ setup do
7
9
  Noncommittal.stop!
8
- TestData.load(transactions: false)
10
+ TestData.load
9
11
  end
10
12
 
11
- def teardown
13
+ teardown do
12
14
  Boop.delete_all
13
15
  Noncommittal.start!
14
16
  end
15
17
  end
16
18
 
17
19
  class TransactionCommittingBoopsTest < TransactionCommittingTestCase
20
+ i_suck_and_my_tests_are_order_dependent!
21
+
18
22
  def test_finds_the_boops
19
23
  assert_equal 15, Boop.count
20
24
  end
@@ -22,4 +26,11 @@ class TransactionCommittingBoopsTest < TransactionCommittingTestCase
22
26
  def test_finds_the_boops_via_another_process
23
27
  assert_equal 15, `RAILS_ENV=test bin/rails runner "puts Boop.count"`.chomp.to_i
24
28
  end
29
+
30
+ def test_cant_have_it_both_ways
31
+ error = assert_raise(TestData::Error) do
32
+ TestData.config.use_transactional_data_loader = true
33
+ end
34
+ assert_match "There is already a non-transactional data loader", error.message
35
+ end
25
36
  end