airblade/paper_trail — pull request #176 by fullbridge-batkins (2012-10-10 23:59:00+00:00)
Title: Force metadata calls to attributes to use current value if value is changing for attribute

Currently, if an attribute is set to be called to populate metadata on the `versions` table, and that attribute's value is being modified in an update, it will use the new value (value it is changing to) for the metadata value. This pull request aims to fix it so it will use the current value (what the attribute's value is prior to the update to the model).

Say you have a model like such:

```ruby
# == Schema Information
#
# Table name: resource_versions
#
# id :integer not null, primary key
# title :string(255)
# contents :text
class Article < ActiveRecord::Base
has_paper_trail :meta => { :title => :title }
end
```

Here is how the gem behaves currently:
```ruby
> art = Article.create(:title => 'Lorem', :content => 'Lorem ipsum dolor sit amet')
=> #

> art.versions.last.title
=> "Lorem"
# I would expect it to actually be the value that is being stored on the object, like so
> art.previous_version.title
=> nil
# this also happens on the update
> art.update_attribue(:title, 'Foobar')
=> true
> art.versions.last.title
=> "Foobar"
# again, I would expect it to return the value that is stored on the table, like so
> art.previous_version.title
=> "Lorem"
```

This commit fixes the gem so that the metadata that gets stored uses the attribute value prior to it's modification, as I would expect it to.