Skip to content

Commit

Permalink
Move instance variables to search_session
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 30, 2017
1 parent 39a3ed1 commit 5713038
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/catalog.rb
Expand Up @@ -47,7 +47,7 @@ def show
@response = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(deprecated_response, 'The @response instance variable is deprecated; use @document.response instead.')

respond_to do |format|
format.html { setup_next_and_previous_documents }
format.html { @search_context = setup_next_and_previous_documents }
format.json { render json: { response: { document: @document } } }
additional_export_formats(@document, format)
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/blacklight/search_context.rb
Expand Up @@ -111,9 +111,7 @@ def setup_next_and_previous_documents
response, documents = search_service.previous_and_next_documents_for_search index, search_state.reset(current_search_session.query_params).to_hash

search_session['total'] = response.total
@search_context_response = response
@previous_document = documents.first
@next_document = documents.last
{ prev: documents.first, next: documents.last }
end
rescue Blacklight::Exceptions::InvalidRequest => e
logger.warn "Unable to setup next and previous documents: #{e}"
Expand Down
8 changes: 4 additions & 4 deletions app/views/catalog/_previous_next_doc.html.erb
@@ -1,12 +1,12 @@
<% #Using the Bootstrap Pagination class -%>
<% # Using the Bootstrap Pagination class -%>
<div class='pagination-search-widgets'>
<% if @previous_document || @next_document %>
<% if @search_context[:prev] || @search_context[:next] %>
<div class="page-links">
<%= link_to_previous_document @previous_document %> |
<%= link_to_previous_document @search_context[:prev] %> |
<%= item_page_entry_info %> |
<%= link_to_next_document @next_document %>
<%= link_to_next_document @search_context[:next] %>
</div>
<% end %>
</div>
8 changes: 4 additions & 4 deletions app/views/catalog/_show_main_content.html.erb
@@ -1,4 +1,4 @@
<%= render 'previous_next_doc' %>
<%= render 'previous_next_doc' if @search_context %>
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name).html_safe %>
<% content_for(:head) { render_link_rel_alternates } %>
Expand All @@ -10,10 +10,10 @@
</div>

<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
<!--
// COinS, for Zotero among others.
<!--
// COinS, for Zotero among others.
// This document_partial_name(@document) business is not quite right,
// but has been there for a while.
// but has been there for a while.
-->
<span class="Z3988" title="<%= @document.export_as_openurl_ctx_kev(document_partial_name(@document)) %>"></span>
<% end %>
16 changes: 8 additions & 8 deletions spec/controllers/catalog_controller_spec.rb
Expand Up @@ -274,32 +274,32 @@
it "sets previous document if counter present in session" do
session[:search] = search_session.merge('counter' => 2)
get :show, params: { id: doc_id }
expect(assigns[:previous_document]).to_not be_nil
expect(assigns[:search_context][:prev]).to_not be_nil
end

it "does not set previous or next document if session is blank" do
get :show, params: { id: doc_id }
expect(assigns[:previous_document]).to be_nil
expect(assigns[:next_document]).to be_nil
expect(assigns[:search_context]).to be_nil
end

it "does not set previous or next document if session[:search]['counter'] is nil" do
session[:search] = {}
get :show, params: { id: doc_id }
expect(assigns[:previous_document]).to be_nil
expect(assigns[:next_document]).to be_nil
expect(assigns[:search_context]).to be_nil
end

it "sets next document if counter present in session" do
session[:search] = search_session.merge('counter' => 2)
get :show, params: { id: doc_id }
expect(assigns[:next_document]).to_not be_nil
expect(assigns[:search_context][:next]).to_not be_nil
end

it "does not break if solr returns an exception" do
allow(controller.send(:search_service)).to receive(:previous_and_next_documents_for_search) {
raise Blacklight::Exceptions::InvalidRequest.new "Error"
}
get :show, params: { id: doc_id }
expect(assigns[:previous_document]).to be_nil
expect(assigns[:next_document]).to be_nil
expect(assigns[:search_context]).to be_nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/views/catalog/show.html.erb_spec.rb
Expand Up @@ -8,7 +8,7 @@
allow(view).to receive(:action_name).and_return('show')
allow(view).to receive_messages(:has_user_authentication_provider? => false)
allow(view).to receive_messages(:render_document_sidebar_partial => "Sidebar")
allow(view).to receive_messages(current_search_session: nil)
allow(view).to receive_messages(current_search_session: nil, search_session: {})
assign :document, document
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
end
Expand Down

0 comments on commit 5713038

Please sign in to comment.