paper-trail-gem--paper_trail/spec
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
..
generators Set MySQL collation: versions tbl: utf8mb4_general_ci 2016-03-31 16:24:11 -04:00
models An idea to combat model pollution 2016-06-06 01:18:31 -04:00
modules Upgrade rubocop and remove old flags (#804) 2016-05-15 03:14:36 -04:00
paper_trail Do not track associations by default 2016-04-26 22:06:22 -04:00
requests Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
support Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
paper_trail_spec.rb Fix whitespace 2016-03-05 17:11:08 -05:00
rails_helper.rb Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
spec_helper.rb Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00