Skip to content

Commit

Permalink
Document AS < 7.1 edge case regardless of AS version we're running on
Browse files Browse the repository at this point in the history
This kill mutation that re-surfaced after upgrading to AS 7.1

Related:
https://github.com/rails/rails/blob/3520cc77df1b52a6c808083214b583c769e9a4b2/activesupport/lib/active_support/time_with_zone.rb#L44-L53

Co-authored-by: Szymon Fiedler <szymon.fiedler@gmail.com>
Co-authored-by: Piotr Jurewicz <pjurewicz93@gmail.com>
  • Loading branch information
3 people committed May 23, 2024
1 parent 4c0ae47 commit 317ea8b
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,35 @@ module Transformation
expect(transformation.dump(record).metadata[:types]).to eq({ data: "OpenStruct", metadata: {} })
expect(transformation.load(transformation.dump(record))).to eq(record)
end

specify "handle classes with overloaded name like ActiveSupport::TimeWithZone < 7.1" do
::RoyalTimeWithZone = Class.new(ActiveSupport::TimeWithZone) do
def self.name
"Time"
end
end

zone = Time.find_zone('Europe/Warsaw')
transformation = PreserveTypes.new.register(
::RoyalTimeWithZone,
serializer: -> (v) { v.utc.iso8601(9) },
deserializer: -> (v) { ::RoyalTimeWithZone.new(Time.iso8601(v), zone) },
stored_type: -> (*) { "RoyalTimeWithZone" }
)

record =
Record.new(
event_id: uuid,
metadata: {},
data: ::RoyalTimeWithZone.new(Time.utc(2024, 5, 23), zone),
event_type: "TestEvent",
timestamp: nil,
valid_at: nil
)

expect(transformation.dump(record).metadata[:types]).to eq({ data: "RoyalTimeWithZone", metadata: {} })
expect(transformation.load(transformation.dump(record))).to eq(record)
end
end
end
end
Expand Down

0 comments on commit 317ea8b

Please sign in to comment.