airblade/paper_trail — pull request #219 by dwbutler (2013-05-11 00:54:20+00:00)
Title: Problem with nil values in `#reify`

I'm using a custom serializer that does not store nil values. I noticed that the attributes are stored correctly, but then not correctly reified back. For example:

```ruby
previous version data: {id: 123}
current version data: {id: 123, name: "Bob"}

model
#=> <#Person id: 123, name: "Bob">

model.previous_version
#Expected => <#Person id: 123, name: nil>
#Actual => <#Person id: 123, name: "Bob">
```

After some digging, I found that the problem is in `#reify`. The current version of the model is reused, and each attribute from the previous version is set on the current model. However, since "name" is not a key in the previous version, name was left as "Bob."

This was not a problem in the default serializers provided. Because they store everything, both versions of the models have all the same keys. For example:

```ruby
previous version data: {id: 123, name: nil, dob: nil}
current version data: {id: 123, name: "Bob", dob: nil}
```

This patch compares the keys between the current model and the previous version. If any keys are found to be missing, it puts them in as nil. This allows those attributes to be set to nil on the reified model.

I updated the serializer tests so they separately test the built-in JSON serializer as well as a custom serializer which doesn't store nil keys.