test_data 0.0.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -5
- data/.standard.yml +2 -0
- data/CHANGELOG.md +41 -0
- data/Gemfile.lock +16 -16
- data/LICENSE.txt +1 -6
- data/README.md +864 -501
- data/example/.gitignore +1 -4
- data/example/Gemfile.lock +74 -74
- data/example/config/application.rb +3 -0
- data/example/config/credentials.yml.enc +1 -2
- data/example/spec/rails_helper.rb +1 -1
- data/example/spec/requests/boops_spec.rb +1 -5
- data/example/spec/requests/rails_fixtures_override_spec.rb +106 -0
- data/example/test/integration/better_mode_switching_demo_test.rb +6 -10
- data/example/test/integration/fixture_load_count_test.rb +82 -0
- data/example/test/integration/load_rollback_truncate_test.rb +40 -45
- data/example/test/integration/mode_switching_demo_test.rb +4 -14
- data/example/test/integration/parallel_boops_with_fixtures_test.rb +2 -6
- data/example/test/integration/parallel_boops_without_fixtures_test.rb +2 -6
- data/example/test/integration/rails_fixtures_double_load_test.rb +10 -0
- data/example/test/integration/rails_fixtures_override_test.rb +110 -0
- data/example/test/integration/test_data_hooks_test.rb +89 -0
- data/example/test/integration/transaction_committing_boops_test.rb +5 -3
- data/example/test/test_helper.rb +2 -6
- data/lib/generators/test_data/cable_yaml_generator.rb +18 -0
- data/lib/generators/test_data/database_yaml_generator.rb +2 -3
- data/lib/generators/test_data/environment_file_generator.rb +7 -0
- data/lib/generators/test_data/initializer_generator.rb +20 -7
- data/lib/generators/test_data/secrets_yaml_generator.rb +19 -0
- data/lib/generators/test_data/webpacker_yaml_generator.rb +3 -2
- data/lib/test_data.rb +37 -1
- data/lib/test_data/active_record_ext.rb +11 -0
- data/lib/test_data/config.rb +33 -3
- data/lib/test_data/configurators.rb +2 -0
- data/lib/test_data/configurators/cable_yaml.rb +25 -0
- data/lib/test_data/configurators/environment_file.rb +3 -2
- data/lib/test_data/configurators/initializer.rb +3 -2
- data/lib/test_data/configurators/secrets_yaml.rb +25 -0
- data/lib/test_data/configurators/webpacker_yaml.rb +4 -3
- data/lib/test_data/custom_loaders/abstract_base.rb +25 -0
- data/lib/test_data/custom_loaders/rails_fixtures.rb +45 -0
- data/lib/test_data/dumps_database.rb +24 -1
- data/lib/test_data/generator_support.rb +3 -0
- data/lib/test_data/inserts_test_data.rb +25 -0
- data/lib/test_data/loads_database_dumps.rb +1 -1
- data/lib/test_data/log.rb +19 -1
- data/lib/test_data/{transactional_data_loader.rb → manager.rb} +78 -81
- data/lib/test_data/rake.rb +16 -7
- data/lib/test_data/statistics.rb +6 -1
- data/lib/test_data/truncates_test_data.rb +31 -0
- data/lib/test_data/version.rb +1 -1
- data/script/reset_example_app +1 -0
- data/script/test +31 -6
- data/test_data.gemspec +1 -1
- metadata +20 -4
@@ -14,7 +14,6 @@ class LoadRollbackTruncateTest < ActiveSupport::TestCase
|
|
14
14
|
def teardown
|
15
15
|
TestData.log.reset
|
16
16
|
TestData.statistics.reset
|
17
|
-
TestData.rollback(:before_data_load)
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_loads_data_then_truncates_then_rolls_back_etc
|
@@ -22,101 +21,97 @@ class LoadRollbackTruncateTest < ActiveSupport::TestCase
|
|
22
21
|
assert_equal 0, Boop.count
|
23
22
|
|
24
23
|
# Now load the dump
|
25
|
-
TestData.
|
24
|
+
TestData.uses_test_data
|
26
25
|
assert_equal 15, Boop.count
|
27
26
|
Boop.create!
|
28
27
|
assert_equal 16, Boop.count
|
29
28
|
|
30
29
|
# Next, truncate the boops
|
31
|
-
TestData.
|
30
|
+
TestData.uses_clean_slate
|
32
31
|
assert_equal 0, Boop.count
|
33
32
|
Boop.create!
|
34
33
|
assert_equal 1, Boop.count
|
35
34
|
|
36
35
|
# Now roll back to _just after truncate_
|
37
|
-
TestData.
|
36
|
+
TestData.uses_clean_slate
|
38
37
|
assert_equal 0, Boop.count
|
39
38
|
Boop.create!
|
40
39
|
assert_equal 1, Boop.count
|
41
40
|
|
42
41
|
# Verify default rollback works after truncate
|
43
|
-
TestData.
|
42
|
+
TestData.uses_test_data
|
44
43
|
assert_equal 15, Boop.count
|
45
44
|
|
46
45
|
# Verify touching non-test-data tables will also be first rollbacked when truncate is called
|
47
|
-
TestData.
|
46
|
+
TestData.uninitialize
|
48
47
|
good = ChattyAuditLog.create!(message: "I do belong here, because now we're at the start, prior to test_data's purview")
|
49
|
-
TestData.
|
48
|
+
TestData.uses_test_data
|
50
49
|
bad = ChattyAuditLog.create!(message: "I won't belong here after truncate because I'm data that the truncate-calling test wouldn't expect")
|
51
50
|
assert_equal 2, ChattyAuditLog.count
|
52
51
|
|
53
|
-
TestData.
|
52
|
+
TestData.uses_clean_slate
|
54
53
|
|
55
54
|
assert_equal 1, ChattyAuditLog.count
|
56
55
|
refute_nil ChattyAuditLog.find_by(id: good.id)
|
57
56
|
assert_nil ChattyAuditLog.find_by(id: bad.id)
|
58
57
|
|
59
|
-
# Verify rollbacking to some nonsense savepoint errors out:
|
60
|
-
error = assert_raise(TestData::Error) { TestData.rollback(:before_nonsense) }
|
61
|
-
assert_match "No known save point named 'before_nonsense'", error.message
|
62
|
-
|
63
58
|
# Warn but load anyway if rolled back to the start and then truncated
|
64
|
-
TestData.
|
65
|
-
TestData.
|
59
|
+
TestData.uninitialize
|
60
|
+
TestData.uses_clean_slate
|
66
61
|
assert_equal :debug, @last_log.level
|
67
|
-
assert_match "TestData.
|
62
|
+
assert_match "TestData.uses_clean_slate was called, but data was not loaded. Loading data", @last_log.message
|
68
63
|
assert_equal 0, Boop.count
|
69
|
-
TestData.
|
64
|
+
TestData.uses_test_data
|
70
65
|
assert_equal 15, Boop.count
|
71
66
|
|
72
67
|
# Chaos: try rolling back outside the gem (one level of extraneous rollback) and verify load recovers
|
73
|
-
TestData.
|
68
|
+
TestData.uninitialize
|
74
69
|
TestData.statistics.reset
|
75
70
|
assert_equal 0, TestData.statistics.load_count
|
76
|
-
TestData.
|
71
|
+
TestData.uses_test_data
|
77
72
|
assert_equal 1, TestData.statistics.load_count
|
78
|
-
TestData.
|
73
|
+
TestData.uses_test_data # Smart enough to not load again
|
79
74
|
assert_equal 1, TestData.statistics.load_count
|
80
75
|
ActiveRecord::Base.connection.rollback_transaction # Someone might do this!
|
81
|
-
TestData.
|
76
|
+
TestData.uses_test_data # Still smart enough to not do this
|
82
77
|
assert_equal 1, TestData.statistics.load_count
|
83
|
-
TestData.
|
78
|
+
TestData.uses_test_data # after load savepoint should have been healed with subsequent load call
|
84
79
|
assert_equal 15, Boop.count
|
85
80
|
|
86
81
|
# Chaos: try rolling back outside the gem (one level of extraneous rollback) and verify truncate recovers
|
87
|
-
TestData.
|
82
|
+
TestData.uninitialize
|
88
83
|
TestData.statistics.reset
|
89
84
|
assert_equal 0, TestData.statistics.truncate_count
|
90
|
-
TestData.
|
91
|
-
TestData.
|
85
|
+
TestData.uses_test_data
|
86
|
+
TestData.uses_clean_slate
|
92
87
|
assert_equal 1, TestData.statistics.truncate_count
|
93
|
-
TestData.
|
88
|
+
TestData.uses_clean_slate
|
94
89
|
assert_equal 1, TestData.statistics.truncate_count
|
95
90
|
ActiveRecord::Base.connection.rollback_transaction # Someone might do this!
|
96
|
-
TestData.
|
91
|
+
TestData.uses_clean_slate # Will recover, not take the bait
|
97
92
|
assert_equal 1, TestData.statistics.truncate_count
|
98
|
-
TestData.
|
93
|
+
TestData.uses_clean_slate # after truncate savepoint should have been healed with subsequent truncate call
|
99
94
|
assert_equal 0, Boop.count
|
100
|
-
TestData.
|
95
|
+
TestData.uses_test_data
|
101
96
|
assert_equal 15, Boop.count
|
102
97
|
|
103
98
|
# Chaos: load data then call rollback two times and ensure we're still in a good spot
|
104
|
-
TestData.
|
99
|
+
TestData.uninitialize
|
105
100
|
TestData.statistics.reset
|
106
|
-
TestData.
|
101
|
+
TestData.uses_test_data
|
107
102
|
assert_equal 15, Boop.count
|
108
103
|
2.times do # Two rollbacks means we're back at before_data_load
|
109
104
|
ActiveRecord::Base.connection.rollback_transaction
|
110
105
|
end
|
111
106
|
assert_equal 0, Boop.count
|
112
|
-
TestData.
|
107
|
+
TestData.uses_test_data # It should successfully load again a second time
|
113
108
|
assert_equal 15, Boop.count
|
114
109
|
assert_equal 2, TestData.statistics.load_count
|
115
110
|
|
116
111
|
# Chaos: truncate data then call rollback two times and ensure we're still in a good spot
|
117
|
-
TestData.
|
112
|
+
TestData.uninitialize
|
118
113
|
TestData.statistics.reset
|
119
|
-
TestData.
|
114
|
+
TestData.uses_clean_slate # will warn-and-load and then truncate
|
120
115
|
assert_equal 0, Boop.count
|
121
116
|
2.times do # Two rollbacks means data is loaded but after_data_load savepoint has been lost
|
122
117
|
ActiveRecord::Base.connection.rollback_transaction
|
@@ -124,14 +119,14 @@ class LoadRollbackTruncateTest < ActiveSupport::TestCase
|
|
124
119
|
assert_equal 15, Boop.count
|
125
120
|
assert_equal 1, TestData.statistics.load_count
|
126
121
|
assert_equal 1, TestData.statistics.truncate_count
|
127
|
-
TestData.
|
122
|
+
TestData.uses_clean_slate # should restore the lost after_data_load savepoint and re-truncate
|
128
123
|
3.times do # Three rollbacks means we are at before_data_load again
|
129
124
|
ActiveRecord::Base.connection.rollback_transaction
|
130
125
|
end
|
131
126
|
assert_equal 0, Boop.count
|
132
|
-
TestData.
|
127
|
+
TestData.uses_test_data
|
133
128
|
assert_equal 15, Boop.count
|
134
|
-
TestData.
|
129
|
+
TestData.uses_clean_slate
|
135
130
|
assert_equal 0, Boop.count
|
136
131
|
assert_equal 3, TestData.statistics.truncate_count
|
137
132
|
assert_equal 2, TestData.statistics.load_count
|
@@ -140,17 +135,15 @@ class LoadRollbackTruncateTest < ActiveSupport::TestCase
|
|
140
135
|
def test_suite_runs_different_tests_in_whatever_order
|
141
136
|
# Imagine a test-datay test runs
|
142
137
|
test_data_using_test = -> do
|
143
|
-
TestData.
|
138
|
+
TestData.uses_test_data # before each
|
144
139
|
Boop.create!
|
145
140
|
assert_equal 16, Boop.count
|
146
|
-
TestData.rollback # after each
|
147
141
|
end
|
148
142
|
|
149
143
|
test_data_avoiding_test = -> do
|
150
|
-
TestData.
|
144
|
+
TestData.uses_clean_slate # before each
|
151
145
|
Boop.create!
|
152
146
|
assert_equal 1, Boop.count
|
153
|
-
TestData.rollback(:after_data_truncate) # after each
|
154
147
|
end
|
155
148
|
|
156
149
|
# Run the tests separately:
|
@@ -170,23 +163,25 @@ class LoadRollbackTruncateTest < ActiveSupport::TestCase
|
|
170
163
|
# In the interest of behaving similarly to .load, rollback in case the
|
171
164
|
# previous test doesn't have an after_each as you might hope/expect
|
172
165
|
3.times do
|
173
|
-
TestData.
|
166
|
+
TestData.uses_clean_slate
|
174
167
|
Boop.create!
|
175
168
|
assert_equal 1, Boop.count
|
176
169
|
end
|
177
170
|
end
|
178
171
|
|
179
172
|
def test_other_rollbacks_mess_with_transaction_state_will_debug_you
|
180
|
-
TestData.
|
173
|
+
TestData.uninitialize
|
174
|
+
TestData.statistics.reset
|
175
|
+
TestData.uses_test_data
|
181
176
|
ActiveRecord::Base.connection.rollback_transaction # data loaded, after_data_load save point destroyed
|
182
|
-
TestData.
|
177
|
+
TestData.uses_test_data
|
183
178
|
assert_equal :debug, @last_log.level # debug only b/c rails fixtures will do this on every after_each if enabled
|
184
179
|
assert_match "Recreating the :after_data_load save point", @last_log.message
|
185
180
|
assert_equal 1, TestData.statistics.load_count
|
186
181
|
|
187
|
-
TestData.
|
182
|
+
TestData.uses_clean_slate
|
188
183
|
ActiveRecord::Base.connection.rollback_transaction # data loaded, after_data_truncate save point destroyed
|
189
|
-
TestData.
|
184
|
+
TestData.uses_clean_slate
|
190
185
|
assert_equal :debug, @last_log.level # debug only b/c rails fixtures will do this on every after_each if enabled
|
191
186
|
assert_match "Recreating the :after_data_truncate save point", @last_log.message
|
192
187
|
assert_equal 1, TestData.statistics.load_count
|
@@ -1,29 +1,19 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class ModeSwitchingTestCase < ActiveSupport::TestCase
|
4
|
+
self.use_transactional_tests = false
|
5
|
+
|
4
6
|
def self.test_data_mode(mode)
|
5
7
|
if mode == :factory_bot
|
6
8
|
require "factory_bot_rails"
|
7
9
|
include FactoryBot::Syntax::Methods
|
8
10
|
|
9
11
|
setup do
|
10
|
-
TestData.
|
11
|
-
ActiveRecord::Base.connection.begin_transaction(joinable: false, _lazy: false)
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
ActiveRecord::Base.connection.rollback_transaction
|
12
|
+
TestData.uses_clean_slate
|
16
13
|
end
|
17
|
-
|
18
14
|
elsif mode == :test_data
|
19
|
-
self.use_transactional_tests = false
|
20
|
-
|
21
15
|
setup do
|
22
|
-
TestData.
|
23
|
-
end
|
24
|
-
|
25
|
-
teardown do
|
26
|
-
TestData.rollback
|
16
|
+
TestData.uses_test_data
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
@@ -5,12 +5,8 @@ class ParallelizedTransactionalFixturefullTestCase < ActiveSupport::TestCase
|
|
5
5
|
self.use_transactional_tests = true
|
6
6
|
fixtures :all
|
7
7
|
|
8
|
-
|
9
|
-
TestData.
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
TestData.rollback
|
8
|
+
setup do
|
9
|
+
TestData.uses_test_data
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
@@ -4,12 +4,8 @@ class ParallelizedNonTransactionalFixturelessTestCase < ActiveSupport::TestCase
|
|
4
4
|
parallelize(workers: :number_of_processors)
|
5
5
|
self.use_transactional_tests = false
|
6
6
|
|
7
|
-
|
8
|
-
TestData.
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
TestData.rollback
|
7
|
+
setup do
|
8
|
+
TestData.uses_test_data
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
@@ -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.uses_rails_fixtures(self)
|
7
|
+
end
|
8
|
+
assert_match "'TestData.uses_rails_fixtures(self)' 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,110 @@
|
|
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.uses_test_data
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_has_no_fixture_boops
|
13
|
+
assert_equal 15, Boop.count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class FixturesUsingTest < ActiveSupport::TestCase
|
18
|
+
fixtures :boops
|
19
|
+
|
20
|
+
setup do
|
21
|
+
TestData.uses_rails_fixtures(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_has_fixture_boops
|
25
|
+
assert boops(:boop_1).persisted?
|
26
|
+
assert_equal 2, Boop.count
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_does_not_get_the_other_fixture_accessor
|
30
|
+
assert_raises(NameError) { method(:pants) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_even_explicitly_loading_test_data_will_truncate_and_then_load_fixtures
|
34
|
+
TestData.uses_test_data
|
35
|
+
TestData.uses_rails_fixtures(self)
|
36
|
+
|
37
|
+
assert_equal 2, Boop.count
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_load_and_rollback_leaves_them_as_is
|
41
|
+
boop = Boop.first
|
42
|
+
original_created_on = boop.created_at.to_date
|
43
|
+
a_year_ago = 1.year.ago.to_date
|
44
|
+
|
45
|
+
boop.update!(created_at: a_year_ago)
|
46
|
+
|
47
|
+
assert_equal Boop.find(boop.id).created_at.to_date, a_year_ago
|
48
|
+
|
49
|
+
# Now trigger a rollback to the fixtures point
|
50
|
+
TestData.uses_rails_fixtures(self)
|
51
|
+
|
52
|
+
assert_equal Boop.find(boop.id).created_at.to_date, original_created_on
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class SomeFixturesAndSomeTestDataInOneClassTest < ActiveSupport::TestCase
|
57
|
+
i_suck_and_my_tests_are_order_dependent!
|
58
|
+
fixtures :all
|
59
|
+
|
60
|
+
def test_fixtures_work
|
61
|
+
TestData.uses_rails_fixtures(self)
|
62
|
+
|
63
|
+
assert_equal Date.civil(2020, 1, 1), boops(:boop_1).updated_at.to_date
|
64
|
+
assert_equal "Levi", pants(:pant_1).brand
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_that_rewinds_to_test_data
|
68
|
+
TestData.uses_test_data
|
69
|
+
|
70
|
+
assert_equal 15, Boop.count
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_that_rewinds_to_the_very_start
|
74
|
+
TestData.uninitialize
|
75
|
+
|
76
|
+
assert_equal 0, Boop.count
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_fixtures_get_reloaded_because_cache_is_cleared
|
80
|
+
TestData.uses_rails_fixtures(self)
|
81
|
+
|
82
|
+
assert_equal Date.civil(2019, 1, 1), boops(:boop_2).updated_at.to_date
|
83
|
+
assert_equal "Wrangler", pants(:pant_2).brand
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class PantsFixturesTest < ActiveSupport::TestCase
|
88
|
+
fixtures :pants
|
89
|
+
|
90
|
+
setup do
|
91
|
+
TestData.uses_rails_fixtures(self)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_has_fixture_pants
|
95
|
+
assert_equal 2, Pant.count
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_does_not_get_the_other_fixture_accessor
|
99
|
+
assert_raises(NameError) { method(:boops) }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class FixtureTestPassingTheWrongThingTest < ActiveSupport::TestCase
|
104
|
+
def test_doing_it_wrong
|
105
|
+
error = assert_raises(TestData::Error) do
|
106
|
+
TestData.uses_rails_fixtures(ActiveRecord::Base)
|
107
|
+
end
|
108
|
+
assert_match "'TestData.uses_rails_fixtures(self)' must be passed a test instance that has had ActiveRecord::TestFixtures mixed-in (e.g. `TestData.uses_rails_fixtures(self)` in an ActiveSupport::TestCase `setup` block), but the provided argument does not respond to 'setup_fixtures'", error.message
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
TestData.config do |config|
|
4
|
+
config.after_test_data_load { MetaBoop.refresh_materialized_view }
|
5
|
+
config.after_test_data_truncate(-> { MetaBoop.refresh_materialized_view })
|
6
|
+
config.after_rails_fixture_load { MetaBoop.refresh_materialized_view }
|
7
|
+
end
|
8
|
+
|
9
|
+
TestData.prevent_rails_fixtures_from_loading_automatically!
|
10
|
+
MetaBoop.refresh_materialized_view # count = 1
|
11
|
+
|
12
|
+
class TestDataHooksTest < ActiveSupport::TestCase
|
13
|
+
fixtures :all
|
14
|
+
i_suck_and_my_tests_are_order_dependent!
|
15
|
+
|
16
|
+
def test_uses_test_data_hook
|
17
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
18
|
+
MetaBoop.reset_refresh_materialized_view_count
|
19
|
+
|
20
|
+
# Materialized view is refreshed and called 1 time
|
21
|
+
TestData.uses_test_data
|
22
|
+
assert_equal 15, Boop.count
|
23
|
+
assert_equal 15, MetaBoop.count
|
24
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
25
|
+
MetaBoop.reset_refresh_materialized_view_count
|
26
|
+
|
27
|
+
# Rollbacks also rollback to materialized view changes without calling again
|
28
|
+
Boop.create!(other_boop: Boop.new)
|
29
|
+
assert_equal 16, Boop.count
|
30
|
+
assert_equal 15, MetaBoop.count
|
31
|
+
MetaBoop.refresh_materialized_view
|
32
|
+
assert_equal 16, MetaBoop.count
|
33
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
34
|
+
TestData.uses_test_data
|
35
|
+
assert_equal 15, Boop.count
|
36
|
+
assert_equal 15, MetaBoop.count
|
37
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
38
|
+
MetaBoop.reset_refresh_materialized_view_count
|
39
|
+
|
40
|
+
# The same hook also works when cleaning slates
|
41
|
+
TestData.uses_clean_slate
|
42
|
+
assert_equal 0, Boop.count
|
43
|
+
assert_equal 0, MetaBoop.count
|
44
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
45
|
+
Boop.create!(other_boop: Boop.new)
|
46
|
+
MetaBoop.refresh_materialized_view
|
47
|
+
assert_equal 1, Boop.count
|
48
|
+
assert_equal 1, MetaBoop.count
|
49
|
+
assert_equal 2, MetaBoop.refresh_materialized_view_count
|
50
|
+
TestData.uses_clean_slate
|
51
|
+
assert_equal 0, Boop.count
|
52
|
+
assert_equal 0, MetaBoop.count
|
53
|
+
assert_equal 2, MetaBoop.refresh_materialized_view_count
|
54
|
+
MetaBoop.reset_refresh_materialized_view_count
|
55
|
+
|
56
|
+
# The same hook works with fixtures
|
57
|
+
TestData.uses_rails_fixtures(self)
|
58
|
+
assert_equal 2, Boop.count
|
59
|
+
assert_equal 2, MetaBoop.count
|
60
|
+
assert_equal 1, MetaBoop.refresh_materialized_view_count
|
61
|
+
Boop.first.delete
|
62
|
+
assert_equal 1, Boop.count
|
63
|
+
assert_equal 2, MetaBoop.count
|
64
|
+
MetaBoop.refresh_materialized_view
|
65
|
+
assert_equal 1, MetaBoop.count
|
66
|
+
assert_equal 2, MetaBoop.refresh_materialized_view_count
|
67
|
+
TestData.uses_rails_fixtures(self)
|
68
|
+
assert_equal 2, Boop.count
|
69
|
+
assert_equal 2, MetaBoop.count
|
70
|
+
assert_equal 2, MetaBoop.refresh_materialized_view_count
|
71
|
+
MetaBoop.reset_refresh_materialized_view_count
|
72
|
+
|
73
|
+
# Rewinding two steps will not call refresh materialized views
|
74
|
+
TestData.uses_test_data
|
75
|
+
assert_equal 15, Boop.count
|
76
|
+
assert_equal 15, MetaBoop.count
|
77
|
+
assert_equal 0, MetaBoop.refresh_materialized_view_count
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_that_hooks_require_valid_settings
|
81
|
+
foo = Struct.new(:thing)
|
82
|
+
assert_raises(TestData::Error) { TestData.config.after_test_data_load(nil) }
|
83
|
+
assert_raises(TestData::Error) { TestData.config.after_test_data_truncate(nil) }
|
84
|
+
assert_raises(TestData::Error) { TestData.config.after_rails_fixture_load(nil) }
|
85
|
+
assert_raises(TestData::Error) { TestData.config.after_test_data_load(foo) }
|
86
|
+
assert_raises(TestData::Error) { TestData.config.after_test_data_truncate(foo) }
|
87
|
+
assert_raises(TestData::Error) { TestData.config.after_rails_fixture_load(foo) }
|
88
|
+
end
|
89
|
+
end
|