Skip to content

Commit

Permalink
Merge pull request #1635 from alphagov/stats-2
Browse files Browse the repository at this point in the history
Roll out Dataset schema to more types
  • Loading branch information
sihugh authored Jan 27, 2020
2 parents 37e4266 + f74b9d6 commit 0b56cd7
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 42 deletions.
6 changes: 5 additions & 1 deletion app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def documents_count
end

def national_statistics?
document_type === "national_statistics"
document_type == "national_statistics"
end

def dataset?
%(national_statistics official_statistics transparency).include? document_type
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% content_for :extra_head_content do %>
<%= machine_readable_metadata(
schema: :article
schema: (@content_item.dataset? ? :dataset : :article)
) %>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/govuk_content_schemas_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class GovukContentSchemasTest < ActionDispatch::IntegrationTest

all_examples_for_supported_schemas.each do |content_item|
test "can successfully render #{content_item['base_path']} schema example" do
content_store_has_item(content_item["base_path"], content_item)
stub_content_store_has_item(content_item["base_path"], content_item)

get content_item["base_path"]

Expand Down
18 changes: 9 additions & 9 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ContentItemsControllerTest < ActionController::TestCase

test "sets the expiry as sent by content-store" do
content_item = content_store_has_schema_example("coming_soon", "coming_soon")
content_store_has_item(content_item["base_path"], content_item, max_age: 20)
stub_content_store_has_item(content_item["base_path"], content_item, max_age: 20)

get :show, params: { path: path_for(content_item) }
assert_response :success
Expand All @@ -242,7 +242,7 @@ class ContentItemsControllerTest < ActionController::TestCase

test "honours cache-control private items" do
content_item = content_store_has_schema_example("coming_soon", "coming_soon")
content_store_has_item(content_item["base_path"], content_item, private: true)
stub_content_store_has_item(content_item["base_path"], content_item, private: true)

get :show, params: { path: path_for(content_item) }
assert_response :success
Expand Down Expand Up @@ -282,7 +282,7 @@ class ContentItemsControllerTest < ActionController::TestCase
utf8_path = "government/case-studies/caf\u00e9-culture"
content_item["base_path"] = "/#{utf8_path}"

content_store_has_item(content_item["base_path"], content_item)
stub_content_store_has_item(content_item["base_path"], content_item)

get :show, params: { path: utf8_path }
assert_response :success
Expand All @@ -291,7 +291,7 @@ class ContentItemsControllerTest < ActionController::TestCase
test "returns 404 for invalid url" do
path = "foreign-travel-advice/egypt]"

content_store_does_not_have_item("/" + path)
stub_content_store_does_not_have_item("/" + path)

get :show, params: { path: path }
assert_response :not_found
Expand All @@ -300,7 +300,7 @@ class ContentItemsControllerTest < ActionController::TestCase
test "returns 404 for item not in content store" do
path = "government/case-studies/boost-chocolate-production"

content_store_does_not_have_item("/" + path)
stub_content_store_does_not_have_item("/" + path)

get :show, params: { path: path }
assert_response :not_found
Expand All @@ -312,7 +312,7 @@ class ContentItemsControllerTest < ActionController::TestCase
content_item = content_store_has_schema_example("special_route", "special_route")
content_item["base_path"] = "/government"

content_store_has_item("/#{path}", content_item)
stub_content_store_has_item("/#{path}", content_item)

get :show, params: { path: path }
assert_response :not_found
Expand All @@ -335,22 +335,22 @@ class ContentItemsControllerTest < ActionController::TestCase
end

test "returns 410 for content items that are gone" do
content_store_has_gone_item("/gone-item")
stub_content_store_has_gone_item("/gone-item")
get :show, params: { path: "gone-item" }
assert_response :gone
end

test "returns a redirect when content item is a redirect" do
content_item = content_store_has_schema_example("redirect", "redirect")
content_store_has_item("/406beacon", content_item)
stub_content_store_has_item("/406beacon", content_item)

get :show, params: { path: "406beacon" }
assert_redirected_to "https://www.test.gov.uk/maritime-safety-weather-and-navigation/register-406-mhz-beacons?query=answer#fragment"
end

test "returns a prefixed redirect when content item is a prefix redirect" do
content_item = content_store_has_schema_example("redirect", "redirect")
content_store_has_item("/406beacon/prefix/to-preserve", content_item)
stub_content_store_has_item("/406beacon/prefix/to-preserve", content_item)

get :show, params: { path: "406beacon/prefix/to-preserve" }
assert_redirected_to "https://www.test.gov.uk/new-406-beacons-destination/to-preserve"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ContentItemsControllerTest < ActionController::TestCase
content_item = govuk_content_schema_example("service_sign_in", "service_sign_in")
link = "https://www.horse.service.gov.uk/account?horse=brown"
content_item["details"]["choose_sign_in"]["options"][0]["url"] = link
content_store_has_item(content_item["base_path"], content_item)
stub_content_store_has_item(content_item["base_path"], content_item)

