Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Update ruby linting #48

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,51 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.6.2)
parallel (1.22.1)
parser (3.1.2.1)
json (2.6.3)
language_server-protocol (3.17.0.3)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
prettier_print (1.2.0)
racc
prettier_print (1.2.1)
racc (1.7.3)
rainbow (3.1.1)
regexp_parser (2.6.0)
rexml (3.2.5)
rubocop (1.36.0)
regexp_parser (2.8.2)
rexml (3.2.6)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-discourse (3.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-discourse (3.4.1)
rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0)
rubocop-rspec (2.13.2)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
syntax_tree (5.1.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
unicode-display_width (2.3.0)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-20
arm64-darwin-22
ruby
x86_64-linux

DEPENDENCIES
rubocop-discourse
Expand Down
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
27 changes: 13 additions & 14 deletions spec/jobs/scheduled/remove_orphaned_scanned_uploads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
require "rails_helper"

describe Jobs::RemoveOrphanedScannedUploads do
let(:upload) { Fabricate(:upload) }
subject(:execute) { described_class.new.execute({}) }

before do
SiteSetting.discourse_antivirus_enabled = true
@scanned_upload = ScannedUpload.create_new!(upload)
end
let(:upload) { Fabricate(:upload) }
let!(:scanned_upload) { ScannedUpload.create_new!(upload) }

it "does nothing if the upload still exists" do
subject.execute({})
before { SiteSetting.discourse_antivirus_enabled = true }

expect(@scanned_upload.reload).to be_present
context "when the upload still exists" do
it "does nothing" do
expect { execute }.not_to change { scanned_upload.reload }
end
end

it "deletes the scanned upload if the upload is gone" do
upload.destroy!

subject.execute({})
orphaned_upload = ScannedUpload.find_by(id: @scanned_upload.id)
context "when the upload is gone" do
before { upload.destroy! }

expect(orphaned_upload).to be_nil
it "deletes the scanned upload" do
expect { execute }.to change { ScannedUpload.where(id: scanned_upload.id).count }.by(-1)
end
end
end