Skip to content

Commit 9a806db

Browse files
committed
feat: Add manual content item
- Copied over the method from government_frontend.This method memoizes the content item from content store to avoid any subsequent calls to content store via gds_api through Services module. Audit trail: https://github.com/alphagov/government-frontend/blob/main/app/presenters/content_item/manual_section.rb#L40
1 parent 49f2b20 commit 9a806db

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

app/models/concerns/manual_parts.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def breadcrumbs
2626
},
2727
]
2828
end
29+
30+
def manual_content_item
31+
@manual_content_item ||= Services.content_store.content_item(base_path)
32+
end
33+
34+
def parsed_content_item
35+
manual_content_item.parsed_content
36+
end
2937
end
3038

3139
private

lib/services.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "gds_api/content_store"
2+
3+
module Services
4+
def self.content_store
5+
@content_store ||= GdsApi::ContentStore.new(
6+
Plek.new.find("content-store"),
7+
# Disable caching to avoid caching a stale max-age in the cache control
8+
# headers, which would cause this app to set the wrong max-age on its
9+
# own responses
10+
disable_cache: true,
11+
)
12+
end
13+
end

spec/models/manual_section_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
it_behaves_like "it can have page title", "manual_section", "what-is-content-design"
44
it_behaves_like "it can have document heading", "manual_section", "what-is-content-design"
55
it_behaves_like "it can have breadcrumbs", "manual_section", "what-is-content-design"
6+
it_behaves_like "it can have manual content item", "manual_section", "what-is-content-design"
67
end

spec/support/concerns/manual_parts.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@
2929
expect(described_class.new(content_item).breadcrumbs).to eq([{ title: "Back to contents", url: "/guidance/content-design/what-is-content-design" }])
3030
end
3131
end
32+
33+
RSpec.shared_examples "it can have manual content item" do |document_type, example_name|
34+
let(:content_item) { GovukSchemas::Example.find(document_type, example_name:) }
35+
36+
it "returns an empty hash when content store returns empty body" do
37+
stub_request(:get, "http://content-store.dev.gov.uk/content/guidance/content-design/what-is-content-design")
38+
.to_return(status: 200, body: "{}", headers: {})
39+
40+
expect(described_class.new(content_item).parsed_content_item).to eq({})
41+
end
42+
end

0 commit comments

Comments
 (0)