recorder 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 064c2afab28615f3f268bfacee354fdf6fceff7063190e084783dfe1640fe054
4
- data.tar.gz: 6062f268b4a47ea089cf90fac14ac124fc2c5e07f65be6d37228a663ec4cfc5e
3
+ metadata.gz: 384497725b7592a28acf04ea3a3984fe7d58003c34983e71db56057c2912cf71
4
+ data.tar.gz: fd57a9e193c6f9f008ee29e7f267498a126faf49c197c87f61f56bb554c04991
5
5
  SHA512:
6
- metadata.gz: ed30006c3d6f960d017a8b97853d5737624c9690f31ffc60ee3d0dc2dbbb21507f3e52e8203dd103192ba8648ca6dc643e969a232fd40a7ee65d0dcc7f11a87b
7
- data.tar.gz: 689acc4c8867035e627413e5586280e2b05327efa7a002713903300016f19a99caa1194e172de45633f6b4fb8771cdf3a380905784f327b3df01bca39ed93129
6
+ metadata.gz: cbd443f7714c47a376858762a95f21b56a2175976804e7aa6e4d2ff4167bb9457202454f701d0fdc4fb1b1e9112f2b5da05a102e551e28f19ab34986f94593cf
7
+ data.tar.gz: 14f1c87a5a7dd9365b8fc34171b2d2e61ccb9096b414871be529b619af7f6b9a43bb49f20390bf391dc5f55be93c765307ea4801b4d655649bcfbfb8faa0cc44
data/CHANGELOG.md CHANGED
@@ -7,6 +7,198 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0]
11
+
12
+ ### Added
13
+
14
+ - `if:` and `unless:` options on `recorder`, which decide per record whether a
15
+ create, update or destroy is recorded, as they do on a Rails callback. Each
16
+ takes a method name as a Symbol, a Proc that takes the record or nothing,
17
+ or `nil` for none, and any other value raises `ArgumentError`. A subclass
18
+ inherits them, and a `recorder_options` override does not change them. They
19
+ are checked only while recording is on, and `Recorder::Tape` called directly
20
+ does not check them.
21
+ - A README section on upgrading to 2.0.0, ordered by what to change before,
22
+ with and after the upgrade.
23
+ - README coverage of pointing `Revision#user` at a user model not named
24
+ `User`, by declaring the association again with `class_name:`. No behaviour
25
+ changes.
26
+
27
+ ### Changed
28
+
29
+ - **Breaking.** `recorder` can be called once per class hierarchy, and calling
30
+ it again, in the same class, a subclass or a parent, raises `ArgumentError`.
31
+ Every call used to register the create, update and destroy callbacks anew, so
32
+ a model that declared it twice wrote two identical revisions per event. A
33
+ subclass that needs different options defines a `recorder_options` instance
34
+ method instead. A declaration that runs twice on one class, such as one in a
35
+ `to_prepare` block on a class that is not reloaded, raises too; it used to
36
+ add another revision per event on every run.
37
+ - **Breaking.** `Recorder.info` raises `ArgumentError` for the columns Recorder
38
+ writes itself: `created_at`, `id`, `item_type`, `item_id`, `event` and
39
+ `data`. A `created_at` set through it used to overwrite every following
40
+ revision's, so `created_at` was not reliably when the revision was written;
41
+ to date revisions otherwise, set `action_date`. The other keys were silently
42
+ overwritten by the revision's own values.
43
+ - **Breaking.** `recorder` raises `ArgumentError` for an option it does not
44
+ know, in its own options or in an association's, so a misspelt one such as
45
+ `ignores:` fails where it is written. It also raises for options that are not
46
+ a hash, for an option name that is neither a symbol nor a string, for an
47
+ option given both as a symbol and as a string, for `associations:` that is
48
+ neither a hash nor an array, for an association name that is neither a symbol
49
+ nor a string or is given as both, and for an association whose options are
50
+ not a hash. These were stored and ignored, or failed when a record was saved.
51
+ `async:` and `delay:` raise too, with a message saying asynchronous recording
52
+ was removed.
53
+ - **Breaking.** The `recorder_options` class method returns the declared
54
+ options frozen, as a plain `Hash` with symbol keys, even when they were
55
+ declared as a `HashWithIndifferentAccess`, so a string key such as
56
+ `recorder_options['ignore']` returns `nil`. Association names are symbols
57
+ too. A `recorder_options` class method that changes `super` in place raises
58
+ `FrozenError` from the first save that reads it, which rolls that save back;
59
+ build a new hash, such as `super.merge(...)`. The `recorder_options` instance
60
+ method returns a copy, which an override may change.
61
+
62
+ ### Removed
63
+
64
+ - **Breaking.** Asynchronous recording: the `async:` and `delay:` options,
65
+ `Recorder.config.async`, `Recorder.config.sidekiq_options` and
66
+ `Recorder::Sidekiq::RevisionsWorker`, with the railtie that loaded it. Every
67
+ revision is written in the save transaction, so the record and its revision
68
+ commit or roll back together. The job was pushed from inside that transaction,
69
+ so a save that rolled back still wrote a revision once the job ran, and the
70
+ revision's `created_at` and `id` followed the job rather than the change.
71
+ `async:` and `delay:` passed to `recorder` raise `ArgumentError`; they had
72
+ no effect from 1.2.2 on, so remove them. Setting `Recorder.config.async` or
73
+ `Recorder.config.sidekiq_options` raises `NoMethodError`. An app that set
74
+ `Recorder.config.async = true` should set it to `false` on 1.x first and let
75
+ the jobs already pushed finish, the scheduled and retrying ones included,
76
+ before upgrading: a job left behind fails once the worker class is gone, and
77
+ its revision is never written.
78
+ - **Breaking.** `Recorder.active_record_protected_attributes?`, which reported
79
+ whether the `ProtectedAttributes` constant was defined.
80
+ - **Breaking.** The undocumented `recorder_dirty?` and `recorder_record?`
81
+ instance methods of observed models. A model that overrode one, or set
82
+ `@recorder_dirty = false` on a record, to skip recording is recorded, and
83
+ code that calls one raises `NoMethodError`. Declare a rule about the model's
84
+ records with `recorder if:` or `unless:`, and skip one call's changes with
85
+ `recorder_disabled! { record.save }`.
86
+
87
+ ### Fixed
88
+
89
+ - Options passed to `recorder` with string keys, such as `'ignore' => [...]`,
90
+ are applied, in its own options and in an association's. They used to be
91
+ ignored, and the model recorded as if they were not given.
92
+ - `recorder` keeps its own copy of the options, so changing the hash it was
93
+ given afterwards changes nothing, and a `recorder_options` instance method
94
+ that changes `super` in place changes only its own copy. Either used to
95
+ change the options of the declaring class and every subclass for the rest of
96
+ the process.
97
+ - **Breaking.** `Recorder.enabled = false` switches recording off, for the
98
+ whole process. It used to report recording as off while every change was
99
+ still recorded, so a script that set it, such as a backfill or a data
100
+ migration, starts leaving no revisions behind.
101
+ - `recorder_disabled!` with a block restores the state it found, so one nested
102
+ in another, or called while recording is already off, leaves it off. It used
103
+ to turn recording back on when its block ended, and what followed was recorded.
104
+ - **Breaking.** The options passed to `recorder` — `ignore:`, `only:`,
105
+ `associations:` and `changes:` — are applied again. Since 1.2.2 they were
106
+ stored on the class while the recorder read them off the record, so every
107
+ model fell back to the global configuration. Models that
108
+ declare options now record what they asked for, which changes existing audit
109
+ trails going forward:
110
+ - `only:` and `ignore:` shrink the snapshot, and an update touching only
111
+ excluded attributes no longer writes a revision.
112
+ - A per-model `ignore:` replaces `Recorder.config.ignore` for that model, so
113
+ globally ignored attributes it does not repeat start being recorded. The
114
+ same holds for `only:`: an attribute it lists is recorded even if the
115
+ global list ignores it. To keep the global list, repeat it, as in
116
+ `ignore: [*Recorder.config.ignore, :token]`.
117
+ - `associations:` adds an `associations` key to create and destroy revisions.
118
+
119
+ A `recorder_options` instance method on the model still takes precedence, and
120
+ replaces the declared options rather than merging with them.
121
+ - **Breaking.** A subclass, STI included, records under the options its parent
122
+ passed to `recorder`. It used to record as if no options were given, so a
123
+ subclass's revisions change shape the way a declaring model's do above.
124
+ - A `recorder_options` instance method defined as private is used. It used to
125
+ be ignored, and the model recorded as if no options were given.
126
+ - **Breaking.** Revisions of an STI subclass store the base class name in
127
+ `item_type`, the model's `polymorphic_name`, so `revisions` finds them. They
128
+ stored the subclass name, which no Active Record lookup through `item` or
129
+ `revisions` matches, so `revisions` on a subclass instance returned nothing.
130
+ Queries that filter `item_type` by a subclass name stop matching new rows;
131
+ filter by the base class, or by the snapshot's inheritance column. Existing
132
+ rows are not rewritten; the README has a snippet that does it.
133
+ - An `action_date` set through `Recorder.info` is recorded, under a symbol or a
134
+ string key. Every revision used to be dated with the server's `Date.today`
135
+ instead, so a revision could not be backdated. A nil or blank one falls back
136
+ to today.
137
+ - `Recorder.info` stores its keys as symbols, so a string key replaces the
138
+ symbol one. Both used to be kept, and which reached the revision depended on
139
+ the order they were set in.
140
+ - **Breaking.** `action_date` is today in the application's time zone,
141
+ `Date.current`, whether the controller concern sets it or nothing does. It
142
+ was the server's date, so an app whose `config.time_zone` differs from the
143
+ server's records a different date for changes made near midnight. Existing
144
+ rows keep the server's date, so a trail that spans the upgrade holds both.
145
+ - `Revision.ordered_by_created_at` orders revisions with the same `created_at`
146
+ by `id`, newest first. They used to come back in whatever order the database
147
+ returned them, so the latest of two revisions written in the same instant
148
+ was not reliably `first`.
149
+ - **Breaking.** A revision records each association named in `associations:`
150
+ as an `attributes` snapshot, on `create` and `destroy` only. It used to add
151
+ the associated record's `saved_changes`, which describe that in-memory
152
+ record's last save rather than the one being recorded. So a revision could
153
+ claim an association changed when it had not, and an update touching only
154
+ excluded attributes still wrote a revision whenever the associated record had
155
+ been saved earlier in the process. An associated record's changes belong to
156
+ its own revisions, so an edit saved through the item, with `autosave:` or
157
+ nested attributes, is recorded only when the associated model records itself
158
+ too. Replacing a `belongs_to` target shows up as the foreign key in the item's
159
+ `changes`; replacing a `has_one` target shows up only in the associated
160
+ records' own revisions. `update` revisions no longer carry `associations`.
161
+ - **Breaking.** `Revision#changed_associations` lists only the associations
162
+ that hold changes, where it listed every recorded one.
163
+ `Revision#association_changeset` returns `nil` when the revision holds no
164
+ changes for that association, or when the item is gone or no longer has that
165
+ association set. It used to raise `KeyError` or `NoMethodError`.
166
+ - **Breaking.** A `destroy` revision's `changes` hold only the entries from
167
+ `changes:`, and the key is omitted when there are none. They used to carry
168
+ the record's `saved_changes`, which `destroy` does not clear, so destroying a
169
+ record saved earlier through the same instance repeated that save's diff, as
170
+ if the deletion had changed those attributes. The `attributes` snapshot is
171
+ unchanged. Existing destroy revisions keep the stale `changes`.
172
+ - `associations:` logs a warning, through the model's logger and once per model
173
+ and process, when it names a collection (`has_many`,
174
+ `has_and_belongs_to_many`) or a name that is not an association of the model.
175
+ Both are still left out of the revision, as before, but used to be skipped
176
+ without a word. A name that only a sibling subclass declares is skipped
177
+ without a warning.
178
+ - **Breaking.** A revision that fails validation, or that a callback on
179
+ `Recorder::Revision` halts, raises `Recorder::RevisionNotSaved`, a new
180
+ subclass of `ActiveRecord::RecordNotSaved` whose `record` is the revision.
181
+ It raises from the save of the observed record, `save` and `update` included,
182
+ so the save rolls back, along with any transaction around it that does not
183
+ rescue the error. Such a revision used to be dropped and the save went
184
+ through without it. A transaction of your own that rescues the error
185
+ commits the record without its revision. An app that adds validations or
186
+ callbacks to `Recorder::Revision` sees them fail the save.
187
+ - **Breaking.** A revision's `attributes`, and the `attributes` of each
188
+ association it records, hold the values the record last loaded from or
189
+ saved to the database: an attribute assigned and never saved keeps its
190
+ saved value. They used to be the in-memory values, which match the database
191
+ after a `create` or an `update` but not after a `destroy`, which saves
192
+ nothing, so a destroy revision could record values the deleted row never
193
+ held. On `destroy`, an associated record that was never saved is left out of
194
+ `associations`; the item's snapshot still holds the foreign key it was
195
+ saved with. Existing rows are not rewritten.
196
+ - An app that loads a gem defining `ProtectedAttributes`, such as
197
+ `protected_attributes_continued`, records revisions. `Recorder::Revision`
198
+ declared `attr_accessible` whenever that constant was defined, and the list
199
+ left out `item_type` and `item_id`, so every revision failed validation and
200
+ was dropped.
201
+
10
202
  ## [1.4.0]
11
203
 
12
204
  ### Added
@@ -136,7 +328,8 @@ Releases at and before 1.1.1 predate this changelog. See the
136
328
  [commit history](https://github.com/jetrockets/recorder/commits/master) for
137
329
  details.
138
330
 
139
- [Unreleased]: https://github.com/jetrockets/recorder/compare/v1.4.0...HEAD
331
+ [Unreleased]: https://github.com/jetrockets/recorder/compare/v2.0.0...HEAD
332
+ [2.0.0]: https://github.com/jetrockets/recorder/compare/v1.4.0...v2.0.0
140
333
  [1.4.0]: https://github.com/jetrockets/recorder/compare/v1.3.0...v1.4.0
141
334
  [1.3.0]: https://github.com/jetrockets/recorder/compare/v1.2.3...v1.3.0
142
335
  [1.2.3]: https://github.com/jetrockets/recorder/compare/v1.2.2...v1.2.3