Closed julitrows closed 1 year ago
@seuros rebased!
I see a flaw in this implementation.
what will happen if i do
assert @hybrid_car.go_back_in_time!(1995, engine_options, flux_capacitor_settings)
where engine_options, flux_capacitor_settings are hashes ?
I will take over this branch and ping you in the new PR
Some time ago I opened this issue: https://github.com/state-machines/state_machines/issues/82
It was closed because everything seemed to be fine.
However https://github.com/state-machines/state_machines/issues/82#issuecomment-1569076464 by @jmanian made me think about the issue again. Instead of providing a test rails application that triggers the problem as I did when I opened the issue, this time I thought of getting inside the gem and try to solve it.
So I created some functional specs (see HybridCar and HybridCarTest) that would reflect the different ways of using positional and keyword arguments in bang methods, and see what happened.
In Ruby 2.7, I would get the Warnings of Doom™ when running the specs that use bang methods and keyword arguments:
test_should_accept_keyword_argument_in_unsafe_method
test_should_accept_positional_and_keyword_arguments_in_unsafe_method
And in Ruby 3.2.2 I would get straight errors:
So there's a breaking issue here.
In 746d5444cc780f5190d50af545ad3151b2a29804 I attempted a basic splitting of the arguments and do the call.
This solved the ERRORS above, but made another test fail:
By looking
machine.rb
and searching forskip
andaction
I learned there's a somewhat obscure feature in which if you pass a boolean as last argument to an event method call, that boolean is used to determine if theaction
defined in thestate_machine
opening statement gets invoked or not.I could not find in the code where this was happening (my metaruby reading is not that good), so I thought of preserving that last boolean argument. In the end, what I did was, if I could determine that there were no kwargs passed, I would just do the original call, instead of the one with positional and keyword arguments separated.
This makes all the tests pass.
I've got some questions tho:
machine.define_helper
call in the event.rb file? There are no other warnings under 2.7, but that might just be that there is no sufficient tests trying different parg/kwarg combinations.Machine#define_helper
instead?Thanks