Testing Custom Primary Key Versioning in PaperTrail
This test suite evaluates the versioning functionality for models with custom primary keys in the PaperTrail gem. It focuses on verifying the proper creation and retrieval of version records for models using non-standard primary key configurations. The tests ensure version instances maintain correct class relationships and reification capabilities.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/models/custom_primary_key_record_spec.rb
# frozen_string_literal: true
require "spec_helper"
RSpec.describe CustomPrimaryKeyRecord, type: :model do
it { is_expected.to be_versioned }
describe "#versions" do
it "returns instances of CustomPrimaryKeyRecordVersion", versioning: true do
custom_primary_key_record = described_class.create!
custom_primary_key_record.update!(name: "bob")
version = custom_primary_key_record.versions.last
expect(version).to be_a(CustomPrimaryKeyRecordVersion)
version_from_db = CustomPrimaryKeyRecordVersion.last
expect(version_from_db.reify).to be_a(described_class)
custom_primary_key_record.destroy
expect(CustomPrimaryKeyRecordVersion.last.reify).to be_a(described_class)
end
end
end