diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 840861e46..aebdade18 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -68,7 +68,7 @@ def load_taxonomy_navigation taxons = @content_item.taxons.select { |taxon| taxon["phase"] == "live" } taxon_ids = taxons.map { |taxon| taxon["content_id"] } - services = Supergroups::Services.new(taxon_ids) + services = Supergroups::Services.new(content_item_path, taxon_ids) @taxonomy_navigation = { services: (services.all_services if services.any_services?), diff --git a/app/presenters/supergroups/services.rb b/app/presenters/supergroups/services.rb index ad62fbb35..f477de18c 100644 --- a/app/presenters/supergroups/services.rb +++ b/app/presenters/supergroups/services.rb @@ -2,9 +2,13 @@ module Supergroups class Services attr_reader :content - def initialize(taxon_ids) + def initialize(current_path, taxon_ids) @taxon_ids = taxon_ids - @content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services") + @content = MostPopularContent.fetch( + content_ids: @taxon_ids, + current_path: current_path, + filter_content_purpose_supergroup: "services" + ) end def all_services diff --git a/app/services/most_popular_content.rb b/app/services/most_popular_content.rb index f8fa1bd3c..036b2afbe 100644 --- a/app/services/most_popular_content.rb +++ b/app/services/most_popular_content.rb @@ -3,16 +3,17 @@ class MostPopularContent include RummagerFields - attr_reader :content_ids, :filter_content_purpose_supergroup, :number_of_links + attr_reader :content_ids, :current_path, :filter_content_purpose_supergroup, :number_of_links - def initialize(content_ids:, filter_content_purpose_supergroup:, number_of_links: 5) + def initialize(content_ids:, current_path:, filter_content_purpose_supergroup:, number_of_links: 5) @content_ids = content_ids + @current_path = current_path @filter_content_purpose_supergroup = filter_content_purpose_supergroup @number_of_links = number_of_links end - def self.fetch(content_ids:, filter_content_purpose_supergroup:) - new(content_ids: content_ids, filter_content_purpose_supergroup: filter_content_purpose_supergroup).fetch + def self.fetch(content_ids:, current_path:, filter_content_purpose_supergroup:) + new(content_ids: content_ids, current_path: current_path, filter_content_purpose_supergroup: filter_content_purpose_supergroup).fetch end def fetch @@ -28,6 +29,7 @@ def search_response fields: RummagerFields::TAXON_SEARCH_FIELDS, filter_part_of_taxonomy_tree: content_ids, order: '-popularity', + reject_link: current_path, } params[:filter_content_purpose_supergroup] = filter_content_purpose_supergroup if filter_content_purpose_supergroup.present? diff --git a/test/services/most_popular_content_test.rb b/test/services/most_popular_content_test.rb index e251f9876..f021eba30 100644 --- a/test/services/most_popular_content_test.rb +++ b/test/services/most_popular_content_test.rb @@ -7,6 +7,7 @@ class MostPopularContentTest < ActiveSupport::TestCase def most_popular_content @most_popular_content ||= MostPopularContent.new( content_ids: taxon_content_ids, + current_path: "/how-to-ride-a-bike", filter_content_purpose_supergroup: 'guidance_and_regulation' ) end @@ -69,6 +70,12 @@ def taxon_content_ids end end + test 'rejects the originating page from the results' do + assert_includes_params(reject_link: '/how-to-ride-a-bike') do + most_popular_content.fetch + end + end + def assert_includes_params(expected_params) search_results = { 'results' => [