Skip to content

Add ensure_ transition methods for safe state transitions#67

Open
stimms wants to merge 1 commit intoguideline-tech:mainfrom
stimms:ensure_state
Open

Add ensure_ transition methods for safe state transitions#67
stimms wants to merge 1 commit intoguideline-tech:mainfrom
stimms:ensure_state

Conversation

@stimms
Copy link
Copy Markdown

@stimms stimms commented Mar 12, 2026

Summary

  • Adds ensure_#{transition_name} and ensure_#{transition_name}! methods that gracefully handle the case when a record is already in the target state
  • Returns true instead of raising an error when already in the destination state
  • The bang variant still raises on invalid transitions; the non-bang variant returns false

Test plan

  • Added tests verifying ensure_ methods return true when already in target state
  • Added tests verifying ensure_ methods perform normal transitions when not in target state
  • Added tests verifying ensure_! raises on invalid transitions
  • Added tests verifying ensure_ without bang can skip save
  • All existing tests continue to pass

🤖 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> and ensure_<transition>! methods for every stator transition, which return true without performing validation/saving when the record is already in the transition’s target state; otherwise they delegate to the existing transition methods (including should_save behavior for the non-bang version).

Extends model specs to cover idempotent behavior, normal delegation when not in the target state, true return 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.

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>
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