1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
Commit graph

4 commits

Author SHA1 Message Date
Jared Beck
8b2d242048 Docs: Update docs, changelog after #731
[ci skip]
2016-03-13 16:02:43 -04:00
Chris Barton
e1f94d4597 Maps enums to database values before storing in object_changes
Keep consistency between versions with regard to `changes` and
`object_changes` and how enum columns store their values.

Before, `changes` would map the changed attributes enum columns to the database
values (integer values). This allows reifying that version to maintain the
integrity of the enum. It did not do so for `object_changes` and thus, `0`
for non-json columns, and the enum value for json columns would be stored instead.
For the non-json columns, it mapped any non-integer enum value to `0` because
during serialization that column is an `integer`.  Now this is fixed,
so that `object_changes` stores the enum mapped value.

Here is an example:

```ruby
class PostWithStatus < ActiveRecord::Base
  has_paper_trail
  enum status: { draft: 0, published: 1, archived: 2 }
end

post = PostWithStatus.new(status: :draft)
post.published!
version = post.versions.last

 # Before
version.changeset #> { 'status' => ['draft', 'draft'] } (stored as [0, 0])

 # After
version.changeset #> { 'status' => ['draft', 'published'] } (stored as [0, 1])
```
2016-03-11 22:11:59 -08:00
Jared Beck
8980f08d0e Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
Kasper Timm Hansen
5be48e491e Use Active Record's type system from 4.2 onwards.
Rails 4.2 deprecates `serialized_attributes` without replacement. However,
it also introduces a type system which lets us treat all attributes the same.

Rails 4.2 has `type_for_attribute` which knows how to serialize and deserialize
itself from a database through `type_cast_for_database` and `type_cast_from_database`.

(In Rails 5 they will be `serialize` and `deserialize` respectively.)

Thus we no longer need the `PaperTrail.config.serialized_attributes` toggle,
and this change makes it do nothing. It's still kept around for backwardscompatibility.
2015-12-21 21:06:42 +01:00