* Drop support for ruby 2.3
* Docs: appraisal
* Drop support for rails <= 5.1
* Upgrade rubocop to 0.80
* Remove defunct code for EoL rails versions
* Rails 5+ style controller test params keyword
* Squash me
Co-Authored-By: Todd Lynam <TLynam@gmail.com>
Co-authored-by: Todd Lynam <TLynam@gmail.com>
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.
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.
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.
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.