Revert changes made to machine find_or_create method in #32 #60
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.
PR #32 introduced functionality to always return a machine if one
is present and no key is supplied to the
state_machine
call.This broke having multiple state machines on the same class unless
both have explicit names eg.using a slightly modified example from
the readme.
The second machine would not be created and
enable
would bedeclared on state, without the alarm namespace.
Tests were lacking to detect this behaviour so have added them.
An alternative fix would be to insist that classes with multiple
state machines always have a state key on each machine including
the default
:state
but I would argue that if you have a statemachine with a non default key then you would always supply the
key when interacting with the machine and have updated
test/functional/driver_default_nonstandard_test.rb
to reflect this.
Happy to make further amendments as you see fit. This is partially an
issue with a proposed fix. As I encountered a situation which was caught
out by this change and was unable to find other references to it. In the mean
time I have just added an explicit
:state
key on the default machine but amunsure how is best to tackle it, so am open to discussion.