has_state_machine 1.3.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94b18269b2a7ac5e0b6ca2aedf9591a78111e30089dfe8a000190bad02725d71
4
- data.tar.gz: 93ce1793915219f7b00725c2faf977cdbd62f40d20fefa21b680b281378ed242
3
+ metadata.gz: 67cb6cdd8b2615f9ca486802de5ef3bd55d5cc3f935ec069a9c888adf509a844
4
+ data.tar.gz: ae0d204c60f82cab7656633e562d49b7ee0501e4b15a65c9daa3b19cb9b5e92a
5
5
  SHA512:
6
- metadata.gz: 82344021e6dd63dde02dbfcb261b39b8773b51cff31ab37846441e655d420dfa9ba63128a893d9c7a11a83c15371320575871bd0e2f32f6c6061c84a8fe72984
7
- data.tar.gz: a2cef6e05f4eb1c63fd2002478c0d2fc9a673cbc1b6be9ec2c13288eee5d0d12b7438514489fc6dc75e9fa257f7571f6f67b3694351be33fe041c5095b115dc3
6
+ metadata.gz: a5863cd591499b89b2fbd77140b665c795bc552d686040faa7ebf3dad26f1b19ae3c4dd7f88a88e1aea31a3fb49168f35b3ff11a9d5e3294cea0fd1aa26ada26
7
+ data.tar.gz: 399f43970999929b7f50735479e598271d2c3d831c744cb83d12317cca01d09169535088dbdbeb8e7fd7e668d1b2a48be11528fe084802524cbe2dffa374ae6a
data/README.md CHANGED
@@ -292,7 +292,7 @@ end
292
292
  `after_transition_commit` callbacks run after the outermost database transaction commits. In detail:
293
293
 
294
294
  - If no transaction is open when `transition_to` is called, they run immediately after the transition commits.
295
- - If the transition happens inside an open transaction — an app-level `ActiveRecord::Base.transaction`, or a nested transition triggered from another state's `before_transition`/`after_transition` — they are deferred until that outermost transaction commits.
295
+ - If the transition happens inside an open transaction — an app-level `ActiveRecord::Base.transaction`, or a nested transition triggered from another state's `before_transition`/`after_transition` — they are deferred until that outermost transaction commits, however deeply nested, including through `requires_new` savepoints and `joinable: false` blocks.
296
296
  - They never run if the transition fails, if `rollback_transition` is raised, or if a surrounding transaction rolls back after the transition. Multiple transitions inside one transaction each fire their callbacks after commit, in transition order.
297
297
 
298
298
  This makes `after_transition_commit` the safe place to enqueue background jobs, call external APIs, etc.: the work only happens once the new state is actually visible to other database connections.
@@ -130,15 +130,20 @@ module HasStateMachine
130
130
  true
131
131
  end
132
132
 
133
- # Use the current transaction: after_all_transactions_commit ignores our
134
- # non-joinable transactions and would run callbacks before commit.
135
133
  def enqueue_transition_commit_callbacks
136
- current_transaction = object.class.connection.current_transaction
134
+ after_outermost_commit { run_callbacks(:transition_commit) { true } }
135
+ end
136
+
137
+ # Walk up to the real COMMIT: Rails runs after_commit early under a
138
+ # non-joinable parent, and after_all_transactions_commit skips those.
139
+ def after_outermost_commit(&block)
140
+ transaction = object.class.connection.current_transaction
141
+ return yield unless transaction.open?
137
142
 
138
- # Rails < 7.2 has no Transaction#after_commit; run callbacks immediately.
139
- return run_callbacks(:transition_commit) { true } unless current_transaction.respond_to?(:after_commit)
143
+ # Rails < 7.2 has no Transaction#after_commit.
144
+ return yield unless transaction.respond_to?(:after_commit)
140
145
 
141
- current_transaction.after_commit { run_callbacks(:transition_commit) { true } }
146
+ transaction.after_commit { after_outermost_commit(&block) }
142
147
  end
143
148
 
144
149
  def rollback_transition
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HasStateMachine
4
- VERSION = "1.3.0"
4
+ VERSION = "1.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Hargett