Testing Version Association Implementation in PaperTrail
This test suite validates the versioning functionality in the PaperTrail gem’s Thing model, focusing on version association scoping and extension behaviors. The tests ensure proper version ordering and custom inspection formatting.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/models/thing_spec.rb
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Thing, type: :model do
describe "#versions", versioning: true do
let(:thing) { described_class.create! }
it "applies the scope option" do
expect(described_class.reflect_on_association(:versions).scope).to be_a Proc
expect(thing.versions.to_sql).to end_with "ORDER BY id desc"
end
it "applies the extend option" do
expect(thing.versions.singleton_class).to be < PrefixVersionsInspectWithCount
expect(thing.versions.inspect).to start_with("1 versions:")
end
end
end