Testing Custom JSON Serializer Implementation in PaperTrail
This test suite validates the custom JSON serialization functionality in PaperTrail, focusing on proper handling of key-value pairs during serialization and deserialization. The tests ensure robust data handling by verifying the removal of blank keys and nil values during these operations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
paper-trail-gem/paper_trail
spec/paper_trail/serializers/custom_json_serializer_spec.rb
# frozen_string_literal: true
require "spec_helper"
require_relative "../../support/custom_json_serializer"
RSpec.describe CustomJsonSerializer do
describe ".load" do
it "deserializes, removing pairs with blank keys or values" do
hash = { "key1" => "banana", "tkey" => nil, "" => "foo" }
expect(described_class.load(hash.to_json)).to(eq("key1" => "banana"))
end
end
describe ".dump" do
it "serializes to JSON, removing pairs with nil values" do
hash = { "key1" => "banana", "tkey" => nil, "" => "foo" }
expect(described_class.dump(hash)).to(eq('{"key1":"banana","":"foo"}'))
end
end
end