views:

103

answers:

1

I think I might have discovered a bug in Vestal Versions (http://github.com/laserlemon/vestal_versions) -- it seems like revert_to's behavior depends on the reverts I've done in the past with the same object. Here's an example:

>> a = Annotation.find(1384)
=> #<Annotation id: 1384, body: "Just hanging out -- \"playing possum\" -- at the stor...", last_updated_by_id: 3, created_by_id: 3, song_id: 30, deleted_at: nil, created_at: "2009-09-06 01:56:55", updated_at: "2009-10-27 22:02:35", referent: "in the spot playing possum\nDebating my destination,...", vote_score: 0>
>> a.revert_to(9)
=> 9
>> a.body
=> #<RDiscount:0x21cf7bc @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="Just hanging out -- \"playing possum\" -- at the store, lacing up the new Nikes, trying to decide where to go for dinner">


>> a = Annotation.find(1384)
=> #<Annotation id: 1384, body: "Just hanging out -- \"playing possum\" -- at the stor...", last_updated_by_id: 3, created_by_id: 3, song_id: 30, deleted_at: nil, created_at: "2009-09-06 01:56:55", updated_at: "2009-10-27 22:02:35", referent: "in the spot playing possum\nDebating my destination,...", vote_score: 0>
>> a.revert_to(8)
=> 8
>> a.body
=> #<RDiscount:0x21b5a10 @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="I.e. just hanging out -- \"playing possum\" -- in the living room, lacing up the new Nikes, trying to decide where to go for dinner">
>> a.revert_to(:last)
=> 11
>> a.revert_to(9)
=> 9
>> a.body
=> #<RDiscount:0x21b5a10 @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="I.e. just hanging out -- \"playing possum\" -- in the living room, lacing up the new Nikes, trying to decide where to go for dinner">

I.e., if I revert_to(9) from a freshly loaded annotation the body field contains an RDiscount object whose text starts "Just hanging out -- \"playing possum\" -- at the store" (which is what the body was as of version 9)

However, if I revert to revert_to(8) from a freshly loaded annotation, check the annotation's body, revert_to(:last), and revert_to(9), the annotation's body while in version 9 will be wrong (it will match the annotation's body from version 8)

Any thoughts?

+3  A: 

This is not a bug in vestal_versions, it's rails not reloading your association after a version change. Assuming your Annotation holds the id to your RDiscount the following happens:

  1. you fetch an Annotation "a" with an RDiscount id of x.
  2. you revert "a" to a previous version, the RDiscount id changes to y.
  3. you call a.body, causing rails to load the RDiscount object with the id y.
  4. you revert "a" to :last, the RDiscount id changes to x again.
  5. you call a.body again, but rails has already loaded the RDiscount object and will return this object instead.
Calavera
Good call -- can you think of a workaround?
Horace Loeb
you could call your association like this: a.body(true). this forces rails to fetch the association from the db. there may be other ways using vestal versions, but i can't think of anything nifty at the momemnt.
Calavera