Testing Version Control Behavior with EmptyArray in PaperTrail
This test suite examines the behavior of the EmptyArray class in PaperTrail’s versioning system. It specifically focuses on verifying that certain operations do not create version records when configured with empty arrays. The tests validate core versioning functionality while handling edge cases for version creation control.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/models/on/empty_array_spec.rb
# frozen_string_literal: true
require "spec_helper"
require_dependency "on/empty_array"
module On
RSpec.describe EmptyArray, type: :model, versioning: true do
describe "#create" do
it "does not create any version records" do
record = described_class.create(name: "Alice")
expect(record.versions.length).to(eq(0))
end
end
describe ".paper_trail.update_columns" do
it "creates a version record" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.paper_trail.update_columns(name: "Bugle")
assert_equal 2, widget.versions.length
end
end
describe "#update" do
it "does not create any version records" do
record = described_class.create(name: "Alice")
record.update(name: "blah")
expect(record.versions.length).to(eq(0))
end
end
end
end