diff --git a/spec/serializers/rest/account_relationship_severance_event_serializer_spec.rb b/spec/serializers/rest/account_relationship_severance_event_serializer_spec.rb index a69e1c2776..909fde39b3 100644 --- a/spec/serializers/rest/account_relationship_severance_event_serializer_spec.rb +++ b/spec/serializers/rest/account_relationship_severance_event_serializer_spec.rb @@ -11,14 +11,9 @@ RSpec.describe REST::AccountRelationshipSeveranceEventSerializer do it 'returns expected values' do expect(subject) .to include( - 'id' => be_a(String).and(eq('123')) + 'id' => be_a(String).and(eq('123')), + 'created_at' => match_api_datetime_format ) end end - - context 'when created_at is populated' do - it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error - end - end end diff --git a/spec/serializers/rest/account_serializer/field_serializer_spec.rb b/spec/serializers/rest/account_serializer/field_serializer_spec.rb index 57f2b529c5..6d97fa573e 100644 --- a/spec/serializers/rest/account_serializer/field_serializer_spec.rb +++ b/spec/serializers/rest/account_serializer/field_serializer_spec.rb @@ -6,14 +6,16 @@ RSpec.describe REST::AccountSerializer::FieldSerializer do subject { serialized_record_json(field, described_class) } let(:default_datetime) { DateTime.new(2024, 11, 28, 16, 20, 0) } - let(:user) { Fabricate(:user) } - let(:account) { user.account } + let(:account) { Fabricate.build :account } context 'when verified_at is populated' do let(:field) { Account::Field.new(account, 'name' => 'Foo', 'value' => 'Bar', 'verified_at' => default_datetime) } it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['verified_at']) }.to_not raise_error + expect(subject) + .to include( + 'verified_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/account_serializer_spec.rb b/spec/serializers/rest/account_serializer_spec.rb index 37c6a776b0..5fd4f8d706 100644 --- a/spec/serializers/rest/account_serializer_spec.rb +++ b/spec/serializers/rest/account_serializer_spec.rb @@ -52,7 +52,10 @@ RSpec.describe REST::AccountSerializer do end it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end diff --git a/spec/serializers/rest/account_warning_serializer_spec.rb b/spec/serializers/rest/account_warning_serializer_spec.rb index ea2e48fbb4..a7a9dc5f63 100644 --- a/spec/serializers/rest/account_warning_serializer_spec.rb +++ b/spec/serializers/rest/account_warning_serializer_spec.rb @@ -12,9 +12,9 @@ RSpec.describe REST::AccountWarningSerializer do expect(subject) .to include( 'id' => be_a(String).and(eq('123')), - 'status_ids' => be_a(Array).and(eq(['456', '789'])) + 'status_ids' => be_a(Array).and(eq(['456', '789'])), + 'created_at' => match_api_datetime_format ) - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error end end end diff --git a/spec/serializers/rest/admin/account_serializer_spec.rb b/spec/serializers/rest/admin/account_serializer_spec.rb index ac7cec0bae..5f617207a7 100644 --- a/spec/serializers/rest/admin/account_serializer_spec.rb +++ b/spec/serializers/rest/admin/account_serializer_spec.rb @@ -9,7 +9,10 @@ RSpec.describe REST::Admin::AccountSerializer do let(:record) { Fabricate :account, user: Fabricate(:user) } it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end diff --git a/spec/serializers/rest/admin/cohort_serializer_spec.rb b/spec/serializers/rest/admin/cohort_serializer_spec.rb index a2bd8fbfa2..1305f901bb 100644 --- a/spec/serializers/rest/admin/cohort_serializer_spec.rb +++ b/spec/serializers/rest/admin/cohort_serializer_spec.rb @@ -11,11 +11,11 @@ RSpec.describe REST::Admin::CohortSerializer do it 'returns expected values' do expect(subject) .to include( - 'data' => be_a(Array), - 'period' => /2024-01-01/ + 'data' => be_a(Array).and( + all(include('date' => match_api_datetime_format)) + ), + 'period' => match(/2024-01-01/).and(match_api_datetime_format) ) - expect { DateTime.rfc3339(subject['period']) }.to_not raise_error - subject['data'].each { |datum| expect { DateTime.rfc3339(datum['date']) }.to_not raise_error } end end end diff --git a/spec/serializers/rest/admin/domain_allow_serializer_spec.rb b/spec/serializers/rest/admin/domain_allow_serializer_spec.rb index 39c013d31c..ace35176a7 100644 --- a/spec/serializers/rest/admin/domain_allow_serializer_spec.rb +++ b/spec/serializers/rest/admin/domain_allow_serializer_spec.rb @@ -9,7 +9,10 @@ RSpec.describe REST::Admin::DomainAllowSerializer do context 'when created_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/admin/domain_block_serializer_spec.rb b/spec/serializers/rest/admin/domain_block_serializer_spec.rb index 5ab3ddc169..37d658b1f7 100644 --- a/spec/serializers/rest/admin/domain_block_serializer_spec.rb +++ b/spec/serializers/rest/admin/domain_block_serializer_spec.rb @@ -9,7 +9,10 @@ RSpec.describe REST::Admin::DomainBlockSerializer do context 'when created_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/admin/email_domain_block_serializer_spec.rb b/spec/serializers/rest/admin/email_domain_block_serializer_spec.rb index 2a1501a158..e146040e24 100644 --- a/spec/serializers/rest/admin/email_domain_block_serializer_spec.rb +++ b/spec/serializers/rest/admin/email_domain_block_serializer_spec.rb @@ -9,7 +9,10 @@ RSpec.describe REST::Admin::EmailDomainBlockSerializer do context 'when created_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/admin/ip_block_serializer_spec.rb b/spec/serializers/rest/admin/ip_block_serializer_spec.rb index c1239b5057..8a68161fc2 100644 --- a/spec/serializers/rest/admin/ip_block_serializer_spec.rb +++ b/spec/serializers/rest/admin/ip_block_serializer_spec.rb @@ -5,19 +5,15 @@ require 'rails_helper' RSpec.describe REST::Admin::IpBlockSerializer do subject { serialized_record_json(record, described_class) } - let(:record) { Fabricate(:ip_block) } - - context 'when created_at is populated' do - it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error - end - end - - context 'when expires_at is populated' do + context 'when timestamps are populated' do let(:record) { Fabricate(:ip_block, expires_at: DateTime.new(2024, 11, 28, 16, 20, 0)) } it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['expires_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format, + 'expires_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/admin/ip_serializer_spec.rb b/spec/serializers/rest/admin/ip_serializer_spec.rb index f93eada759..5aabf74756 100644 --- a/spec/serializers/rest/admin/ip_serializer_spec.rb +++ b/spec/serializers/rest/admin/ip_serializer_spec.rb @@ -9,7 +9,10 @@ RSpec.describe REST::Admin::IpSerializer do context 'when used_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['used_at']) }.to_not raise_error + expect(subject) + .to include( + 'used_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/admin/measure_serializer_spec.rb b/spec/serializers/rest/admin/measure_serializer_spec.rb index 08c7170a4a..e158d9d9ba 100644 --- a/spec/serializers/rest/admin/measure_serializer_spec.rb +++ b/spec/serializers/rest/admin/measure_serializer_spec.rb @@ -12,7 +12,12 @@ RSpec.describe REST::Admin::MeasureSerializer do context 'when start_at is populated' do it 'parses as RFC 3339 datetime' do - subject['data'].each { |datum| expect { DateTime.rfc3339(datum['date']) }.to_not raise_error } + expect(subject) + .to include( + 'data' => all( + include('date' => match_api_datetime_format) + ) + ) end end end diff --git a/spec/serializers/rest/admin/report_serializer_spec.rb b/spec/serializers/rest/admin/report_serializer_spec.rb index c0f841d6bf..78d7d4f10a 100644 --- a/spec/serializers/rest/admin/report_serializer_spec.rb +++ b/spec/serializers/rest/admin/report_serializer_spec.rb @@ -5,23 +5,15 @@ require 'rails_helper' RSpec.describe REST::Admin::ReportSerializer do subject { serialized_record_json(report, described_class) } - let(:report) { Fabricate(:report) } - - context 'with created_at' do - it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error - end - end - - context 'with action_taken_at' do - let(:acting_account) { Fabricate(:account) } - - before do - report.resolve!(acting_account) - end + context 'with timestamps' do + let(:report) { Fabricate(:report, action_taken_at: 3.days.ago) } it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['action_taken_at']) }.to_not raise_error + expect(subject) + .to include( + 'action_taken_at' => match_api_datetime_format, + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/announcement_serializer_spec.rb b/spec/serializers/rest/announcement_serializer_spec.rb index 6b746e5c2f..ee0acab981 100644 --- a/spec/serializers/rest/announcement_serializer_spec.rb +++ b/spec/serializers/rest/announcement_serializer_spec.rb @@ -19,10 +19,13 @@ RSpec.describe REST::AnnouncementSerializer do context 'when date fields are populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['starts_at']) }.to_not raise_error - expect { DateTime.rfc3339(subject['ends_at']) }.to_not raise_error - expect { DateTime.rfc3339(subject['published_at']) }.to_not raise_error - expect { DateTime.rfc3339(subject['updated_at']) }.to_not raise_error + expect(subject) + .to include( + 'starts_at' => match_api_datetime_format, + 'ends_at' => match_api_datetime_format, + 'published_at' => match_api_datetime_format, + 'updated_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/filter_serializer_spec.rb b/spec/serializers/rest/filter_serializer_spec.rb index c2c0e1635a..4d38a29acb 100644 --- a/spec/serializers/rest/filter_serializer_spec.rb +++ b/spec/serializers/rest/filter_serializer_spec.rb @@ -10,11 +10,14 @@ RSpec.describe REST::FilterSerializer do ) end - let(:filter) { Fabricate :custom_filter, expires_at: DateTime.new(2024, 11, 28, 16, 20, 0) } + let(:filter) { Fabricate.build :custom_filter, expires_at: DateTime.new(2024, 11, 28, 16, 20, 0) } context 'when expires_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['expires_at']) }.to_not raise_error + expect(subject) + .to include( + 'expires_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/marker_serializer_spec.rb b/spec/serializers/rest/marker_serializer_spec.rb index 8b8285c9e8..58266319eb 100644 --- a/spec/serializers/rest/marker_serializer_spec.rb +++ b/spec/serializers/rest/marker_serializer_spec.rb @@ -14,7 +14,10 @@ RSpec.describe REST::MarkerSerializer do context 'when updated_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['updated_at']) }.to_not raise_error + expect(subject) + .to include( + 'updated_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/muted_account_serializer_spec.rb b/spec/serializers/rest/muted_account_serializer_spec.rb index 2a6dd9fe17..2db3f7be95 100644 --- a/spec/serializers/rest/muted_account_serializer_spec.rb +++ b/spec/serializers/rest/muted_account_serializer_spec.rb @@ -25,7 +25,10 @@ RSpec.describe REST::MutedAccountSerializer do end it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['mute_expires_at']) }.to_not raise_error + expect(subject) + .to include( + 'mute_expires_at' => match_api_datetime_format + ) end end diff --git a/spec/serializers/rest/notification_group_serializer_spec.rb b/spec/serializers/rest/notification_group_serializer_spec.rb index 2a1293292d..01fd8ce0a1 100644 --- a/spec/serializers/rest/notification_group_serializer_spec.rb +++ b/spec/serializers/rest/notification_group_serializer_spec.rb @@ -14,7 +14,10 @@ RSpec.describe REST::NotificationGroupSerializer do context 'when latest_page_notification_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['latest_page_notification_at']) }.to_not raise_error + expect(subject) + .to include( + 'latest_page_notification_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/notification_request_serializer_spec.rb b/spec/serializers/rest/notification_request_serializer_spec.rb index 34332679d6..6dc4b04f5c 100644 --- a/spec/serializers/rest/notification_request_serializer_spec.rb +++ b/spec/serializers/rest/notification_request_serializer_spec.rb @@ -17,15 +17,13 @@ RSpec.describe REST::NotificationRequestSerializer do let(:current_user) { Fabricate(:user) } let(:notification_request) { Fabricate :notification_request } - context 'when created_at is populated' do + context 'when timestampts are populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error - end - end - - context 'when updated_at is populated' do - it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['updated_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format, + 'updated_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/notification_serializer_spec.rb b/spec/serializers/rest/notification_serializer_spec.rb index 7296c1b935..b833bcb6e1 100644 --- a/spec/serializers/rest/notification_serializer_spec.rb +++ b/spec/serializers/rest/notification_serializer_spec.rb @@ -14,7 +14,10 @@ RSpec.describe REST::NotificationSerializer do context 'when created_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/poll_serializer_spec.rb b/spec/serializers/rest/poll_serializer_spec.rb index 71ed9deb3e..3837ac1984 100644 --- a/spec/serializers/rest/poll_serializer_spec.rb +++ b/spec/serializers/rest/poll_serializer_spec.rb @@ -15,11 +15,14 @@ RSpec.describe REST::PollSerializer do end let(:current_user) { Fabricate(:user) } - let(:poll) { Fabricate :poll } + let(:poll) { Fabricate.build :poll, expires_at: 5.days.from_now } context 'when expires_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['expires_at']) }.to_not raise_error + expect(subject) + .to include( + 'expires_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/report_serializer_spec.rb b/spec/serializers/rest/report_serializer_spec.rb index 5cbeb0fee0..180cdbdb68 100644 --- a/spec/serializers/rest/report_serializer_spec.rb +++ b/spec/serializers/rest/report_serializer_spec.rb @@ -10,24 +10,15 @@ RSpec.describe REST::ReportSerializer do ) end - let(:status) { Fabricate(:status) } - let(:report) { Fabricate(:report, status_ids: [status.id]) } - - context 'with created_at' do - it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error - end - end - - context 'with action_taken_at' do - let(:acting_account) { Fabricate(:account) } - - before do - report.resolve!(acting_account) - end + context 'with timestamps' do + let(:report) { Fabricate(:report, action_taken_at: 3.days.ago) } it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['action_taken_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format, + 'action_taken_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/scheduled_status_serializer_spec.rb b/spec/serializers/rest/scheduled_status_serializer_spec.rb index 2fe689766f..08ad8a6f8a 100644 --- a/spec/serializers/rest/scheduled_status_serializer_spec.rb +++ b/spec/serializers/rest/scheduled_status_serializer_spec.rb @@ -10,19 +10,15 @@ RSpec.describe REST::ScheduledStatusSerializer do ) end - let(:account) { Fabricate(:account) } - let(:scheduled_status) { Fabricate.build(:scheduled_status, scheduled_at: 4.minutes.from_now, account: account, params: { application_id: 123 }) } + let(:scheduled_status) { Fabricate.build(:scheduled_status, scheduled_at: 4.minutes.from_now, params: { application_id: 123 }) } describe 'serialization' do - it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['scheduled_at']) } - .to_not raise_error - end - it 'returns expected values and removes application_id from params' do expect(subject.deep_symbolize_keys) - .to include(scheduled_at: be_a(String)) - .and include(params: not_include(:application_id)) + .to include( + scheduled_at: be_a(String).and(match_api_datetime_format), + params: not_include(:application_id) + ) end end end diff --git a/spec/serializers/rest/status_edit_serializer_spec.rb b/spec/serializers/rest/status_edit_serializer_spec.rb index 1f5ac54b7b..95590d1f96 100644 --- a/spec/serializers/rest/status_edit_serializer_spec.rb +++ b/spec/serializers/rest/status_edit_serializer_spec.rb @@ -14,7 +14,10 @@ RSpec.describe REST::StatusEditSerializer do context 'when created_at is populated' do it 'parses as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end end diff --git a/spec/serializers/rest/status_serializer_spec.rb b/spec/serializers/rest/status_serializer_spec.rb index ca0591eb69..b6908aa414 100644 --- a/spec/serializers/rest/status_serializer_spec.rb +++ b/spec/serializers/rest/status_serializer_spec.rb @@ -54,7 +54,10 @@ RSpec.describe REST::StatusSerializer do context 'with created_at' do it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error + expect(subject) + .to include( + 'created_at' => match_api_datetime_format + ) end end @@ -62,7 +65,10 @@ RSpec.describe REST::StatusSerializer do let(:status) { Fabricate.build :status, edited_at: 3.days.ago } it 'is serialized as RFC 3339 datetime' do - expect { DateTime.rfc3339(subject['edited_at']) }.to_not raise_error + expect(subject) + .to include( + 'edited_at' => match_api_datetime_format + ) end end end diff --git a/spec/support/matchers/api_datetime_format.rb b/spec/support/matchers/api_datetime_format.rb new file mode 100644 index 0000000000..d19c909438 --- /dev/null +++ b/spec/support/matchers/api_datetime_format.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +RSpec::Matchers.define :match_api_datetime_format do + match(notify_expectation_failures: true) do |value| + expect { DateTime.rfc3339(value) } + .to_not raise_error + end +end