Skip to content

Fix error "undefined method '[]' for nil" - #27

Merged
makmic merged 1 commit into
makandra:masterfrom
LisaHader:master
Aug 11, 2025
Merged

Fix error "undefined method '[]' for nil"#27
makmic merged 1 commit into
makandra:masterfrom
LisaHader:master

Conversation

@LisaHader

Copy link
Copy Markdown
Contributor

After upgrading an application to the current latest version of rails_state_machine (3.1.1) and running my specs, I encountered a lot of errors undefined method '[]' for nil when running the application's specs.

This seems to be caused by the removal of the line @state_machine_state_managers ||= {} in model.rb in the previous version. After creating a model with a state machine through factory bot, the test crashes with the given error message.

After adding the previously removed line of code back in, all my tests are passing as expected.

@makmic

makmic commented Aug 11, 2025

Copy link
Copy Markdown
Member

I'm a bit surprised that it was not enough to set/reset the state machine manager cache only in after_initialize. But I can imagine factory_bot breaking because of it - let's add it back like you suggested 👍

@makmic
makmic merged commit 92f3477 into makandra:master Aug 11, 2025
13 checks passed
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.

2 participants