Testing Plant Model Versioning and STI Implementation in Paper Trail
This test suite validates the Paper Trail versioning functionality for the Plant model, focusing on Single Table Inheritance (STI) implementation and version restoration. The tests ensure proper model versioning and handling of non-standard STI column contents across different plant types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/models/plant_spec.rb
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Plant, type: :model, versioning: true do
it "baseline test setup" do
expect(described_class.new).to be_versioned
expect(described_class.inheritance_column).to eq("species")
end
describe "#descends_from_active_record?" do
it "returns true, meaning that Animal is not an STI subclass" do
expect(described_class.descends_from_active_record?).to eq(true)
end
end
it "works with non standard STI column contents" do
plant = described_class.create
plant.destroy
tomato = Tomato.create
tomato.destroy
reified = plant.versions.last.reify
expect(reified.class).to eq(described_class)
reified = tomato.versions.last.reify
expect(reified.class).to eq(Tomato)
end
end