Add ensure_ transition methods for safe state transitions#67
Open
stimms wants to merge 1 commit intoguideline-tech:mainfrom
Open
Add ensure_ transition methods for safe state transitions#67stimms wants to merge 1 commit intoguideline-tech:mainfrom
stimms wants to merge 1 commit intoguideline-tech:mainfrom
Conversation
Adds ensure_#{transition_name} and ensure_#{transition_name}! methods
that gracefully handle the case when a record is already in the target
state, returning true instead of raising an error.
This allows calling ensure_approve! on something already approved
without triggering an invalid transition error.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensure_#{transition_name}andensure_#{transition_name}!methods that gracefully handle the case when a record is already in the target statetrueinstead of raising an error when already in the destination statefalseTest plan
ensure_methods returntruewhen already in target stateensure_methods perform normal transitions when not in target stateensure_!raises on invalid transitionsensure_without bang can skip save🤖 Generated with Claude Code
Note
Medium Risk
Adds new generated transition methods that change how callers can invoke state changes (idempotent when already in target state). Risk is moderate because it affects the core transition method generator and could alter application control flow around persistence/validation expectations.
Overview
Adds generated
ensure_<transition>andensure_<transition>!methods for every stator transition, which returntruewithout performing validation/saving when the record is already in the transition’s target state; otherwise they delegate to the existing transition methods (includingshould_savebehavior for the non-bang version).Extends model specs to cover idempotent behavior, normal delegation when not in the target state,
truereturn values, optional skip-save semantics, and bang-method failure on invalid transitions.Written by Cursor Bugbot for commit 0b4ce80. This will update automatically on new commits. Configure here.