From 6c45123809b50982f8cbed5ab37c8bdaeef9b1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Thu, 30 Nov 2023 16:48:25 +0100 Subject: [PATCH] Use named subjects in specs --- .../flag_quarantined_uploads_spec.rb | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/spec/jobs/scheduled/flag_quarantined_uploads_spec.rb b/spec/jobs/scheduled/flag_quarantined_uploads_spec.rb index b64c9d8..9fd28b0 100644 --- a/spec/jobs/scheduled/flag_quarantined_uploads_spec.rb +++ b/spec/jobs/scheduled/flag_quarantined_uploads_spec.rb @@ -4,51 +4,49 @@ describe Jobs::FlagQuarantinedUploads do describe "#execute" do + subject(:execute) { described_class.new.execute({}) } + let(:scan_message) { "Win.Test.EICAR_HDB-1 FOUND" } let(:upload) { Fabricate(:upload) } - - before do - SiteSetting.flag_malicious_uploads = true - @scanned_upload = - ScannedUpload.create!(upload: upload, quarantined: true, scan_result: scan_message) + let(:reviewable_upload) { ReviewableUpload.find_by(target: upload) } + let!(:scanned_upload) do + ScannedUpload.create!(upload: upload, quarantined: true, scan_result: scan_message) end - it "flags the upload if it was previously quarantined" do - subject.execute({}) - - reviewable_upload = ReviewableUpload.find_by(target: upload) + before { SiteSetting.flag_malicious_uploads = true } - expect(reviewable_upload).to be_present + it "flags the upload if it was previously quarantined" do + execute expect(reviewable_upload.payload["scan_message"]).to eq(scan_message) end - it "does nothing if the flag_malicious_uploads flag is disabled" do - SiteSetting.flag_malicious_uploads = false - - subject.execute({}) - reviewable_upload = ReviewableUpload.find_by(target: upload) + context "when the flag_malicious_uploads flag is disabled" do + before { SiteSetting.flag_malicious_uploads = false } - expect(reviewable_upload).to be_nil + it "does nothing" do + execute + expect(reviewable_upload).to be_nil + end end - it "does nothing if a reviewable already exists" do - @scanned_upload.flag_upload - - subject.execute({}) + context "when a reviewable already exists" do + before { scanned_upload.flag_upload } - reviewable_upload = ReviewableUpload.find_by(target: upload) - scores = reviewable_upload.reviewable_scores + it "does nothing" do + execute - expect(scores.size).to eq(1) + expect(reviewable_upload.reviewable_scores.size).to eq(1) + end end - it "does nothing if the scanned upload is not quarantined" do - @scanned_upload.update!(quarantined: false) + context "when the scanned upload is not quarantined" do + before { scanned_upload.update!(quarantined: false) } - subject.execute({}) - reviewable_upload = ReviewableUpload.find_by(target: upload) + it "does nothing" do + execute - expect(reviewable_upload).to be_nil + expect(reviewable_upload).to be_nil + end end end end