Bugs: Browse | Submit New | Admin

[#12498] versions() function does not update after revert_to/save.

Date:
2007-07-23 06:42
Priority:
3
Submitted By:
Tim Coulter (tcoulter)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
versions() function does not update after revert_to/save.

Detailed description
The versions() function returns an incorrect result when trying to revert back (and save) an old version of an
acts_as_versioned object.

Consider this situation, where the Discussion object is my acts_as_versioned object:

(in irb)
>> d = Discussion.create(:text => "hello")
d = Discussion.create(:text => "hello")
=> #<Discussion:0xb76666e4 ...///::cut!::/// "version"=>1 ///::cut!::///...>
>> d.text = "good afternoon"
d.text = "good afternoon"
=> "good afternoon"
>> d.save # => version 2
d.save
=> true
>> d.text = "goodbye"
d.text = "goodbye"
=> "goodbye"
>> d.save # => version 3
d.save
=> true
>> d.version
d.version
=> 3
>> d.versions
d.versions
=> [#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d7110
@attributes={"discussion_id"=>"3", "updated_at"=>"2007-07-22 23:33:19",
"text"=>"hello", "id"=>"12", "version"=>"1"}>,
#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d70d4 @attributes={"discussion_id"=>"3",
"updated_at"=>"2007-07-22 23:34:00", "text"=>"good afternoon",
"id"=>"13", "version"=>"2"}>,
#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d7098 @attributes={"discussion_id"=>"3",
"updated_at"=>"2007-07-22 23:34:09", "text"=>"goodbye",
"id"=>"14", "version"=>"3"}>]
>> d.revert_to(2)
d.revert_to(2)
=> true
>> d.text
d.text
=> "good afternoon"
>> d.save # => version 4
d.save
=> true
>> d.version
d.version
=> 4
>> d.versions
d.versions
=> [#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d7110
@attributes={"discussion_id"=>"3", "updated_at"=>"2007-07-22 23:33:19",
"text"=>"hello", "id"=>"12", "version"=>"1"}>,
#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d70d4 @attributes={"discussion_id"=>"3",
"updated_at"=>"2007-07-22 23:34:00", "text"=>"good afternoon",
"id"=>"13", "version"=>"2"}>,
#<ActiveRecord::Acts::Versioned::DiscussionVersion:0xb75d7098 @attributes={"discussion_id"=>"3",
"updated_at"=>"2007-07-22 23:34:09", "text"=>"goodbye",
"id"=>"14", "version"=>"3"}>]

Look at the last result: There are currently four versions, yet the versions() function returns only three!

Reloading the object from the database fixes this problem.

The Discussion classed used acts_as_versioned with default parameters (this means there were none). I am using (as far
as I know) the latest released version of acts_as_versioned.



Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item