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

Remove unnecessary route #2031

Merged
merged 1 commit into from
Nov 26, 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 .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ RSpec/MessageChain:
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive
Enabled: false

# Offense count: 339
# Configuration parameters: AggregateFailuresByDefault.
Expand Down
11 changes: 6 additions & 5 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ def session_tracking_params document, counter
##
# Get the URL for tracking search sessions across pages using polymorphic routing
def session_tracking_path document, params = {}
return if document.nil?
return if document.nil? || controller_name == 'bookmarks'

if respond_to?(controller_tracking_method)
send(controller_tracking_method, params.merge(id: document))
else
blacklight.track_search_context_path(params.merge(id: document))
if main_app.respond_to?(controller_tracking_method)
return main_app.public_send(controller_tracking_method, params.merge(id: document))
end

raise "Unable to find #{controller_tracking_method} route helper. " \
"Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?"
end

def controller_tracking_method
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
Blacklight::Engine.routes.draw do
get "search_history", to: "search_history#index", as: "search_history"
delete "search_history/clear", to: "search_history#clear", as: "clear_search_history"
post "/catalog/:id/track", to: 'catalog#track', as: 'track_search_context'
end
15 changes: 6 additions & 9 deletions spec/helpers/blacklight/url_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@

before do
allow(controller).to receive(:action_name).and_return('index')
allow(helper.main_app).to receive(:track_test_path).and_return('tracking url')
allow(helper.main_app).to receive(:respond_to?).with('track_test_path').and_return(true)
end

it "consists of the document title wrapped in a <a>" do
Expand Down Expand Up @@ -248,9 +250,9 @@
end

it "converts the counter parameter into a data- attribute" do
allow(helper).to receive(:track_test_path).with(hash_including(id: have_attributes(id: '123456'), counter: 5)).and_return('tracking url')
expect(Deprecation).to receive(:warn)
expect(helper.link_to_document(document, :title_tsim, counter: 5)).to include 'data-context-href="tracking url"'
expect(helper.main_app).to have_received(:track_test_path).with(hash_including(id: have_attributes(id: '123456'), counter: 5))
end

it "includes the data- attributes from the options" do
Expand All @@ -259,16 +261,11 @@
end

it 'adds a controller-specific tracking attribute' do
expect(helper).to receive(:track_test_path).and_return('/asdf')
expect(helper.main_app).to receive(:track_test_path).and_return('/asdf')
link = helper.link_to_document document, data: { x: 1 }

expect(link).to have_selector '[data-context-href="/asdf"]'
end

it 'adds a global tracking attribute' do
link = helper.link_to_document document, data: { x: 1 }
expect(link).to have_selector '[data-context-href="/catalog/123456/track"]'
end
end

describe "link_to_previous_search" do
Expand All @@ -292,12 +289,12 @@
let(:document) { SolrDocument.new(id: 1) }

it "determines the correct route for the document class" do
allow(helper).to receive(:track_test_path).with(id: have_attributes(id: 1)).and_return('x')
allow(helper.main_app).to receive(:track_test_path).with(id: have_attributes(id: 1)).and_return('x')
expect(helper.session_tracking_path(document)).to eq 'x'
end

it "passes through tracking parameters" do
allow(helper).to receive(:track_test_path).with(id: have_attributes(id: 1), x: 1).and_return('x')
allow(helper.main_app).to receive(:track_test_path).with(id: have_attributes(id: 1), x: 1).and_return('x')
expect(helper.session_tracking_path(document, x: 1)).to eq 'x'
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/views/catalog/_index_header.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
let(:blacklight_config) { Blacklight::Configuration.new }

before do
allow(controller).to receive(:action_name).and_return('index')
assign :response, instance_double(Blacklight::Solr::Response, start: 0)
allow(view).to receive(:render_grouped_response?).and_return false
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
allow(view).to receive(:session_tracking_params).and_return({})
end

it "renders the document header" do
Expand Down
4 changes: 1 addition & 3 deletions spec/views/catalog/_show_sidebar.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
end

before do
allow(controller).to receive(:action_name).and_return('show')
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:has_user_authentication_provider?).and_return(false)
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
allow(view).to receive(:document_actions).and_return([])
allow(view).to receive(:session_tracking_params).and_return({})
end

it "shows more-like-this titles in the sidebar" do
Expand Down
3 changes: 1 addition & 2 deletions spec/views/catalog/_thumbnail.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
assign :response, instance_double(Blacklight::Solr::Response, start: 0)
allow(view).to receive(:render_grouped_response?).and_return false
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
allow(view).to receive(:session_tracking_params).and_return({})
end

it "renders the thumbnail if the document has one" do
Expand Down