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

25 commits

Author SHA1 Message Date
Jared Beck
1d42d0d0ab Extract gem: paper_trail-association_tracking
See README and CHANGELOG for rationale.
2018-06-04 14:53:14 -04:00
Jared Beck
00367625a4 Alternative solution to #1084 2018-05-14 12:26:32 -04:00
fukayatsu
20bf893b67 Fix saving changes on #touch 2018-05-14 19:12:47 +09:00
Weston Ganger
02b6de2dac Integrate versioning into AR touch method (#1063)
* integrate versioning into AR touch method

* add touch to list of :on events, deprecate touch_with_version

* integrate versioning into AR touch method
2018-03-16 18:21:45 -04:00
Jared Beck
430738fcee Fix touch_with_version's data_for_update
Fixes https://github.com/airblade/paper_trail/issues/1047

Fixes touch_with_version when the update callback is not installed,
eg. `has_paper_trail(on: [])`
2018-03-04 02:17:22 -05:00
Jared Beck
79de10216e Set @in_after_callback correctly during record_destroy
A destroy event can be handled either in a before-callback
or an after-callback. It's configurable.

However, we were not setting @in_after_callback accordingly.

I'm not aware of a specific bug caused by failing to set
this instance variable correctly, but if the instance variable
is a lie, it's easy to imagine such a bug now or in the future.
2018-03-04 01:48:17 -05:00
Jared Beck
593da233bf Docs: Dirty, controllers
[ci skip]
2018-03-04 01:42:54 -05:00
Jared Beck
c659b1faf0 A new API for request variables 2018-02-27 00:14:33 -05:00
Jared Beck
b7b4119147 Require AR and AS: require all and earlier
Fixes a rare issue with load order when using PT outside of rails.
2018-01-31 12:25:31 -05:00
Jared Beck
c5b4a9ec66 Raise helpful error when CVC is abstract
Instead of crashing when misconfigured Custom Version Classes are
used, an error will be raised earlier, with a much more helpful message.

[Fixes #961]
2018-01-22 00:23:51 -05:00
Jared Beck
cfbf7a647c Lint: Style/FrozenStringLiteralComment 2017-12-10 23:05:39 -05:00
Jared Beck
fd3f41584e Raise when belongs_to_required_by_default
Using paper_trail.on_destroy(:after) with ActiveRecord's
belongs_to_required_by_default will produce an error instead of a warning.
2017-12-10 22:42:16 -05:00
Jared Beck
9db3b3ce05 Delete LegacyActiveRecordShim 🎉
We no longer support rails < 4.2
2017-10-27 12:34:56 -04:00
Sean Linsley
4150f8c4fd call before_save instead 2017-10-19 11:16:21 -05:00
Sean Linsley
dbbe77002e Fix callback to only run before update
`before_save` doesn't accept `:on` as an argument, so this callback was actually running on all save events, not just on update.

https://github.com/rails/rails/issues/17622

Depending on what `reset_timestamp_attrs_for_update_if_needed` does, this might need to be backported to older versions.

I've submitted a PR to Rails to raise an exception when unexpected arguments are passed... unsure if an exception is the right way to go when there might be quite a few gems with this bug.

https://github.com/rails/rails/pull/30919
2017-10-18 11:10:42 -05:00
Jared Beck
e2505c4f30 rubocop 0.48.1 (was 0.48.0) 2017-05-21 02:40:23 -04:00
Jared Beck
c9161129c3 Lint: Set TargetRubyVersion to 2.1 2017-03-31 21:45:06 -04:00
Jared Beck
dc4fc621ef Remove deprecated methods re: serialized attributes
These methods were deprecated in PT 5.0.0
https://github.com/airblade/paper_trail/pull/679
2017-03-03 12:09:17 -05:00
Jared Beck
b4149864f4 Remove rails 3 branch of association definition 2016-12-13 22:27:29 -05:00
Jared Beck
2604ce4071 Extract private method save_habtm_association? 2016-11-11 15:55:20 -05:00
Jared Beck
cfe86bf720 Remove deprecated model methods 2016-09-08 19:37:23 -04:00
Jared Beck
069871d6a2 Fix deprecation warning in setup_associations
[Fixes #836]
2016-07-05 20:13:32 -04:00
Jared Beck
48cdb7932c Extract private methods from #setup_callbacks_for_habtm 2016-06-27 02:07:31 -04:00
Jared Beck
bfa7487d25 Reduce duplication in #update_habtm_state 2016-06-27 01:50:41 -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