mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Docs: clarify the un-deletion example
The integer id (153) was a little confusing.
This commit is contained in:
parent
be7c6ae78e
commit
f5df000078
2 changed files with 22 additions and 3 deletions
|
@ -516,11 +516,12 @@ Note `version_at` gives you the object, not a version, so you don't need to call
|
|||
Undeleting is just as simple:
|
||||
|
||||
```ruby
|
||||
widget = Widget.find 42
|
||||
widget = Widget.find(42)
|
||||
widget.destroy
|
||||
# Time passes....
|
||||
widget = PaperTrail::Version.find(153).reify # the widget as it was before destruction
|
||||
widget.save # the widget lives!
|
||||
versions = widget.versions # versions ordered by versions.created_at, ascending
|
||||
widget = versions.last.reify # the widget as it was before destruction
|
||||
widget.save # the widget lives!
|
||||
```
|
||||
|
||||
You could even use PaperTrail to implement an undo system, [Ryan Bates has!][3]
|
||||
|
|
|
@ -155,6 +155,24 @@ describe Widget, type: :model do
|
|||
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
|
||||
assert_equal 2, versions_for_widget.length
|
||||
end
|
||||
|
||||
it "can have multiple destruction records" do
|
||||
versions = lambda { |widget|
|
||||
# Workaround for AR 3. When we drop AR 3 support, we can simply use
|
||||
# the `widget.versions` association, instead of `with_item_keys`.
|
||||
PaperTrail::Version.with_item_keys("Widget", widget.id)
|
||||
}
|
||||
widget = Widget.create
|
||||
assert_equal 1, widget.versions.length
|
||||
widget.destroy
|
||||
assert_equal 2, versions.call(widget).length
|
||||
widget = widget.version.reify
|
||||
widget.save
|
||||
assert_equal 3, versions.call(widget).length
|
||||
widget.destroy
|
||||
assert_equal 4, versions.call(widget).length
|
||||
assert_equal 2, versions.call(widget).where(event: "destroy").length
|
||||
end
|
||||
end
|
||||
|
||||
describe "#paper_trail.originator" do
|
||||
|
|
Loading…
Reference in a new issue