diff --git a/app/helpers/blacklight/url_helper_behavior.rb b/app/helpers/blacklight/url_helper_behavior.rb index 7a0a045766..3997e8af03 100644 --- a/app/helpers/blacklight/url_helper_behavior.rb +++ b/app/helpers/blacklight/url_helper_behavior.rb @@ -81,12 +81,12 @@ 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? - - if respond_to?(controller_tracking_method) - send(controller_tracking_method, params.merge(id: document)) + return if document.nil? || controller_name == 'bookmarks' + if main_app.respond_to?(controller_tracking_method) + main_app.public_send(controller_tracking_method, params.merge(id: document)) else - blacklight.track_search_context_path(params.merge(id: document)) + raise "Unable to find #{controller_tracking_method} route helper. " \ + "Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?" end end diff --git a/config/routes.rb b/config/routes.rb index 45f4347c96..cb34c24c0f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/helpers/blacklight/url_helper_behavior_spec.rb b/spec/helpers/blacklight/url_helper_behavior_spec.rb index 19937b866b..5c96b1eb6e 100644 --- a/spec/helpers/blacklight/url_helper_behavior_spec.rb +++ b/spec/helpers/blacklight/url_helper_behavior_spec.rb @@ -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 " do @@ -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 @@ -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 @@ -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 diff --git a/spec/views/catalog/_index_header.html.erb_spec.rb b/spec/views/catalog/_index_header.html.erb_spec.rb index 3dc0ed58b9..4cd4f14ab7 100644 --- a/spec/views/catalog/_index_header.html.erb_spec.rb +++ b/spec/views/catalog/_index_header.html.erb_spec.rb @@ -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 diff --git a/spec/views/catalog/_show_sidebar.erb_spec.rb b/spec/views/catalog/_show_sidebar.erb_spec.rb index 1e1f8c0a69..c5e85f81b2 100644 --- a/spec/views/catalog/_show_sidebar.erb_spec.rb +++ b/spec/views/catalog/_show_sidebar.erb_spec.rb @@ -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 diff --git a/spec/views/catalog/_thumbnail.html.erb_spec.rb b/spec/views/catalog/_thumbnail.html.erb_spec.rb index 8165f22427..66ecbdd674 100644 --- a/spec/views/catalog/_thumbnail.html.erb_spec.rb +++ b/spec/views/catalog/_thumbnail.html.erb_spec.rb @@ -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