path = "#{path_for(content_item)}/#{content_item['details']['choose_sign_in']['slug']}"

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/step_navigation_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ContentItemsControllerTest < ActionController::TestCase
content_item["base_path"] = "/pass-plus"
path = content_item["base_path"][1..-1]

content_store_has_item(content_item["base_path"], content_item)
stub_content_store_has_item(content_item["base_path"], content_item)

@controller.stubs(:page_in_scope?).returns(false)

Expand All @@ -24,7 +24,7 @@ class ContentItemsControllerTest < ActionController::TestCase
content_item["base_path"] = "/not-part-of-a-step-by-step"
path = content_item["base_path"][1..-1]

content_store_has_item(content_item["base_path"], content_item)
stub_content_store_has_item(content_item["base_path"], content_item)

@controller.stubs(:page_in_scope?).returns(false)

Expand Down
4 changes: 2 additions & 2 deletions test/integration/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
<h2>Item two</h2><p>Content about item two</p>
</div>"

content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])

assert_not page.has_css?(".gem-c-contents-list")
Expand Down Expand Up @@ -79,7 +79,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
'explanation': "This is out of date",
'withdrawn_at': "2014-08-09T11:39:05Z",
}
content_store_has_item("/government/organisations/department-of-health/about", content_item.to_json)
stub_content_store_has_item("/government/organisations/department-of-health/about", content_item.to_json)

visit_with_cachebust "/government/organisations/department-of-health/about"

Expand Down
4 changes: 2 additions & 2 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
test "document collection with no body and 2 collection groups where 1st group has long body" do
content_item = get_content_example("document_collection")
content_item["details"]["collection_groups"][0]["body"] = Faker::Lorem.characters(number: 416)
content_store_has_item(content_item["base_path"], content_item.to_json)
stub_content_store_has_item(content_item["base_path"], content_item.to_json)
visit(content_item["base_path"])

assert page.has_css?(".gem-c-contents-list")
Expand Down Expand Up @@ -53,7 +53,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
"documents" => %w[a-content-id],
},
]
content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])

assert_not page.has_css?(".gem-c-contents-list")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/guide_print_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GuidePrint < ActionDispatch::IntegrationTest
def setup_and_visit_guide_print(name)
example = get_content_example_by_schema_and_name("guide", name)
@content_item = example.tap do |item|
content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit "#{item['base_path']}/print"
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GuideTest < ActionDispatch::IntegrationTest
def setup_and_visit_part_in_guide
@content_item = get_content_example("guide").tap do |item|
chapter_path = "#{item['base_path']}/key-stage-1-and-2"
content_store_has_item(chapter_path, item.to_json)
stub_content_store_has_item(chapter_path, item.to_json)
visit_with_cachebust(chapter_path)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/help_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HelpPageTest < ActionDispatch::IntegrationTest
test "sets noindex meta tag for '/help/cookie-details'" do
@content_item = get_content_example("help_page").tap do |item|
item["base_path"] = "/help/cookie-details"
content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])
end

Expand Down
4 changes: 2 additions & 2 deletions test/integration/html_publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1)
'withdrawn_at': "2014-08-09T11:39:05Z",
}

content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
stub_content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
visit_with_cachebust "/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration"

assert page.has_css?(".gem-c-notice__title", text: "This policy paper was withdrawn on 9 August 2014")
Expand All @@ -101,7 +101,7 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1)
'withdrawn_at': "2014-08-09T11:39:05Z",
}

content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
stub_content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
visit_with_cachebust "/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration"

assert page.has_css?(".gem-c-notice__title", text: "This publication was withdrawn on 9 August 2014")
Expand Down
6 changes: 3 additions & 3 deletions test/integration/meta_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MetaTagsTest < ActionDispatch::IntegrationTest
)
end

content_store_has_item("/some-page", case_study.to_json)
stub_content_store_has_item("/some-page", case_study.to_json)

visit_with_cachebust "/some-page"

Expand All @@ -22,7 +22,7 @@ class MetaTagsTest < ActionDispatch::IntegrationTest
random
end

content_store_has_item("/some-page", case_study.to_json)
stub_content_store_has_item("/some-page", case_study.to_json)

visit_with_cachebust "/some-page"

Expand All @@ -41,7 +41,7 @@ class MetaTagsTest < ActionDispatch::IntegrationTest
random
end

content_store_has_item("/some-page", case_study.to_json)
stub_content_store_has_item("/some-page", case_study.to_json)

visit_with_cachebust "/some-page"

Expand Down
4 changes: 2 additions & 2 deletions test/integration/phase_label_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PhaseLabelTest < ActionDispatch::IntegrationTest
case_study = GovukSchemas::Example.find("case_study", example_name: "case_study")
case_study["phase"] = "alpha"

content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", case_study.to_json)
stub_content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", case_study.to_json)

