fixtury 1.0.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 514698ec587a7323fdc0cb3c81c93dd9666e16c87d7f5f2aa867d1cd6ac95ee3
4
- data.tar.gz: dd34ff54006e203bef96d6fce2c4c1dd2c97f9143d2d29d5e022c496600e0aff
3
+ metadata.gz: 1d721c0d209b0c6d3862fbbc522c7c658de4b65ec717dd06cd14c3fdc1813841
4
+ data.tar.gz: 139981e92652bd20c0c272324e0c0e0c24ac06ad1d22f7bb46c2e01719d358ca
5
5
  SHA512:
6
- metadata.gz: 0d1b1f1222fb51994a2ce522fcdec21b8b7bb3198eaecac72d7924d59996e5f0200c00a90dca5dbc75efded7292f26593bff266844bfb41ffd8214d9f25ae469
7
- data.tar.gz: e3bc71e4a40c3a40f12e23895e55cee83fa34b93d5db13e486c62a2e004671e64f775712dd71ba68ed4441de622ce667d2a43529ea2dacb47dafcfd3b1fb0119
6
+ metadata.gz: 874a770245b43bec8d2de2d116acf0b7ea4e4b40565561784f25318c731afcca0c0e07078cec7ffef4988674a168f34891aeecdae1b55dfdd11309cfd08fb411
7
+ data.tar.gz: 19539f08615abc69f2b4659107336478424c917e83f6200457be6d8cb25e3b6157b1e75cf235abcd8d11051bdbf8070e1a2aa881df7be4feb5da2ab5df436a0e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fixtury (1.0.1)
4
+ fixtury (2.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -28,14 +28,14 @@ GEM
28
28
  benchmark (0.4.0)
29
29
  bigdecimal (3.1.9)
30
30
  byebug (11.1.3)
31
- concurrent-ruby (1.3.4)
32
- connection_pool (2.4.1)
31
+ concurrent-ruby (1.3.5)
32
+ connection_pool (2.5.0)
33
33
  drb (2.2.1)
34
34
  globalid (1.2.1)
35
35
  activesupport (>= 6.1)
36
- i18n (1.14.6)
36
+ i18n (1.14.7)
37
37
  concurrent-ruby (~> 1.0)
38
- logger (1.6.4)
38
+ logger (1.6.5)
39
39
  m (1.6.2)
40
40
  method_source (>= 0.6.7)
41
41
  rake (>= 0.9.2.2)
@@ -96,13 +96,13 @@ CHECKSUMS
96
96
  benchmark (0.4.0) sha256=0f12f8c495545e3710c3e4f0480f63f06b4c842cc94cec7f33a956f5180e874a
97
97
  bigdecimal (3.1.9) sha256=2ffc742031521ad69c2dfc815a98e426a230a3d22aeac1995826a75dabfad8cc
98
98
  byebug (11.1.3) sha256=2485944d2bb21283c593d562f9ae1019bf80002143cc3a255aaffd4e9cf4a35b
99
- concurrent-ruby (1.3.4) sha256=d4aa926339b0a86b5b5054a0a8c580163e6f5dcbdfd0f4bb916b1a2570731c32
100
- connection_pool (2.4.1) sha256=0f40cf997091f1f04ff66da67eabd61a9fe0d4928b9a3645228532512fab62f4
99
+ concurrent-ruby (1.3.5) sha256=813b3e37aca6df2a21a3b9f1d497f8cbab24a2b94cab325bffe65ee0f6cbebc6
100
+ connection_pool (2.5.0) sha256=233b92f8d38e038c1349ccea65dd3772727d669d6d2e71f9897c8bf5cd53ebfc
101
101
  drb (2.2.1) sha256=e9d472bf785f558b96b25358bae115646da0dbfd45107ad858b0bc0d935cb340
102
- fixtury (1.0.1)
102
+ fixtury (2.0.2)
103
103
  globalid (1.2.1) sha256=70bf76711871f843dbba72beb8613229a49429d1866828476f9c9d6ccc327ce9
104
- i18n (1.14.6) sha256=dc229a74f5d181f09942dd60ab5d6e667f7392c4ee826f35096db36d1fe3614c
105
- logger (1.6.4) sha256=b627b91c922231050932e7bf8ee886fe54790ba2238a468ead52ba21911f2ee7
104
+ i18n (1.14.7) sha256=ceba573f8138ff2c0915427f1fc5bdf4aa3ab8ae88c8ce255eb3ecf0a11a5d0f
105
+ logger (1.6.5) sha256=c3cfe56d01656490ddd103d38b8993d73d86296adebc5f58cefc9ec03741e56b
106
106
  m (1.6.2) sha256=2fb85aff050b6b699e6dbca47b45d426e2136ccdfabb64437e9630230d29108e
107
107
  method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
108
108
  mini_portile2 (2.8.8) sha256=8e47136cdac04ce81750bb6c09733b37895bf06962554e4b4056d78168d70a75
@@ -126,4 +126,4 @@ CHECKSUMS
126
126
  tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
127
127
 
128
128
  BUNDLED WITH
129
- 2.6.2
129
+ 2.6.3
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 database records are present prior to your suite running. If you're using ActiveRecord `use_transactional_fixtures` and `use_transactional_tests` will be respected.
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
+
@@ -25,8 +25,12 @@ module Fixtury
25
25
 
26
26
  class DefinitionExecutionError < Base
27
27
 
28
+ attr_reader :original_error
29
+
28
30
  def initialize(pathname, error)
29
- super("Error while building #{pathname.inspect}: #{error}")
31
+ @original_error = error
32
+ super("Error while building #{pathname.inspect}: #{original_error}")
33
+ set_backtrace(original_error.backtrace)
30
34
  end
31
35
 
32
36
  end
@@ -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, and rollback any changes after the test
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
- # The setup and teardown attempt to manage a transaction for each registered database
53
- # connection if ActiveRecord::Base is present. If use_transaction_tests or use_transactional_fixtures
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, and rollback any changes
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
@@ -2,6 +2,11 @@
2
2
 
3
3
  module Fixtury
4
4
 
5
- VERSION = "1.0.1"
5
+ MAJOR = 2
6
+ MINOR = 0
7
+ PATCH = 2
8
+ PRERELEASE = nil
9
+
10
+ VERSION = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join(".")
6
11
 
7
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixtury
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-02 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,7 +147,6 @@ files:
147
147
  - ".github/workflows/build.yml"
148
148
  - ".gitignore"
149
149
  - ".ruby-version"
150
- - ".travis.yml"
151
150
  - Gemfile
152
151
  - Gemfile.lock
153
152
  - README.md
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.3.7
7
- before_install: gem install bundler -v 2.0.2