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 28, 2017
1 parent 39a3ed1 commit a41e69c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ 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
search_session['prev'] = documents.first
search_session['next'] = documents.last
end
rescue Blacklight::Exceptions::InvalidRequest => e
logger.warn "Unable to setup next and previous documents: #{e}"
Expand Down
6 changes: 3 additions & 3 deletions app/views/catalog/_previous_next_doc.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<% #Using the Bootstrap Pagination class -%>
<div class='pagination-search-widgets'>
<% if @previous_document || @next_document %>
<% if search_session['prev'] || search_session['next'] %>
<div class="page-links">
<%= link_to_previous_document @previous_document %> |
<%= link_to_previous_document search_session['prev'] %> |
<%= item_page_entry_info %> |
<%= link_to_next_document @next_document %>
<%= link_to_next_document search_session['next'] %>
</div>
<% end %>
</div>
16 changes: 8 additions & 8 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
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(controller.send(:search_session)['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(controller.send(:search_session)).to be_empty
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(controller.send(:search_session)).to be_empty
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(controller.send(:search_session)['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(controller.send(:search_session)).to be_empty
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/views/catalog/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
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 a41e69c

Please sign in to comment.