Testing Destroy Event Version Management in PaperTrail
This test suite validates the destroy functionality and event tracking in the PaperTrail gem, focusing on version record creation and custom event handling during model destruction. The tests ensure proper version management and event naming when objects are destroyed.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/models/on/destroy_spec.rb
# frozen_string_literal: true
require "spec_helper"
require_dependency "on/destroy"
module On
RSpec.describe Destroy, type: :model, versioning: true do
describe "#versions" do
it "only creates one version record, for the destroy event" do
record = described_class.create(name: "Alice")
record.update(name: "blah")
record.destroy
expect(record.versions.length).to(eq(1))
expect(record.versions.last.event).to(eq("destroy"))
end
end
describe "#paper_trail_event" do
it "rembembers the custom event name" do
record = described_class.create(name: "Alice")
record.paper_trail_event = "banana"
record.update(name: "blah")
record.destroy
expect(record.versions.length).to(eq(1))
expect(record.versions.last.event).to(eq("banana"))
end
end
end
end