diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 1ee9f55d4..ecac6ee5a 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,6 +1,4 @@ class ContentController < ApplicationController - include ContentHelper - def accessibility_statement render_content_page :accessibility_statement end @@ -8,4 +6,19 @@ class ContentController < ApplicationController def privacy_notice render_content_page :privacy_notice, page_title: "Privacy notice for tenants and buyers of new social housing" end + +private + + def render_content_page(page_name, page_title: nil, locals: {}) + raw_content = File.read("app/views/content/#{page_name}.md") + content_with_erb_tags_replaced = ApplicationController.renderer.render( + inline: raw_content, + locals:, + ) + + @page_title = page_title || page_name.to_s.humanize + @page_content = GovukMarkdown.render(content_with_erb_tags_replaced).html_safe + + render "content/page" + end end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb deleted file mode 100644 index 1f81e9a3c..000000000 --- a/app/helpers/content_helper.rb +++ /dev/null @@ -1,14 +0,0 @@ -module ContentHelper - def render_content_page(page_name, page_title: nil, locals: {}) - raw_content = File.read("app/views/content/#{page_name}.md") - content_with_erb_tags_replaced = ApplicationController.renderer.render( - inline: raw_content, - locals:, - ) - - page_title ||= page_name.to_s.humanize - page_content = GovukMarkdown.render(content_with_erb_tags_replaced).html_safe - - render "content/page", locals: { page_title:, page_content: } - end -end diff --git a/app/views/content/page.html.erb b/app/views/content/page.html.erb index 87b59160e..39acc46f9 100644 --- a/app/views/content/page.html.erb +++ b/app/views/content/page.html.erb @@ -1,9 +1,9 @@ -<%= content_for :title, page_title %> +<%= content_for :title, @page_title %>
-

<%= page_title %>

+

<%= @page_title %>

- <%= page_content %> + <%= @page_content %>
diff --git a/spec/helpers/content_helper_spec.rb b/spec/helpers/content_helper_spec.rb deleted file mode 100644 index 8c5172226..000000000 --- a/spec/helpers/content_helper_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "rails_helper" - -RSpec.describe ContentHelper do - let(:page_name) { "privacy_notice" } - - describe "render content page" do - it "returns the page" do - expected_html = "Privacy notice" - expect(render_content_page(page_name)).to match(expected_html) - expect(page).to have_title("Privacy notice") - end - end -end diff --git a/spec/requests/content_controller_spec.rb b/spec/requests/content_controller_spec.rb new file mode 100644 index 000000000..78a236709 --- /dev/null +++ b/spec/requests/content_controller_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe ContentController, type: :request do + let(:headers) { { "Accept" => "text/html" } } + let(:page) { Capybara::Node::Simple.new(response.body) } + + describe "render privacy notice content page" do + before do + get "/privacy-notice", headers: headers, params: {} + end + + it "returns a 200" do + expect(response).to have_http_status(:success) + end + + it "returns the page" do + expect(page).to have_title("Privacy notice") + end + end + + describe "render accessibility statement content page" do + before do + get "/accessibility-statement", headers: headers, params: {} + end + + it "returns a 200" do + expect(response).to have_http_status(:success) + end + + it "returns the page" do + expect(page).to have_title("Accessibility statement") + end + end +end