fixtury 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +3 -1
- data/lib/fixtury/minitest_hooks.rb +6 -55
- data/lib/fixtury/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e33235b7dd547261eea486aee6d6ed0351157a11d1c76757d49b27c93b1b39
|
4
|
+
data.tar.gz: 8bd05c9be267d73b48b55fd7f20a4f6164ea22b41ba3ec889a8fd63026240e2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1a4e6331284da0e92b6af11567dd8d8e35ac079ddb8029a2c10ddc42538bce1157964dd923dda9a42819aedfc765d7095711863714d2490ed05759090ee0bc4
|
7
|
+
data.tar.gz: fa19480c1a11de53003580bf1a328561c00b11922c2aaeb34925961e8ab2a173a0185cbbd9db4ff60735ea2d013da16c914ae7e4e4f7df706d86289f15fa69a2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fixtury (
|
4
|
+
fixtury (2.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -99,7 +99,7 @@ CHECKSUMS
|
|
99
99
|
concurrent-ruby (1.3.4) sha256=d4aa926339b0a86b5b5054a0a8c580163e6f5dcbdfd0f4bb916b1a2570731c32
|
100
100
|
connection_pool (2.4.1) sha256=0f40cf997091f1f04ff66da67eabd61a9fe0d4928b9a3645228532512fab62f4
|
101
101
|
drb (2.2.1) sha256=e9d472bf785f558b96b25358bae115646da0dbfd45107ad858b0bc0d935cb340
|
102
|
-
fixtury (
|
102
|
+
fixtury (2.0.0)
|
103
103
|
globalid (1.2.1) sha256=70bf76711871f843dbba72beb8613229a49429d1866828476f9c9d6ccc327ce9
|
104
104
|
i18n (1.14.6) sha256=dc229a74f5d181f09942dd60ab5d6e667f7392c4ee826f35096db36d1fe3614c
|
105
105
|
logger (1.6.4) sha256=b627b91c922231050932e7bf8ee886fe54790ba2238a468ead52ba21911f2ee7
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ class MyTest < ::Minitest::Test
|
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
-
Loading this file would ensure `users/fresh` is loaded into the fixture set before the suite is run. In the context of Minitest::Test, the Fixtury::MinitestHooks file will ensure the
|
24
|
+
Loading this file would ensure `users/fresh` is loaded into the fixture set before the suite is run. In the context of Minitest::Test, the Fixtury::MinitestHooks file will ensure the fixtures are present prior to your suite running.
|
25
25
|
|
26
26
|
## Configuration
|
27
27
|
|
@@ -109,3 +109,5 @@ end
|
|
109
109
|
|
110
110
|
When installed with the railtie, a MutationObserver module is prepended into ActiveRecord::Base. It observes record mutations and ensures a record is not mutated outside of the declared isolation level. If you're not using ActiveRecord check out Fixtury::MutationObserver to see how you could hook into other frameworks.
|
111
111
|
|
112
|
+
In your test suite when utilizing the Fixtury::MinitestHooks records will be loaded before ActiveRecord's transactional fixtures transaction is opened. This means the you can define all your fixtures in your tests, they will be prebuilt and, as long as the fixtury references are preserved, all your fixtures are cached across runs. The fixtures in each file are loaded on demand which means only the fixtures necessary for the test to run are prebuilt (and cached for reuse). Standard transactional fixture rollback occurs after each test run so any mutation to fixtures will not be persisted.
|
113
|
+
|
@@ -7,8 +7,7 @@ module Fixtury
|
|
7
7
|
# MinitestHooks is a module designed to hook into a Minitest test case, and
|
8
8
|
# provide a way to load fixtures into the test case. It is designed to be
|
9
9
|
# prepended into the test case class, and will automatically load fixtures
|
10
|
-
# before the test case is setup
|
11
|
-
# case is torn down.
|
10
|
+
# before the test case is setup.
|
12
11
|
#
|
13
12
|
# The module also provides a way to define fixture dependencies, and will
|
14
13
|
# automatically load those dependencies before the test case is setup.
|
@@ -44,14 +43,15 @@ module Fixtury
|
|
44
43
|
#
|
45
44
|
# end
|
46
45
|
#
|
46
|
+
# Use `as: false` if you do not want an accessor created.
|
47
|
+
#
|
47
48
|
# A Set object named fixtury_dependencies is made available on the test class.
|
48
49
|
# This allows you to load all Minitest runnables and analyze what fixtures are
|
49
50
|
# needed. This is very helpful in CI pipelines when you want to prepare all fixtures
|
50
51
|
# ahead of time to share between multiple processes.
|
51
52
|
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# are present, those settings will be respected. If neither are present, a transaction will be used.
|
53
|
+
# It is the responsibility of the suite to manage the snapshot or rollback of the database. Generally
|
54
|
+
# something like ActiveRecord's use_transactional_fixtures will work just fine.
|
55
55
|
module MinitestHooks
|
56
56
|
|
57
57
|
def self.prepended(klass)
|
@@ -67,8 +67,7 @@ module Fixtury
|
|
67
67
|
module ClassMethods
|
68
68
|
|
69
69
|
# Declare fixtury dependencies for this test case. This will automatically
|
70
|
-
# load the fixtures before the test case is setup
|
71
|
-
# after the test case is torn down.
|
70
|
+
# load the fixtures before the test case is setup.
|
72
71
|
#
|
73
72
|
# @param searches [Array<String>] A list of fixture names to load. These should be resolvable paths relative to Fixtury.schema (root).
|
74
73
|
# @param opts [Hash] A list of options to customize the behavior of the fixtures.
|
@@ -115,12 +114,6 @@ module Fixtury
|
|
115
114
|
super
|
116
115
|
end
|
117
116
|
|
118
|
-
# Minitest after_teardown hook. This will rollback any changes made to the fixtures after the test.
|
119
|
-
def after_teardown(...)
|
120
|
-
super
|
121
|
-
fixtury_teardown if fixtury_dependencies.any?
|
122
|
-
end
|
123
|
-
|
124
117
|
# Access a fixture via a search term. This will access the fixture from the Fixtury store.
|
125
118
|
# If the fixture was not declared as a dependency, an error will be raised.
|
126
119
|
#
|
@@ -138,44 +131,10 @@ module Fixtury
|
|
138
131
|
Fixtury.store.get(dfn.pathname)
|
139
132
|
end
|
140
133
|
|
141
|
-
# Retrieve all database connections that are currently registered with a writing role.
|
142
|
-
#
|
143
|
-
# @return [Array<ActiveRecord::ConnectionAdapters::AbstractAdapter>] The list of database connections.
|
144
|
-
def fixtury_database_connections
|
145
|
-
return [] unless defined?(ActiveRecord::Base)
|
146
|
-
|
147
|
-
pools = ActiveRecord::Base.connection_handler.connection_pool_list(:writing)
|
148
|
-
pools.map { |pool| pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection }
|
149
|
-
end
|
150
|
-
|
151
134
|
# Load all dependenct fixtures and begin a transaction for each database connection.
|
152
135
|
def fixtury_setup
|
153
136
|
Fixtury.store.clear_stale_references!
|
154
137
|
fixtury_load_all_fixtures!
|
155
|
-
return unless fixtury_use_transactions?
|
156
|
-
|
157
|
-
fixtury_database_connections.each do |conn|
|
158
|
-
conn.begin_transaction joinable: false
|
159
|
-
if conn.pool.respond_to?(:lock_thread=)
|
160
|
-
conn.pool.lock_thread = true
|
161
|
-
elsif conn.pool.respond_to?(:pin_connection!)
|
162
|
-
conn.pool.pin_connection!(true)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
# Rollback any changes made to the fixtures
|
168
|
-
def fixtury_teardown
|
169
|
-
return unless fixtury_use_transactions?
|
170
|
-
|
171
|
-
fixtury_database_connections.each do |conn|
|
172
|
-
conn.rollback_transaction if conn.open_transactions.positive?
|
173
|
-
if conn.pool.respond_to?(:lock_thread=)
|
174
|
-
conn.pool.lock_thread = false
|
175
|
-
elsif conn.pool.respond_to?(:unpin_connection!)
|
176
|
-
conn.pool.unpin_connection!
|
177
|
-
end
|
178
|
-
end
|
179
138
|
end
|
180
139
|
|
181
140
|
# Load all fixture dependencies that have not previously been loaded into the store.
|
@@ -190,13 +149,5 @@ module Fixtury
|
|
190
149
|
end
|
191
150
|
end
|
192
151
|
|
193
|
-
# Adhere to common Rails test transaction settings.
|
194
|
-
def fixtury_use_transactions?
|
195
|
-
return use_transactional_tests if respond_to?(:use_transactional_tests)
|
196
|
-
return use_transactional_fixtures if respond_to?(:use_transactional_fixtures)
|
197
|
-
|
198
|
-
true
|
199
|
-
end
|
200
|
-
|
201
152
|
end
|
202
153
|
end
|
data/lib/fixtury/version.rb
CHANGED