Sha256: 9a71e30978eb7efa61a650f212406ecb281ef60f054be9d89c8db42ecf6dfd9b

Contents?: true

Size: 1.41 KB

Versions: 18

Compression:

Stored size: 1.41 KB

Contents

require "rails_helper"

RSpec.describe FileScanJob, type: :job do
  subject { described_class.new }
  let(:scanned_file) { double(clean?: true) }
  let(:unscanned_file) { double(id: 1, clean?: false, content_type: "text/plain", filename: "test.txt") }
  let(:success_response) { double(success?: true) }
  let(:error_response) { double(success?: false, body: "Error response body") }

  it "deals with a nil argument" do
    expect { subject.perform nil }.to_not raise_error
  end

  it "returns quickly if the file is already scanned" do
    expect { subject.perform scanned_file }.to_not raise_error
  end

  it "updates the scan_status after scanning the file" do
    now = Time.now
    allow(Time).to receive(:now).and_return now
    allow(unscanned_file).to receive(:open).and_yield __FILE__
    expect(unscanned_file).to receive(:update_columns).with scan_status: "scanned", updated_at: Time.now
    allow(subject).to receive(:connection).and_return double(post: success_response)
    subject.perform unscanned_file
  end

  it "marks the file as quarantined when dirty" do
    now = Time.now
    allow(Time).to receive(:now).and_return now
    allow(unscanned_file).to receive(:open).and_yield __FILE__
    expect(unscanned_file).to receive(:update_columns).with scan_status: "quarantined", updated_at: Time.now
    allow(subject).to receive(:connection).and_return double(post: error_response)
    subject.perform unscanned_file
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rails_template_18f-2.0.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-1.3.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-1.2.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-1.1.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-1.0.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.8.2 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.8.1 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.8.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.7.2 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.7.1 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.7.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.6.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.5.3 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.5.2 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.5.1 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.5.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.4.1 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb
rails_template_18f-0.4.0 lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb