Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/case_studies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CaseStudiesController < ContentItemsController
def show
@case_study = CaseStudiesPresenter.new(@content_item, view_context)
end

private

def content_item_slug
request.path
end
end
5 changes: 5 additions & 0 deletions app/models/case_study.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CaseStudy < ContentItem
include Metadata
include Linkable
include Updatable
end
18 changes: 18 additions & 0 deletions app/presenters/case_studies_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CaseStudiesPresenter < ContentItemPresenter
attr_reader :content_item, :view_context

def initialize(content_item, view_context)
super(content_item)
@content_item = content_item
@view_context = view_context
end

def title_and_context
{
title: content_item.title,
context: I18n.t("content_item.schema_name.#{content_item.document_type}", count: 1),
context_locale: view_context.t_locale_fallback("content_item.schema_name.#{content_item.document_type}", count: 1),
average_title_length: "long",
}
end
end
52 changes: 52 additions & 0 deletions app/views/case_studies/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<% content_for :title, "#{@content_item.page_title} - #{I18n.t("content_item.schema_name.#{@content_item.document_type}", count: 1)} - GOV.UK" %>
<% content_for :extra_headers do %>
<%= render "govuk_publishing_components/components/machine_readable_metadata", { content_item: @content_item.to_h, schema: :article } %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds responsive-top-margin">
<%= render 'govuk_publishing_components/components/title', @case_study.title_and_context %>
</div>
<%= render 'shared/translations' %>
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %>
</div>
</div>

<hr class="govuk-section-break govuk-section-break--s govuk-section-break--visible" aria-hidden="true">

<%= render 'shared/publisher_metadata_with_logo' %>
<% if @content_item.withdrawn? %>
<%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="content-bottom-margin">
<div class="responsive-bottom-margin">
<%= render 'components/figure',
src: @content_item.image["url"],
alt: @content_item.image["alt_text"],
credit: @content_item.image["credit"],
caption: @content_item.image["caption"] if @content_item.image %>
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= raw(@content_item.body) %>
<% end %>
</div>

<%= render 'components/published_dates', {
published: display_date(@content_item.first_published_at),
last_updated: display_date(@content_item.updated),
history: @content_item.history
} %>
</div>
</div>

<%= render 'shared/sidebar_navigation' %>
</div>

<%= render 'shared/footer_navigation' %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
# Placeholder for attachments being virus-scanned
get "/placeholder", to: "placeholder#show"

get "/case-studies/:slug(.:locale)", to: "case_studies#show"

scope "/get-involved" do
get "/take-part/:slug", to: "take_part#show"
end
Expand Down
13 changes: 13 additions & 0 deletions spec/requests/case_study_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.describe "Case Study" do
before do
content_store_has_example_item("/government/case-studies/get-britain-building-carlisle-park", schema: :case_study)
end

context "GET index" do
it "returns 200" do
get "/government/case-studies/get-britain-building-carlisle-park"

expect(response).to have_http_status(:ok)
end
end
end
38 changes: 38 additions & 0 deletions spec/system/case_studies_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
RSpec.describe "CaseStudy" do
before do
content_store_has_example_item("/government/case-studies/get-britain-building-carlisle-park", schema: :case_study)
content_store_has_example_item("/government/case-studies/doing-business-in-spain", schema: :case_study, example: "doing-business-in-spain")
end

context "when visiting a Case Study page" do
it "displays the case_study page" do
visit "/government/case-studies/get-britain-building-carlisle-park"

expect(page).to have_title("Get Britain Building: Carlisle Park - Case study - GOV.UK")

expect(page).to have_css("h1", text: "Get Britain Building: Carlisle Park")
expect(page).to have_text("Nearly 400 homes are set to be built on the site of a former tar distillery thanks to Gleeson Homes and HCA investment.")

expect(page).to have_css(".gem-c-translation-nav")
end

context "when visiting a Withdrawn Case Study page which is also translatable" do
it "displays the case_study page" do
visit "/government/case-studies/doing-business-in-spain"

expect(page).to have_title("[Withdrawn] Doing business in Spain - Case study - GOV.UK")

expect(page).to have_css("h1", text: "Doing business in Spain")
expect(page).to have_text("This case study was withdrawn on")

expect(page).to have_css(".gem-c-translation-nav")
end
end

it "does not display a single page notification button" do
visit "/government/case-studies/get-britain-building-carlisle-park"

expect(page).not_to have_css(".gem-c-single-page-notification-button")
end
end
end

0 comments on commit 637866e

Please sign in to comment.