Skip to content

Commit

Permalink
Use named subjects in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Flink committed Nov 30, 2023
1 parent 58a1aab commit 6c45123
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions spec/jobs/scheduled/flag_quarantined_uploads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6c45123

Please sign in to comment.