Skip to content

Commit 76bf0e5

Browse files
committed
Avoid creating vaccines
This should prevent flaky tests where they sometimes fail when the vaccine is cached on the programme and then unavailable in other tests.
1 parent 9b37b2f commit 76bf0e5

5 files changed

Lines changed: 21 additions & 19 deletions

File tree

spec/helpers/consents_helper_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@
44
subject(:reasons) { helper.consent_refusal_reasons(consent) }
55

66
shared_examples "refusal reason label" do |expected_label|
7-
before do
8-
create(
9-
:vaccine,
10-
:contains_gelatine,
11-
programme_type: programme.type,
12-
disease_types: programme.disease_types
13-
)
14-
end
15-
167
it "uses the programme-specific refusal reason label" do
178
reason = reasons.find { |reason| reason.value == "contains_gelatine" }
189
expect(reason.label).to eq(expected_label) if reason

spec/lib/fhir_mapper/vaccine_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
subject(:fhir_mapper) { described_class.new(vaccine) }
55

66
let(:vaccine) do
7-
create(
7+
build(
88
:vaccine,
99
:injection,
1010
snomed_product_code: "183817183",
@@ -58,7 +58,7 @@
5858
end
5959

6060
context "with flu injection vaccine, dose 1" do
61-
let(:vaccine) { create(:vaccine, :flu, :injection) }
61+
let(:vaccine) { build(:vaccine, :flu, :injection) }
6262

6363
it "pairs the correct code with the correct term" do
6464
coding =
@@ -72,7 +72,7 @@
7272
end
7373

7474
context "with flu nasal vaccine, dose 2" do
75-
let(:vaccine) { create(:vaccine, :flu, :nasal) }
75+
let(:vaccine) { build(:vaccine, :flu, :nasal) }
7676

7777
it "pairs the correct code with the correct term" do
7878
coding =

spec/models/batch_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
# fk_rails_... (vaccine_id => vaccines.id)
2525
#
2626
describe Batch do
27-
subject(:batch) { build(:batch) }
27+
subject(:batch) { build(:batch, vaccine:) }
28+
29+
let(:vaccine) { Vaccine.all.sample }
2830

2931
describe "scopes" do
30-
let(:archived_batch) { create(:batch, :archived) }
31-
let(:not_archived_batch) { create(:batch) }
32+
let(:archived_batch) { create(:batch, :archived, vaccine:) }
33+
let(:not_archived_batch) { create(:batch, vaccine:) }
3234

3335
describe "#archived" do
3436
subject(:scope) { described_class.archived }
@@ -79,7 +81,7 @@
7981
end
8082

8183
context "when already archived" do
82-
let(:batch) { create(:batch, :archived) }
84+
let(:batch) { create(:batch, :archived, vaccine:) }
8385

8486
it "doesn't change archived_at" do
8587
expect { archive! }.not_to change(batch, :archived_at)

spec/models/health_question_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
let(:vaccine) { create(:vaccine) }
3434
let!(:hqs) { create_list(:health_question, 3, vaccine:) }
3535

36+
around(:all) do |example|
37+
# This is safe because we don't reference a programme at any point.
38+
Vaccine.enable_factorybot_factories = true
39+
example.run
40+
Vaccine.enable_factorybot_factories = false
41+
end
42+
3643
describe "#first_health_question" do
3744
it "returns the first health question" do
3845
hqs.first.update! next_question: hqs.second

spec/policies/batch_policy_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
let(:team) { create(:team) }
88
let(:user) { create(:user, team:) }
99

10-
let(:batch) { create(:batch, team:) }
11-
let(:archived_batch) { create(:batch, :archived, team:) }
12-
let(:non_team_batch) { create(:batch) }
10+
let(:vaccine) { Vaccine.all.sample }
11+
12+
let(:batch) { create(:batch, team:, vaccine:) }
13+
let(:archived_batch) { create(:batch, :archived, team:, vaccine:) }
14+
let(:non_team_batch) { create(:batch, vaccine:) }
1315

1416
it { should include(batch) }
1517
it { should include(archived_batch) }

0 commit comments

Comments
 (0)