Ensure datetime/date are serialized to correct format (#33086)
This commit is contained in:
parent
a8edc82471
commit
5cf37248cc
28 changed files with 515 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue