From f6daf73286e4a0ac34d8334d5e408911834b9b06 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 11 Dec 2024 03:24:50 -0500 Subject: [PATCH] Add non-matching cases to `Report#history` spec (#33253) --- spec/models/report_spec.rb | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index e62b2e9094..2384c73acc 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -105,25 +105,32 @@ RSpec.describe Report do describe 'history' do subject(:action_logs) { report.history } - let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) } + let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id]) } let(:target_account) { Fabricate(:account) } let(:status) { Fabricate(:status) } let(:account_warning) { Fabricate(:account_warning, report_id: report.id) } - before do - Fabricate(:action_log, target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago) - Fabricate(:action_log, target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago) - Fabricate(:action_log, target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago) - Fabricate(:action_log, target_type: 'AccountWarning', account_id: target_account.id, target_id: account_warning.id, created_at: 2.days.ago) - end + let!(:matched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning', target_id: account_warning.id) } + let!(:matched_type_account) { Fabricate(:action_log, target_type: 'Account', target_id: report.target_account_id) } + let!(:matched_type_report) { Fabricate(:action_log, target_type: 'Report', target_id: report.id) } + let!(:matched_type_status) { Fabricate(:action_log, target_type: 'Status', target_id: status.id) } + + let!(:unmatched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning') } + let!(:unmatched_type_account) { Fabricate(:action_log, target_type: 'Account') } + let!(:unmatched_type_report) { Fabricate(:action_log, target_type: 'Report') } + let!(:unmatched_type_status) { Fabricate(:action_log, target_type: 'Status') } it 'returns expected logs' do expect(action_logs) .to have_attributes(count: 4) - .and include(have_attributes(target_type: 'Account')) - .and include(have_attributes(target_type: 'AccountWarning')) - .and include(have_attributes(target_type: 'Report')) - .and include(have_attributes(target_type: 'Status')) + .and include(matched_type_account_warning) + .and include(matched_type_account) + .and include(matched_type_report) + .and include(matched_type_status) + .and not_include(unmatched_type_account_warning) + .and not_include(unmatched_type_account) + .and not_include(unmatched_type_report) + .and not_include(unmatched_type_status) end end