Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude current page from most popular searches #997

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?),
Expand Down
8 changes: 6 additions & 2 deletions app/presenters/supergroups/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions app/services/most_popular_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?

Expand Down
7 changes: 7 additions & 0 deletions test/services/most_popular_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' => [
Expand Down