visit_with_cachebust "/government/case-studies/get-britain-building-carlisle-park"

Expand All @@ -15,7 +15,7 @@ class PhaseLabelTest < ActionDispatch::IntegrationTest
test "No phase label is displayed for a Content item without a phase field" do
content_item = GovukSchemas::Example.find("case_study", example_name: "case_study")
content_item.delete("phase")
content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", content_item.to_json)
stub_content_store_has_item("/government/case-studies/get-britain-building-carlisle-park", content_item.to_json)

visit_with_cachebust "/government/case-studies/get-britain-building-carlisle-park"

Expand Down
7 changes: 7 additions & 0 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PublicationTest < ActionDispatch::IntegrationTest
},
)

assert_has_structured_data(page, "Article")

assert_footer_has_published_dates("Published 3 May 2016")
end

Expand Down Expand Up @@ -63,6 +65,11 @@ class PublicationTest < ActionDispatch::IntegrationTest
assert page.has_css?('img[alt="National Statistics"]')
end

test "national statistics publication has correct structured data" do
setup_and_visit_content_item("statistics_publication")
assert_has_structured_data(page, "Dataset")
end

test "renders 'Applies to' block in important metadata when there are excluded nations" do
setup_and_visit_content_item("statistics_publication")

Expand Down
2 changes: 1 addition & 1 deletion test/integration/service_sign_in/choose_sign_in_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ChooseSignInTest < ActionDispatch::IntegrationTest
def setup_and_visit_choose_sign_in_page(example_name, example_path)
content_item = get_content_example(example_name)
content_path = content_item["base_path"] + example_path
content_store_has_item(content_path, content_item.to_json)
stub_content_store_has_item(content_path, content_item.to_json)
visit(content_path)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CreateNewAccount < ActionDispatch::IntegrationTest
def setup_and_visit_create_new_account_page
content_item = get_content_example("service_sign_in")
path = content_item["base_path"] + "/create-new-account"
content_store_has_item(path, content_item.to_json)
stub_content_store_has_item(path, content_item.to_json)
visit(path)
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/statistical_data_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest
<h2>Item two</h2><p>Content about item two</p>
</div>"

content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])

assert_not page.has_css?(".gem-c-contents-list")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/topical_event_about_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest
@content_item = get_content_example("topical_event_about_page")
@content_item["details"]["body"] = body_with_two_contents_list_items

content_store_has_item(@content_item["base_path"], @content_item.to_json)
stub_content_store_has_item(@content_item["base_path"], @content_item.to_json)

visit_with_cachebust @content_item["base_path"]
assert_not page.has_css?(".gem-c-contents-list")
Expand All @@ -36,7 +36,7 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest
@content_item = get_content_example("topical_event_about_page")
@content_item["details"]["body"] = long_first_item_body

content_store_has_item(@content_item["base_path"], @content_item.to_json)
stub_content_store_has_item(@content_item["base_path"], @content_item.to_json)

visit_with_cachebust @content_item["base_path"]
assert page.has_css?(".gem-c-contents-list")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/travel_advice_atom_feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setup_and_parse_travel_advice_atom_feed(name)
path: "#{@content_item['base_path']}.atom",
)

content_store_has_item(@content_item["base_path"], @content_item.to_json)
stub_content_store_has_item(@content_item["base_path"], @content_item.to_json)

@feed = RSS::Parser.parse(uri.read)
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/travel_advice_print_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TravelAdvicePrint < ActionDispatch::IntegrationTest
def setup_and_visit_travel_advice_print(name)
example = get_content_example_by_schema_and_name("travel_advice", name)
@content_item = example.tap do |item|
content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit "#{item['base_path']}/print"
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/travel_advice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest

def setup_and_visit_travel_advice_part(name, part)
@content_item = get_content_example(name).tap do |item|
content_store_has_item("#{item['base_path']}/#{part}", item.to_json)
stub_content_store_has_item("#{item['base_path']}/#{part}", item.to_json)
visit "#{item['base_path']}/#{part}"
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration/working_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest
test "with a body that has no h2s" do
item = get_content_example("short")
item["details"]["body"] = "<div class='govspeak'><p>Some content<p></div>"
content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit(item["base_path"])

assert page.has_text?("Some content")
Expand All @@ -49,7 +49,7 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest
<h2>Item two</h2><p>Content about item two</p>
</div>"

content_store_has_item(item["base_path"], item.to_json)
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])

assert_not page.has_css?(".gem-c-contents-list")
Expand Down
2 changes: 1 addition & 1 deletion test/support/govuk_content_schema_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module GovukContentSchemaExamples

def content_store_has_schema_example(schema_name, example_name)
document = govuk_content_schema_example(schema_name, example_name)
content_store_has_item(document["base_path"], document)
stub_content_store_has_item(document["base_path"], document)
document
end

Expand Down
Loading

0 comments on commit 0b56cd7

Please sign in to comment.