Closed HashtagONUD closed 3 years ago
Discovered that if I comment out the if symbol, the workflow works as normal:
state :tsp_isnow_0_state do
event :tsp_wasasked_1_event, transitions_to: :tsp_wasasked_1_state # , if: :both_locations_exist?
end
It also works when I keep the if
condition, but return true from theboth_locations_exist?
method. If the method returns false, I get the same error as before.
To allow/prevent transition during the runtime depending on some condition, please read the documentation for "Conditional event transition" https://github.com/geekq/workflow#conditional-event-transitions
You need an :if
parameter (will call the function to decide to allow or prevent the transition) and not the if
modifier you use, when defining the workflow (this just prevents the event definition from the beginning).
I'm using ruby 2.6.3p62 (2019-04-16 revision 67580) with Rails 6 & these gems:
In my Transporter model, I want to make sure that a condition is true before the state is allowed to change:
I'm doing something perhaps a little unusual. My states and events are defined in the model (that's normal) but the code that fires the events is dynamically built by reading the current state. So for the above code, if the current state is "tsp_isnow_0_state", it makes a string called "tsp_wasasked_1_event" and sends that to the model object:
The problem is when the
prompt
method runs, I get this error:...but this is wrong because the
tsp_wasasked_1_event
event is defined in the model workflow (above). In my rails console, I can see the starting state is there:And I can see the next state in the spec is defined:
Any idea why the event isn't being found in the workflow_spec?
Thanks for any assistance!