1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
# frozen_string_literal: true
require "spec_helper"
module PaperTrail
module AttributeSerializers
::RSpec.describe ObjectAttribute do
if ENV["DB"] == "postgres"
describe "postgres-specific column types" do
describe "#serialize" do
it "serializes a postgres array into a plain array" do
attrs = { "post_ids" => [1, 2, 3] }
described_class.new(PostgresUser).serialize(attrs)
expect(attrs["post_ids"]).to eq [1, 2, 3]
end
end
describe "#deserialize" do
it "deserializes a plain array correctly" do
attrs = { "post_ids" => [1, 2, 3] }
described_class.new(PostgresUser).deserialize(attrs)
expect(attrs["post_ids"]).to eq [1, 2, 3]
end
it "deserializes an array serialized with Rails <= 5.0.1 correctly" do
attrs = { "post_ids" => "{1,2,3}" }
described_class.new(PostgresUser).deserialize(attrs)
expect(attrs["post_ids"]).to eq [1, 2, 3]
end
it "deserializes an array of time objects correctly" do
date1 = 1.day.ago
date2 = 2.days.ago
date3 = 3.days.ago
attrs = { "post_ids" => [date1, date2, date3] }
described_class.new(PostgresUser).serialize(attrs)
described_class.new(PostgresUser).deserialize(attrs)
expect(attrs["post_ids"]).to eq [date1, date2, date3]
end
end
end
end
end
end
end
|