Skip to content

Commit c1d4028

Browse files
committed
Handle duplicate [withdrawn] in page title
1 parent 41abebb commit c1d4028

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def page_title(content_item = nil)
66

77
def build_page_title(elements = [], withdrawn: false)
88
title = (elements + ["GOV.UK"]).compact.join(" - ")
9-
withdrawn ? "[Withdrawn] #{title}" : title
9+
withdrawn && !title.start_with?("[Withdrawn]") ? "[Withdrawn] #{title}" : title
1010
end
1111

1212
def current_path_without_query_string

spec/helpers/application_helper_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
it "prepends the withdrawn tag if flag is set" do
4242
expect(build_page_title(["Title", nil, "Type"], withdrawn: true)).to eq("[Withdrawn] Title - Type - GOV.UK")
4343
end
44+
45+
it "does not prepend when title has withdrawn already" do
46+
expect(build_page_title(["[Withdrawn] Title", nil, "Type"], withdrawn: true)).to eq("[Withdrawn] Title - Type - GOV.UK")
47+
end
4448
end
4549

4650
describe "#current_path_without_query_string" do

0 commit comments

Comments
 (0)