Skip to content

Fix after-callback transitions on Mongoid 8.1 (QUAL-2685) - #12

Merged
roloand merged 5 commits into
masterfrom
QUAL-2685-after-callback-transitions-mongoid-8-1
Oct 30, 2026
Merged

roloand merged 5 commits into
masterfrom
QUAL-2685-after-callback-transitions-mongoid-8-1

Conversation

@roloand

@roloand roloand commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes after_save/after_update transition callbacks on Mongoid 8.1 (QUAL-2685), adds real-MongoDB specs, makes the 8.1 CI cells required, bumps to 0.1.3.

Root cause (verified)

Specs were written first and run against real Mongo before any lib change: on both 8.1 combos 6 of 8 failed (after_save on create, after_save on update, run-once, subsequent transition, after_update); 7.4 combos failed only the after_update specs. This confirms the spec's theory: Mongoid 8.1 empties changes[field] inside after_save, so process_state_transition_from_changes finds nothing.

Extra finding not in the spec: after_update transitions never fired on any Mongoid version (7.4 too) because define_state_attribute only registered before_save/after_save/validation hooks and never dispatched :after_update. The new after_update hook fixes that too.

Change

  • before_save captures changes[field] per instance; after_update and after_save replay the captured change (after_save clears it in ensure).
  • Specs: spec/mongoid_after_callbacks_spec.rb (real MongoDB, create and update).
  • CI: removed continue-on-error/experimental from the 8.1 cells.
  • Version 0.1.3.

Verification

Full suite, 68 examples, 0 failures on as6.1/as7.0 x mongoid7.4/8.1 (Ruby 3.0.6, mongo:7.0 local).

Decisions made

  • after_update dispatch added (not just 8.1 fix) since the ticket asks for after_update coverage and it was silently dead.
  • add_run_once_callback left in place (callback DSL refactor is out of scope); consequence: the same from->to transition on one instance fires once per lifecycle, as before.
  • before_create/after_create/before_update DSL events are still never dispatched; not fixed, follow-up candidate.
  • Tag v0.1.3 NOT created; to be tagged alongside the QUAL-2631 bump.
  • Not changed: errors[field] << (PR QUAL-2625: Modernize CI with Rails and Mongoid matrix #11).

🤖 Generated with Claude Code

roloand and others added 3 commits October 30, 2026 14:19
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment thread spec/mongoid_after_callbacks_spec.rb Resolved
Comment thread lib/stateful/mongoid.rb Resolved
Comment thread lib/stateful/mongoid.rb Resolved
roloand and others added 2 commits October 30, 2026 14:22
The run-once guard hid duplicate dispatches from the old assertion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ubuntu-latest is now 26.04, which has no prebuilt Ruby 3.0 or 3.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@roloand
roloand marked this pull request as ready for review October 30, 2026 20:55
@roloand
roloand merged commit 099f1b6 into master Oct 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant