Skip to content

Commit

Permalink
Merge pull request #1068 from alphagov/fix-links-out-content-nav
Browse files Browse the repository at this point in the history
Fix content out links for content pages AB
  • Loading branch information
Vanita Barrett authored Sep 3, 2018
2 parents c51a56a + 108b365 commit d683e9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load_taxonomy_navigation

@taxonomy_navigation = {}
@content_item.links_out_supergroups.each do |supergroup|
supergroup_taxon_links = "Supergroups::#{supergroup.camelcase}".constantize.new(current_base_path, taxon_ids, filter_content_purpose_subgroup: @content_item.links_out_subgroups)
supergroup_taxon_links = "Supergroups::#{supergroup.camelcase}".constantize.new(current_base_path, taxon_ids, filter_content_purpose_subgroup: @content_item.links_out_subgroups(supergroup))
@taxonomy_navigation[supergroup.to_sym] = supergroup_taxon_links.tagged_content
end

Expand Down
8 changes: 4 additions & 4 deletions app/presenters/content_item/links_out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def links_out_supergroups
@links_out_supergroups ||= fetch_links_out_supergroups
end

def links_out_subgroups
@links_out_subgroups ||= fetch_links_out_subgroups
def links_out_subgroups(supergroup)
fetch_links_out_subgroups(supergroup)
end

private
Expand All @@ -14,10 +14,10 @@ def fetch_links_out_supergroups
links_out.map { |link| link["supergroup"] }.uniq
end

def fetch_links_out_subgroups
def fetch_links_out_subgroups(supergroup)
subgroups = []
links_out.each do |link|
if link["type"] == "content_purpose_subgroup"
if link["type"] == "content_purpose_subgroup" && link["supergroup"] == supergroup
subgroups << link["title"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/supergroups/supergroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Supergroup
def initialize(current_path, taxon_ids, filters, content_order_class)
@current_path = current_path
@taxon_ids = taxon_ids
@filters = default_filters.merge(filters)
@filters = filters.merge(default_filters)
@content = fetch_content(content_order_class)
end

Expand Down
17 changes: 13 additions & 4 deletions test/presenters/content_item/links_out_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def assert_returns_guide
end

def assert_returns_guidance
assert_equal %w(guidance), @links_out.links_out_subgroups
assert_equal %w(guidance), @links_out.links_out_subgroups("guidance_and_regulation")
end

def assert_returns_guidance_and_regulation
Expand Down Expand Up @@ -220,7 +220,16 @@ def content_item
amended_rules["document_type"] = nil

stub_load_rules(amended_rules)
assert_equal %w(link_to_news), @links_out.links_out_subgroups
assert_equal %w(link_to_news), @links_out.links_out_subgroups("news_and_communications")
end

test 'links_out_subgroups returns no subgroup names if content_purpose_subgroup is not a subgroup of the supergroup' do
amended_rules = rules
amended_rules["content_purpose_subgroup"]["guidance"] << news_rule
amended_rules["document_type"] = nil

stub_load_rules(amended_rules)
assert_equal [], @links_out.links_out_subgroups("guidance_and_regulation")
end

test 'links_out_subgroups returns correct subgroup names for content_purpose_subgroup rules' do
Expand All @@ -229,14 +238,14 @@ def content_item
amended_rules["document_type"] = nil

stub_load_rules(amended_rules)
assert_equal %w(link_to_guidance link_to_news), @links_out.links_out_subgroups
assert_equal %w(link_to_news), @links_out.links_out_subgroups("news_and_communications")
end

test 'links_out_subgroups returns correct subgroup names for document_type rules' do
amended_rules = rules
amended_rules["document_type"]["guide"] << news_rule

stub_load_rules(amended_rules)
assert_equal %w(link_to_news), @links_out.links_out_subgroups
assert_equal %w(link_to_news), @links_out.links_out_subgroups("news_and_communications")
end
end

0 comments on commit d683e9d

Please sign in to comment.