- It was only ignoring attributes defined as symbols.
- It now ignores when attributes are either defined as symbols or Hashes.
- Consolidates calculation to be shared when determining if changed and not ignored.
Resolves#1240
Introduces event classes, like Events::Create, which wrap the
AR instance and have one public method, `#data`, which returns
the attributes of nascent `Version` records. See comments in
Events::Base.
This extraction greatly simplifies RecordTrail. Not only have
we moved a lot of code out of RecordTrail, but we've also
moved the `@in_after_callback` variable. In its new location, this
variable is much easier to understand, and we no longer need the
`ensure` blocks to reset it.
Preserving compatibility with PT-AT caused some minor difficulties,
and we should follow up with them to see if we can simplify the
API they are using. Specifically, we would like to delete the
`data_for_*` methods.
- Fix Lint/RescueWithoutErrorClass
- And I use the term "fix" loosely
- Fix RSpec/PredicateMatcher
- The failure message should actually be better this way too.
- RSpec/LetBeforeExamples
- RSpec/HookArgument
- Fix RSpec/ExpectInHook in widget_spec.rb
- Fix RSpec/MessageSpies
- I like spies. I've never linted them before, but I like how they
separate test setup from assertions.
The reason some projects have both is so that some spec files can be
run in isolation, without the rails stuff. In practice, I don't find
myself ever doing this. So, the complexity of two files is unnecessary.
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.
When attributes are ignored, either by `:ignore` or by `:skip`,
then during updates, timestamp attributes like `updated_at` should
not be considered notable changes.
[Fixes#569]