-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add case studies model, controller, presenter, route and tests
Commit audit trail: - https://github.com/alphagov/government-frontend/blob/0aee348d51cebacd5344115f2ca02bdb17095249/app/presenters/case_study_presenter.rb - https://github.com/alphagov/government-frontend/blob/0aee348d51cebacd5344115f2ca02bdb17095249/app/views/content_items/case_study.html.erb - https://github.com/alphagov/government-frontend/blob/0aee348d51cebacd5344115f2ca02bdb17095249/test/integration/case_study_test.rb - https://github.com/alphagov/government-frontend/blob/0aee348d51cebacd5344115f2ca02bdb17095249/test/presenters/case_study_presenter_test.rb - https://github.com/alphagov/government-frontend/blob/0aee348d51cebacd5344115f2ca02bdb17095249/config/routes.rb
- Loading branch information
1 parent
ca5ee62
commit b5517ce
Showing
7 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CaseStudy < ContentItem | ||
include Metadata | ||
include Linkable | ||
include Updatable | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("formats.#{content_item.document_type}", count: 1), | ||
context_locale: view_context.t_locale_fallback("formats.#{content_item.document_type}", count: 1), | ||
average_title_length: "long", | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<% content_for :title, "#{@content_item.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 %> | ||
|
||
<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' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
RSpec.describe "CaseStudy" do | ||
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" | ||
|
||
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 |