Skip to content

Commit

Permalink
DEBUG-2334 add new_record flag to AR model custom serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Nov 26, 2024
1 parent ce4393e commit 04f6e7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/datadog/di/contrib/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# steep:ignore:start
value_to_serialize = {
attributes: value.attributes,
new_record: value.new_record?,
}
serializer.serialize_value(value_to_serialize, depth: depth ? depth - 1 : nil, type: value.class)
# steep:ignore:end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def mysql_connection_string
expected: {type: "SerializerRailsSpecTestEmptyModel", entries: [[
{type: 'Symbol', value: 'attributes'},
{type: 'Hash', entries: [[{type: 'String', value: 'id'}, {type: 'NilClass', isNull: true}]]},
], [
{type: 'Symbol', value: 'new_record'},
{type: 'TrueClass', value: 'true'},
]]}},
{name: "AR model with empty attributes",
input: -> { SerializerRailsSpecTestBasicModel.new },
Expand All @@ -89,6 +92,9 @@ def mysql_connection_string
[{type: 'String', value: 'created_at'}, {type: 'NilClass', isNull: true}],
[{type: 'String', value: 'updated_at'}, {type: 'NilClass', isNull: true}],
]},
], [
{type: 'Symbol', value: 'new_record'},
{type: 'TrueClass', value: 'true'},
]]}},
{name: "AR model with filled out attributes",
input: -> {
Expand All @@ -105,6 +111,28 @@ def mysql_connection_string
[{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}],
[{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}],
]},
], [
{type: 'Symbol', value: 'new_record'},
{type: 'TrueClass', value: 'true'},
]]}},
{name: "AR model with filled out attributes and persisted",
input: -> {
SerializerRailsSpecTestBasicModel.create!(
title: 'Hello, world!', created_at: Time.utc(2020, 1, 2), updated_at: Time.utc(2020, 1, 3)
)
},
expected: {type: "SerializerRailsSpecTestBasicModel", entries: [[
{type: 'Symbol', value: 'attributes'},
{type: 'Hash', entries: [
[{type: 'String', value: 'id'}, {type: 'Integer', value: '1'}],
[{type: 'String', value: 'title'}, {type: 'String', value: 'Hello, world!'}],
# TODO serialize Time, Date, DateTime types
[{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}],
[{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}],
]},
], [
{type: 'Symbol', value: 'new_record'},
{type: 'FalseClass', value: 'false'},
]]}},
]

Expand Down

0 comments on commit 04f6e7e

Please sign in to comment.