Skip to content

Commit c033435

Browse files
authored
Merge pull request #5898 from nhsuk/clear-out-draft-vaccination-record
Clear out draft vaccination record
2 parents 2093d1b + f18542d commit c033435

4 files changed

Lines changed: 81 additions & 6 deletions

File tree

app/controllers/vaccination_records_controller.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ def show
99
end
1010

1111
def update
12-
DraftVaccinationRecord.new(
13-
request_session: session,
14-
current_user:
15-
).read_from!(@vaccination_record)
12+
draft_vaccination_record =
13+
DraftVaccinationRecord.new(request_session: session, current_user:)
14+
# TODO: Refactor this so that we don't need to clear out the attributes from
15+
# the draft record(s) in this use case. This likely means changing
16+
# RequestSessionPersistable to do this clearing out. One possible
17+
# approach would be to change `new` to instantiate without loading
18+
# values from the session, and adding `new_from_session` to replace
19+
# the existing functionality in `new`.
20+
draft_vaccination_record.clear!
21+
draft_vaccination_record.clear_changes_information
22+
draft_vaccination_record.read_from!(@vaccination_record)
1623

1724
redirect_to draft_vaccination_record_path("confirm")
1825
end

app/models/draft_vaccination_record.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def initialize(current_user:, **attributes)
4949
if: :performed_by_user
5050
}
5151

52-
validates :source, inclusion: { in: VaccinationRecord.sources.keys }
53-
5452
def wizard_steps
5553
[
5654
:identity,
@@ -146,6 +144,7 @@ def wizard_steps
146144
:protocol,
147145
presence: true
148146
validates :full_dose, inclusion: { in: [true, false] }
147+
validates :source, inclusion: { in: VaccinationRecord.sources.keys }
149148
end
150149

151150
def administered?

spec/features/edit_vaccination_record_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@
424424
then_i_should_see_the_vaccination_record
425425
and_i_should_see_the_patient_based_breadcrumb
426426
end
427+
428+
scenario "User edits two vaccination records with different delivery methods" do
429+
given_i_am_signed_in
430+
and_a_bulk_uploaded_vaccination_record_exists
431+
and_a_vaccination_record_with_a_different_delivery_method_exists
432+
433+
when_i_visit_the_first_vaccination_record_directly
434+
and_i_click_on_edit_vaccination_record
435+
436+
and_i_visit_the_flu_vaccination_record_directly
437+
and_i_click_on_edit_vaccination_record
438+
and_i_click_on_save_changes
439+
440+
then_i_should_see_a_success_message
441+
end
427442
end
428443

429444
def given_an_hpv_programme_is_underway
@@ -541,6 +556,33 @@ def and_a_bulk_uploaded_vaccination_record_exists
541556
)
542557
end
543558

559+
def and_a_vaccination_record_with_a_different_delivery_method_exists
560+
@flu_programme = Programme.flu
561+
@flu_vaccine = @flu_programme.vaccines.first
562+
@flu_batch =
563+
create(:batch, :not_expired, team: @team, vaccine: @flu_vaccine)
564+
565+
@flu_vaccination_record =
566+
create(
567+
:vaccination_record,
568+
:sourced_from_bulk_upload,
569+
uploaded_by: @team.users.first,
570+
delivery_method: :nasal_spray,
571+
delivery_site: :nose,
572+
batch: @flu_batch,
573+
vaccine: @flu_batch.vaccine,
574+
patient: @patient,
575+
programme: @flu_programme,
576+
performed_by_user: nil,
577+
performed_by_given_name: "Albus",
578+
performed_by_family_name: "Dumbledore"
579+
)
580+
581+
expect(@flu_vaccination_record.delivery_method).not_to eq(
582+
@vaccination_record.delivery_method
583+
)
584+
end
585+
544586
def and_a_delayed_triage_exists
545587
delay_date = @vaccination_record.performed_at + 28.days
546588
@delayed_triage =
@@ -996,6 +1038,13 @@ def when_i_visit_the_vaccination_record_directly
9961038
visit vaccination_record_path(@vaccination_record)
9971039
end
9981040

1041+
alias_method :when_i_visit_the_first_vaccination_record_directly,
1042+
:when_i_visit_the_vaccination_record_directly
1043+
1044+
def and_i_visit_the_flu_vaccination_record_directly
1045+
visit vaccination_record_path(@flu_vaccination_record)
1046+
end
1047+
9991048
def and_i_should_see_the_session_specific_breadcrumb
10001049
breadcrumb = page.find(".nhsuk-breadcrumb")
10011050
expect(breadcrumb).to have_content("Sessions")
@@ -1030,4 +1079,18 @@ def and_i_should_see_the_patient_based_breadcrumb
10301079
expect(breadcrumb).to have_content("Children")
10311080
expect(breadcrumb).not_to have_content("Sessions")
10321081
end
1082+
1083+
def when_i_edit_the_first_vaccination_record
1084+
visit vaccination_record_path(@vaccination_record)
1085+
1086+
click_on "Edit vaccination record"
1087+
click_on "Save changes"
1088+
end
1089+
1090+
def then_i_should_see_a_success_message
1091+
expect(page).to have_alert(
1092+
"Success",
1093+
text: "Vaccination outcome recorded for flu"
1094+
)
1095+
end
10331096
end

spec/models/draft_vaccination_record_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@
227227
end
228228

229229
context "when source is 'service'" do
230+
before { draft_vaccination_record.wizard_step = :confirm }
231+
230232
let(:attributes) { valid_administered_attributes }
231233

232234
it "is valid" do
@@ -236,6 +238,8 @@
236238
end
237239

238240
context "when source is invalid" do
241+
before { draft_vaccination_record.wizard_step = :confirm }
242+
239243
let(:attributes) do
240244
valid_administered_attributes.merge(source: "invalid_source")
241245
end
@@ -249,6 +253,8 @@
249253
end
250254

251255
context "when source is nil" do
256+
before { draft_vaccination_record.wizard_step = :confirm }
257+
252258
let(:attributes) { valid_administered_attributes.except(:source) }
253259

254260
it "is invalid" do

0 commit comments

Comments
 (0)