Skip to content

Commit

Permalink
change not_ran scope. add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Jan 6, 2025
1 parent 0d79888 commit 910fcd7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RejectApplicationsController < NpqSeparation::AdminController

def create
if (file = params.dig(:bulk_operation_reject_applications, :file))
BulkOperation::RejectApplications.not_ran.destroy_all
BulkOperation::RejectApplications.not_started.destroy_all
@bulk_operation.file.attach(file)
if @bulk_operation.valid?
@bulk_operation.save!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RevertApplicationsToPendingController < NpqSeparation::AdminController

def create
if (file = params.dig(:bulk_operation_revert_applications_to_pending, :file))
BulkOperation::RevertApplicationsToPending.not_ran.destroy_all
BulkOperation::RevertApplicationsToPending.not_started.destroy_all
@bulk_operation.file.attach(file)
if @bulk_operation.valid?
@bulk_operation.save!
Expand Down
2 changes: 1 addition & 1 deletion app/models/bulk_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class BulkOperation < ApplicationRecord

validate :file_valid

scope :not_ran, -> { where(result: nil) }
scope :not_started, -> { where(started_at: nil) }

def started?
started_at.present?
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/bulk_operation/reject_applications.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryBot.define do
factory :reject_applications, class: BulkOperation::RejectApplications do
factory :reject_applications_bulk_operation, class: BulkOperation::RejectApplications do
admin { create(:admin) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end
end
let(:uploaded_file) { Rack::Test::UploadedFile.new(file.path) }
let(:application_ecf_ids) { [SecureRandom.uuid] }
let(:application_ecf_ids) { [SecureRandom.uuid, SecureRandom.uuid] }

it "calls BulkOperation::BulkChangeApplicationsToPending" do
expect(BulkOperation::BulkChangeApplicationsToPending).to receive(:new).with(application_ecf_ids:).and_call_original
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/bulk_operation/bulk_reject_applications_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe "#perform" do
subject { described_class.new.perform(bulk_operation_id:) }

let(:bulk_operation) { create(:reject_applications, admin: create(:admin), file: uploaded_file) }
let(:bulk_operation) { create(:reject_applications_bulk_operation, admin: create(:admin), file: uploaded_file) }
let(:bulk_operation_id) { bulk_operation.id }
let(:file) do
Tempfile.new.tap do |file|
Expand All @@ -13,7 +13,7 @@
end
end
let(:uploaded_file) { Rack::Test::UploadedFile.new(file.path) }
let(:application_ecf_ids) { [SecureRandom.uuid] }
let(:application_ecf_ids) { [SecureRandom.uuid, SecureRandom.uuid] }

it "calls BulkOperation::BulkRejectApplications" do
expect(BulkOperation::BulkRejectApplications).to receive(:new).with(application_ecf_ids:).and_call_original
Expand Down
23 changes: 22 additions & 1 deletion spec/models/bulk_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,31 @@
end

describe "scopes" do
context "not_ran" do
describe "not_started" do
let(:started_bulk_operation) { create(:reject_applications_bulk_operation, started_at: Time.zone.yesterday) }
let(:not_started_bulk_operation) { create(:reject_applications_bulk_operation, started_at: nil) }

it "returns not started bulk opeartions" do
expect(BulkOperation.not_started).to eq [not_started_bulk_operation]
end
end
end

describe "#started?" do
context "when started_at present" do
let(:bulk_operation) { build(:reject_applications_bulk_operation, started_at: Time.zone.yesterday) }

it "returns true" do
expect(bulk_operation.started?).to be true
end
end

context "when started_at not present" do
let(:bulk_operation) { create(:reject_applications_bulk_operation, started_at: nil) }

it "returns false" do
expect(bulk_operation.started?).to be false
end
end
end
end

0 comments on commit 910fcd7

Please sign in to comment.