0
0
Fork 0

Ensure datetime/date are serialized to correct format (#33086)

This commit is contained in:
Nik Clayton 2024-12-14 16:50:41 +01:00 committed by GitHub
parent a8edc82471
commit 5cf37248cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 515 additions and 5 deletions

View file

@ -5,9 +5,11 @@ require 'rails_helper'
RSpec.describe REST::ExtendedDescriptionSerializer do
subject { serialized_record_json(record, described_class) }
let(:default_datetime) { DateTime.new(2024, 11, 28, 16, 20, 0) }
describe 'serialization' do
context 'with text present' do
let(:record) { ExtendedDescription.new text: 'Hello world', updated_at: Date.new(2024, 1, 1) }
let(:record) { ExtendedDescription.new text: 'Hello world', updated_at: default_datetime }
it 'returns expected values' do
expect(subject)
@ -15,19 +17,19 @@ RSpec.describe REST::ExtendedDescriptionSerializer do
'content' => eq(<<~HTML),
<p>Hello world</p>
HTML
'updated_at' => eq('2024-01-01')
'updated_at' => eq('2024-11-28T16:20:00+00:00')
)
end
end
context 'with text missing' do
let(:record) { ExtendedDescription.new text: nil, updated_at: Date.new(2024, 1, 1) }
let(:record) { ExtendedDescription.new text: nil, updated_at: default_datetime }
it 'returns expected values' do
expect(subject)
.to include(
'content' => eq(''),
'updated_at' => eq('2024-01-01')
'updated_at' => eq('2024-11-28T16:20:00+00:00')
)
end
end