Skip to content

Commit 3251e13

Browse files
committed
Add hide_from_search_engines method
- we have to add a robots noindex tag to pages that are children of a list of specific pages in the publication presenter - extends model to include parent
1 parent 51d9d2b commit 3251e13

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

app/models/html_publication.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class HtmlPublication < ContentItem
2+
def parent
3+
linked("parent").first
4+
end
25
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class HtmlPublicationPresenter < ContentItemPresenter
2+
def hide_from_search_engines?
3+
PublicationPresenter::PATHS_TO_HIDE.include? content_item.parent.base_path
4+
end
25
end

app/views/html_publication/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
schema: :html_publication,
66
content_item: content_item.to_h %>
77

8-
<% if content_item.hide_from_search_engines? %>
8+
<% if @presenter.hide_from_search_engines? %>
99
<meta name="robots" content="noindex">
1010
<% end %>
1111
<% end %>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
RSpec.describe HtmlPublication do
2+
subject(:html_publication) { described_class.new(content_store_response) }
3+
4+
let(:content_store_response) { GovukSchemas::Example.find("html_publication", example_name: "published") }
5+
6+
it "returns a parent" do
7+
expect(html_publication.parent.content_id).to eq("8b19c238-54e3-4e27-b0d7-60f8e2a677c9")
8+
end
29
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
RSpec.describe HtmlPublicationPresenter do
2+
subject(:html_publication_presenter) { described_class.new(HtmlPublication.new(content_store_response)) }
3+
4+
let(:content_store_response) { GovukSchemas::Example.find("html_publication", example_name: "long_form_and_automatically_numbered_headings") }
5+
6+
describe "#hide_from_search_engines?" do
7+
it "returns false" do
8+
expect(html_publication_presenter.hide_from_search_engines?).to be false
9+
end
10+
11+
context "when the page is in the hide list" do
12+
let(:content_store_response) do
13+
GovukSchemas::Example.find(:html_publication, example_name: "long_form_and_automatically_numbered_headings").tap do |example|
14+
example["links"]["parent"][0]["base_path"] = "/government/publications/govuk-app-testing-privacy-notice-how-we-use-your-data"
15+
end
16+
end
17+
18+
it "returns true" do
19+
expect(html_publication_presenter.hide_from_search_engines?).to be true
20+
end
21+
end
22+
end
223
end

0 commit comments

Comments
 (0)