geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Implicit state transitions not enforcing rules #184

Closed kelchm closed 2 years ago

kelchm commented 8 years ago

Is there a reasonable way to support implicit state transitions and their associated rules/callbacks using Workflow?

As a simple example:

class Article
  include Workflow
  workflow do
    state :new do
      event :submit, :transitions_to => :awaiting_review
    end
    state :awaiting_review do
      event :review, :transitions_to => :being_reviewed
    end
    state :being_reviewed do
      event :accept, :transitions_to => :accepted
      event :reject, :transitions_to => :rejected
    end
    state :accepted
    state :rejected
  end
...
end

If I have an AR Article model whose state is new, and attempt to update the workflow_state property to accepted I would expect the transition to be rejected identically to how it would be if I called article.accept!, however I find that the model is persisted with the state accepted even though this was not a valid transition.