Skip to content

Commit

Permalink
Merge pull request #986 from alphagov/track-themes
Browse files Browse the repository at this point in the history
Track taxon slugs rather than titles
  • Loading branch information
alecgibson authored Apr 3, 2017
2 parents 6719f08 + 09ef0be commit a5c2e3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions app/views/govuk_component/analytics_meta_tags.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@
navigation_document_type = content_item_hash[:navigation_document_supertype]
meta_tags["govuk:navigation-document-type"] = navigation_document_type if navigation_document_type

def root_taxons(content_item)
def root_taxon_slugs(content_item)
root_taxon_set = Set.new

links = content_item[:links]
# Taxons will have :parent_taxons, but content items will have :taxons
parent_taxons = links[:parent_taxons] || links[:taxons] unless links.nil?

if parent_taxons.blank?
root_taxon_set << content_item[:title] if content_item[:document_type] == 'taxon'
root_taxon_set << content_item[:base_path].sub(%r(^/), '') if content_item[:document_type] == 'taxon'
else
parent_taxons.each do |parent_taxon|
root_taxon_set += root_taxons(parent_taxon)
root_taxon_set += root_taxon_slugs(parent_taxon)
end
end

root_taxon_set
end

themes = root_taxons(content_item_hash)
meta_tags["govuk:themes"] = themes.to_a.sort.join('; ') unless themes.empty?
themes = root_taxon_slugs(content_item_hash)
meta_tags["govuk:themes"] = themes.to_a.sort.join(', ') unless themes.empty?
%>
<% meta_tags.each do |name, content| %>
<meta name="<%= name %>" content="<%= content %>">
Expand Down
13 changes: 9 additions & 4 deletions test/govuk_component/analytics_meta_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ def example_document_for(format, example_name)
test "renders themes metatag for root taxon" do
taxon = {
title: 'Root taxon',
base_path: '/root-taxon',
links: {
parent_taxons: [],
},
}
render_component(content_item: example_document_for('taxon', 'taxon').merge(taxon))
assert_meta_tag('govuk:themes', 'Root taxon')
assert_meta_tag('govuk:themes', 'root-taxon')
end

test "renders themes metatag for child taxon" do
Expand All @@ -136,13 +137,14 @@ def example_document_for(format, example_name)
parent_taxons: [
{
title: 'Root taxon',
base_path: '/root-taxon',
document_type: 'taxon',
},
],
},
}
render_component(content_item: example_document_for('taxon', 'taxon').merge(taxon))
assert_meta_tag('govuk:themes', 'Root taxon')
assert_meta_tag('govuk:themes', 'root-taxon')
end

test "renders themes metatag for content item" do
Expand All @@ -156,6 +158,7 @@ def example_document_for(format, example_name)
parent_taxons: [
{
title: 'Root taxon',
base_path: '/root-taxon',
document_type: 'taxon',
},
],
Expand All @@ -165,7 +168,7 @@ def example_document_for(format, example_name)
},
}
render_component(content_item: example_document_for('case_study', 'case_study').merge(content_item))
assert_meta_tag('govuk:themes', 'Root taxon')
assert_meta_tag('govuk:themes', 'root-taxon')
end

test "renders themes metatag for content item with multiple roots" do
Expand All @@ -179,6 +182,7 @@ def example_document_for(format, example_name)
parent_taxons: [
{
title: 'Education root taxon',
base_path: '/education-root-taxon',
document_type: 'taxon',
},
],
Expand All @@ -195,6 +199,7 @@ def example_document_for(format, example_name)
parent_taxons: [
{
title: 'Parenting root taxon',
base_path: '/parenting-root-taxon',
document_type: 'taxon',
}
],
Expand All @@ -206,7 +211,7 @@ def example_document_for(format, example_name)
},
}
render_component(content_item: example_document_for('case_study', 'case_study').merge(content_item))
assert_meta_tag('govuk:themes', 'Education root taxon; Parenting root taxon')
assert_meta_tag('govuk:themes', 'education-root-taxon, parenting-root-taxon')
end

test "does not render themes metatag for content item with no taxon" do
Expand Down

0 comments on commit a5c2e3c

Please sign in to comment.