Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/case_study_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CaseStudyController < ContentItemsController
def show
@case_study_presenter = ContentItemModelPresenter.new(content_item)
end
end
8 changes: 8 additions & 0 deletions app/models/case_study.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CaseStudy < ContentItem
include Updatable
include WorldwideOrganisations

def related_entities
(linkable_organisations + worldwide_organisations).uniq
end
end
71 changes: 71 additions & 0 deletions app/views/case_study/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<% content_for :title, "#{@case_study_presenter.page_title} - #{I18n.t("formats.#{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 %>

<main role="main" id="content" class="case-study" <%= lang_attribute(content_item.locale) %>>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds responsive-top-margin">
<%= render 'govuk_publishing_components/components/title', {
title: content_item.title,
context: I18n.t("formats.#{content_item.document_type}", count: 1),
context_locale: t_locale_fallback("formats.#{content_item.document_type}", count: 1),
average_title_length: "long",
} %>
</div>
<%= render 'shared/translations' %>
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/lead_paragraph', text: content_item.description %>
</div>
</div>

<%= render 'shared/publisher_metadata', locals: {
from: govuk_styled_links_list(content_item.related_entities),
first_published: display_date(content_item.first_public_at || content_item.first_published_at),
last_updated: display_date(content_item.updated),
see_updates_link: true,
}
%>

<% if content_item.withdrawn? %>
<% withdrawn_time_tag = tag.time(display_date(content_item.withdrawn_at), datetime: content_item.withdrawn_at) %>

<%= render 'govuk_publishing_components/components/notice', {
title: I18n.t("formats.case_study.withdrawn_notice.title", schema_name: I18n.t("formats.#{content_item.schema_name}", count: 1, locale: :en).downcase, withdrawn_time: withdrawn_time_tag).html_safe,
description_govspeak: content_item.withdrawn_explanation&.html_safe,
time: withdrawn_time_tag,
lang: "en",
} %>
<% 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_public_at),
last_updated: display_date(content_item.updated),
history: content_item.history
} %>
</div>
</div>

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

<%= 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 @@ -77,6 +77,8 @@
# Placeholder for attachments being virus-scanned
get "/placeholder", to: "placeholder#show"

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

scope "/get-involved" do
get "/", to: "get_involved#show"
get "/take-part/:slug", to: "take_part#show"
Expand Down
4 changes: 4 additions & 0 deletions spec/models/case_study_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RSpec.describe CaseStudy do
it_behaves_like "it can be updated", "case_study"
it_behaves_like "it can have worldwide organisations", "case_study"
end
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 "when visiting the index route" do
it "returns 200" do
get "/government/case-studies/get-britain-building-carlisle-park"

expect(response).to have_http_status(:ok)
end
end
end
41 changes: 41 additions & 0 deletions spec/system/case_study_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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

it_behaves_like "it has meta tags", "case_study", "/government/case-studies/doing-business-in-spain"
it_behaves_like "it has meta tags for images", "case_study", "/government/case-studies/doing-business-in-spain"

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 ca267f5

Please sign in to comment.