<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">18062</assigned-user-id>
  <attachments-count type="integer">1</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2009-08-10T10:48:39-04:00</created-at>
  <creator-id type="integer">65780</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer" nil="true"></milestone-id>
  <number type="integer">28</number>
  <permalink>loopback-transitions-dont-appear-to-update-rails-record</permalink>
  <priority type="integer">37</priority>
  <project-id type="integer">13288</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>resolved</state>
  <tag nil="true"></tag>
  <title>Loopback transitions don't appear to update Rails' record</title>
  <updated-at type="datetime">2009-10-07T13:20:34-04:00</updated-at>
  <user-id type="integer">21335</user-id>
  <user-name>Kenneth Kalmer</user-name>
  <creator-name>onitony</creator-name>
  <assigned-user-name>Aaron Pfeifer</assigned-user-name>
  <url>http://pluginaweek.lighthouseapp.com/projects/13288/tickets/28</url>
  <original-body>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).</original-body>
  <latest-body>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).</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;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).&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer">18062</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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).</body>
      <body-html>&lt;div&gt;&lt;p&gt;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).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-10T10:48:39-04:00</created-at>
      <creator-id type="integer">65780</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">28</number>
      <permalink>loopback-transitions-dont-appear-to-update-rails-record</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">13288</project-id>
      <state>new</state>
      <tag nil="true"></tag>
      <title>Loopback transitions don't appear to update Rails' record</title>
      <updated-at type="datetime">2009-08-10T10:48:41-04:00</updated-at>
      <user-id type="integer">65780</user-id>
      <user-name>onitony</user-name>
      <creator-name>onitony</creator-name>
      <assigned-user-name>Aaron Pfeifer</assigned-user-name>
      <url>http://pluginaweek.lighthouseapp.com/projects/13288/tickets/28</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">18062</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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.</body>
      <body-html>&lt;div&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-10T12:31:24-04:00</created-at>
      <creator-id type="integer">65780</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">28</number>
      <permalink>loopback-transitions-dont-appear-to-update-rails-record</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">13288</project-id>
      <state>open</state>
      <tag nil="true"></tag>
      <title>Loopback transitions don't appear to update Rails' record</title>
      <updated-at type="datetime">2009-08-10T12:31:29-04:00</updated-at>
      <user-id type="integer">18062</user-id>
      <user-name>Aaron Pfeifer</user-name>
      <creator-name>onitony</creator-name>
      <assigned-user-name>Aaron Pfeifer</assigned-user-name>
      <url>http://pluginaweek.lighthouseapp.com/projects/13288/tickets/28</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">18062</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>(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/bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f</body>
      <body-html>&lt;div&gt;&lt;p&gt;(from &lt;a href=
&quot;/projects/13288/changesets/bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f&quot;
title=
&quot;Changeset [bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f]&quot;&gt;[bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f]&lt;/a&gt;)
Fix loopbacks not causing records to save in ORM integrations if no
other fields were changed [&lt;a href=&quot;/projects/13288/tickets/28&quot;
title=&quot;Ticket #28&quot;&gt;#28&lt;/a&gt; state:resolved] &lt;a href=
&quot;http://github.com/pluginaweek/state_machine/commit/bcaafa8eb3308c78c64a404e9c3ca0ccf2c4bb5f&quot;&gt;
http://github.com/pluginaweek/state_machine/commit/bcaafa8eb3308c78...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-08-10T21:59:11-04:00</created-at>
      <creator-id type="integer">65780</creator-id>
      <diffable-attributes type="yaml">--- 
:state: open
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">28</number>
      <permalink>loopback-transitions-dont-appear-to-update-rails-record</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">13288</project-id>
      <state>resolved</state>
      <tag nil="true"></tag>
      <title>Loopback transitions don't appear to update Rails' record</title>
      <updated-at type="datetime">2009-08-10T21:59:12-04:00</updated-at>
      <user-id type="integer">18062</user-id>
      <user-name>Aaron Pfeifer</user-name>
      <creator-name>onitony</creator-name>
      <assigned-user-name>Aaron Pfeifer</assigned-user-name>
      <url>http://pluginaweek.lighthouseapp.com/projects/13288/tickets/28</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">18062</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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</body>
      <body-html>&lt;div&gt;&lt;p&gt;Aaron&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;The test file is gisted here: &lt;a href=
&quot;http://gist.github.com/204224&quot;&gt;http://gist.github.com/204224&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The long and the short of it is that when combined with the
acts_as_audited plugin (&lt;a href=
&quot;http://github.com/kennethkalmer/acts_as_audited&quot;&gt;http://github.com/kennethkalmer/acts_as_audited&lt;/a&gt;)
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.&lt;/p&gt;
&lt;p&gt;Best&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-10-07T13:20:32-04:00</created-at>
      <creator-id type="integer">65780</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">28</number>
      <permalink>loopback-transitions-dont-appear-to-update-rails-record</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">13288</project-id>
      <state>resolved</state>
      <tag nil="true"></tag>
      <title>Loopback transitions don't appear to update Rails' record</title>
      <updated-at type="datetime">2009-10-07T13:20:34-04:00</updated-at>
      <user-id type="integer">21335</user-id>
      <user-name>Kenneth Kalmer</user-name>
      <creator-name>onitony</creator-name>
      <assigned-user-name>Aaron Pfeifer</assigned-user-name>
      <url>http://pluginaweek.lighthouseapp.com/projects/13288/tickets/28</url>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>bc21e0c5e80bc5ff3a518bab329dbb6c990967d6</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-10-07T13:20:32-04:00</created-at>
      <filename>0001-state-attribute-should-only-be-marked-as-dirty-if-it.patch</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">288778</id>
      <size type="integer">1118</size>
      <uploader-id type="integer">21335</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://pluginaweek.lighthouseapp.com/attachments/288778/0001-state-attribute-should-only-be-marked-as-dirty-if-it.patch</url>
    </attachment>
  </attachments>
</ticket>
