Skip to content

Commit 8f3f089

Browse files
authored
Merge pull request #3654 from nhsuk/fix-incomplete-location-address-formatting
Refactor location display to handle missing addresses gracefully
2 parents 3fb1667 + 1a456af commit 8f3f089

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app/helpers/address_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ def format_address_multi_line(addressable)
88
def format_address_single_line(addressable)
99
addressable.address_parts.join(", ")
1010
end
11+
12+
def format_location_name_and_address_single_line(location)
13+
[location.name, format_address_single_line(location)].compact_blank.join(
14+
", "
15+
)
16+
end
1117
end

app/views/draft_vaccination_records/location.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
text: title } do %>
1515

1616
<% @locations.each do |location| %>
17-
<%= f.govuk_radio_button :location_name, "#{location.name}, #{format_address_single_line(location)}",
17+
<%= f.govuk_radio_button :location_name, format_location_name_and_address_single_line(location),
1818
label: { text: location.name },
1919
hint: { text: format_address_single_line(location) } %>
2020
<% end %>

spec/helpers/address_helper_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
let(:location) do
55
create(
66
:school,
7+
name: "School of Politics",
78
address_line_1: "10 Downing Street",
89
address_town: "London",
910
address_postcode: "SW1A 1AA"
@@ -21,4 +22,26 @@
2122

2223
it { should eq("10 Downing Street, London, SW1A 1AA") }
2324
end
25+
26+
describe "#format_location_name_and_address_single_line" do
27+
subject(:formatted_string) do
28+
helper.format_location_name_and_address_single_line(location)
29+
end
30+
31+
it { should eq("School of Politics, 10 Downing Street, London, SW1A 1AA") }
32+
33+
context "with a nil address" do
34+
let(:location) do
35+
create(
36+
:school,
37+
name: "School of Politics",
38+
address_line_1: "",
39+
address_town: "",
40+
address_postcode: ""
41+
)
42+
end
43+
44+
it { should eq("School of Politics") }
45+
end
46+
end
2447
end

0 commit comments

Comments
 (0)