From 493fc01b9dc287dcf48c575257bb3ffac81a2bec Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 27 Apr 2022 10:59:08 +0100 Subject: [PATCH] Ensure filters work when ID is passed --- spec/models/case_log_spec.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index e24222d3e..005e8c057 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1897,10 +1897,19 @@ RSpec.describe CaseLog do let(:organisation_1) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_3) { FactoryBot.create(:organisation) } - let!(:case_log_1) { FactoryBot.create(:case_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1) } - let!(:case_log_2) { FactoryBot.create(:case_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2) } - let!(:case_log_3) { FactoryBot.create(:case_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1) } - let!(:case_log_4) { FactoryBot.create(:case_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2) } + + before do + FactoryBot.create(:case_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1) + FactoryBot.create(:case_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2) + FactoryBot.create(:case_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1) + FactoryBot.create(:case_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2) + end + + it "filters by given organisation id" do + expect(described_class.filter_by_organisation([organisation_1.id]).count).to eq(3) + expect(described_class.filter_by_organisation([organisation_1.id, organisation_2.id]).count).to eq(4) + expect(described_class.filter_by_organisation([organisation_3.id]).count).to eq(0) + end it "filters by given organisation" do expect(described_class.filter_by_organisation([organisation_1]).count).to eq(3)