Skip to content

Commit

Permalink
Add dataset schema to other types
Browse files Browse the repository at this point in the history
The national_statistics, official_statistics and transparency document types
also contain datasets so will benefit from better structured data.
  • Loading branch information
sihugh committed Jan 27, 2020
1 parent c3c0259 commit f74b9d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def national_statistics?
document_type == "national_statistics"
end

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

private

def documents_list
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
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
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def visit_with_cachebust(visit_uri)
visit(uri)
end

def assert_has_structured_data(page, schema_name)
assert find_structured_data(page, schema_name).present?
end

def find_structured_data(page, schema_name)
schema_sections = page.find_all("script[type='application/ld+json']", visible: false)
schemas = schema_sections.map { |section| JSON.parse(section.text(:all)) }
Expand Down

0 comments on commit f74b9d6

Please sign in to comment.