Loopback transitions don't appear to update Rails' record
Reported by onitony | August 10th, 2009 @ 10:48 AM
It seems that if a State Machine instance performs a transition that loops back into it's previous state, the record is not saved (because no fields have been modified?). The desired behaviour though, is for updated_at to update, to note the time the transition took place (same as it happens in non-loopback transitions).
Comments and changes to this ticket
-
Aaron Pfeifer August 10th, 2009 @ 12:31 PM
- → State changed from new to open
Thanks for the report and nice catch. This would definitely be a problem if the ORM only saves a record when the field has been really been changed. I'll work on getting a fix applied over the next day.
-
Aaron Pfeifer August 10th, 2009 @ 09:59 PM
- → State changed from open to resolved
(from [bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f]) Fix loopbacks not causing records to save in ORM integrations if no other fields were changed [#28 state:resolved] http://github.com/pluginaweek/state_machine/commit/bcaafa8eb3308c78...
-
Kenneth Kalmer October 7th, 2009 @ 01:20 PM
Aaron
The patch also creates another issue with ActiveRecord. I've attached a fix to this ticket. Unfortunately I didn't have the time to dissect your test cases and update the tests for ActiveRecord, but I did write a test file that you can drop into the root of the state_machine project and run.
The test file is gisted here: http://gist.github.com/204224
The long and the short of it is that when combined with the acts_as_audited plugin (http://github.com/kennethkalmer/acts_as_audited) the state changes are impossible to track. Inside write(), the call to state_will_change!() forces the changes hash to have the new state as the before and after values, which is not desirable at all. The audits, which work by way of sweeper or callback doesn't gain access to the original state before the transition.
Best
-
Aaron Pfeifer March 13th, 2010 @ 07:51 PM
Kenneth,
This has now been fixed: http://github.com/pluginaweek/state_machine/commit/2929f0edc2b3167c...
My apologies for taking so long to get this fix into the main line.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Adds support for creating state machines for attributes within a model
