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

7 commits

Author SHA1 Message Date
Jared Beck
932bf22347 Fix NameError when pg is not loaded
Most apps only load a single db adapter gem.

A MySQL app, for example will not load the pg gem.

See https://github.com/airblade/paper_trail/issues/1022
2017-12-10 02:34:40 -05:00
Hubert Pompecki
4cce9b0179 Serializing postgres arrays (#1018)
This PR addresses #1015

Starting from Rails version 5.0.2 the default serializer of PostgreSQL columns returns an ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array object instead of a string. This new object is not suitable for JSON encoding and breaks versioning of any array fields backed by Postgres.

Whenever a PostgreSQL array is used, instead of asking Active Record for a serializer we introduce our own, which simply returns the underlying array without any modifications.
2017-12-08 11:44:40 -05:00
Jared Beck
9db3b3ce05 Delete LegacyActiveRecordShim 🎉
We no longer support rails < 4.2
2017-10-27 12:34:56 -04:00
Jared Beck
7884c143b6 Fix deserialization of enums written by PT 4
Fixes #855
2016-09-02 18:14:54 -04:00
Jared Beck
bc1308ea80 Fix enum serialization in rails 4.2
Fixes #798

Our test suite has one model that tests enums, PostWithStatus. Its
spec did not cover `touch_with_version`. Somehow, probably during
our upgrade to rails 5, we broke `touch_with_version` for enums.
Unlike other methods, when an enum arrives at
`CastAttributeSerializer#serialize` during `touch_with_version`, it
is already a number. We assumed it was always a string.

This is sort of a hack, just handling both strings and numbers in
`#serialize`. I'd rather figure out how a number got to `#serialize`
in the first place. However, a hack is acceptable, as it's only
for rails 4.2, and the hack will eventually be deleted when we
drop support for 4.2.
2016-08-14 00:24:13 -04:00
Jared Beck
ad3806fcbb An idea to combat model pollution
Problem
-------

`has_paper_trail` adds too many methods to the ActiveRecord model.

> If I'm counting correctly, installing the paper_trail gem adds 36 instance
> methods and 10 class methods to all of your active record models. Of those
> 46, 13 have a prefix, either "pt_" or "paper_trail_". I don't know what the
> best way to deal with this is. Ideally, we'd add far fewer methods to
> people's models. If we were able to add fewer methods to models, then I
> wouldn't mind prefixing all of them.
> https://github.com/airblade/paper_trail/issues/703

Solution
--------

Add only two methods to the AR model.

1. An instance method `#paper_trail`
2. A class method `.paper_trail`

The instance method would return a `RecordTrail` and the class method would
return a `ClassTrail`. Those names are totally up for debate.

Advantages
----------

- Plain ruby, easy to understand
- Adding new methods to e.g. the `RecordTrail` does not add any methods to
  the AR model.
- Methods privacy is more strongly enforced.
- Enables isolated testing of e.g. `RecordTrail`; it can be constructed with a
  mock AR instance.

Disadvantages
-------------

- Two new classes, though they are simple.
2016-06-06 01:18:31 -04:00
Jared Beck
10cabf2408 Break AttributesSerialization into small modules
It already was organized *in memory* but now it's organized in files.

Also, there are six fewer methods being mixed into the model class
(they became ObjectAttribute and ObjectChangesAttribute).

I like how the legacy (rails < 4.2) support is now all in one file,
so it'll be really easy to drop when the time comes.

Finally, a minor thing, I renamed CastedAttributeSerializer to
CastAttributeSerializer, because I don't think "casted" is the
correct conjugation.
2016-05-18 23:12:45 -04:00