Skip to content

Commit

Permalink
Merge pull request #951 from projectblacklight/back_to_nil
Browse files Browse the repository at this point in the history
back_to_search should return the catalog path if last search is nil
  • Loading branch information
Jessie Keck committed Jul 18, 2014
2 parents 36121a9 + 9573a64 commit 14bca52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def link_back_to_catalog(opts={:label=>nil})
query_params[:page] = ((counter - 1)/ per_page) + 1
end

link_url = scope.url_for(query_params)
link_url = if query_params.empty?
search_action_path(only_path: true)
else
scope.url_for(query_params)
end
label = opts.delete(:label)

if link_url =~ /bookmarks/
Expand Down
24 changes: 17 additions & 7 deletions spec/helpers/url_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
describe BlacklightUrlHelper do

let(:blacklight_config) do
@config ||= Blacklight::Configuration.new.configure do |config|
Blacklight::Configuration.new.configure do |config|
config.index.title_field = 'title_display'
config.index.display_type_field = 'format'
end
end

before(:each) do
before do
allow(helper).to receive(:search_action_path) do |*args|
catalog_index_url *args
end
Expand All @@ -21,19 +21,18 @@

describe "url_for_document" do
let(:controller_class) { ::CatalogController.new }
let(:doc) { SolrDocument.new }

before do
allow(helper).to receive_messages(controller: controller_class)
allow(helper).to receive_messages(controller_name: controller_class.controller_name)
end

it "should be a polymorphic routing-ready object" do
doc = SolrDocument.new
expect(helper.url_for_document(doc)).to eq doc
end

it "should allow for custom show routes" do
doc = SolrDocument.new
helper.blacklight_config.show.route = { controller: 'catalog' }
expect(helper.url_for_document(doc)).to eq({controller: 'catalog', action: :show, id: doc})
end
Expand All @@ -42,7 +41,6 @@
let(:controller_class) { ::BookmarksController.new }

it "should use polymorphic routing" do
doc = SolrDocument.new
expect(helper.url_for_document(doc)).to eq doc
end
end
Expand All @@ -53,7 +51,6 @@
helper.blacklight_config.show.route = { controller: :current }
end
it "should support the :current controller configuration" do
doc = SolrDocument.new
expect(helper.url_for_document(doc)).to eq({controller: 'alternate', action: :show, id: doc})
end
end
Expand Down Expand Up @@ -105,7 +102,20 @@
end
end

describe "when an alternate scope is passed in" do
context "without current search context" do
before do
controller.request.assign_parameters(Rails.application.routes, 'catalog', 'show', id: '123')
allow(helper).to receive_messages(current_search_session: nil)
end

subject { helper.link_back_to_catalog }

it "should link to the catalog" do
expect(subject).to eq '<a href="/catalog">Back to Search</a>'
end
end

context "when an alternate scope is passed in" do
let(:my_engine) { double("Engine") }

it "should call url_for on the engine scope" do
Expand Down

0 comments on commit 14bca52

Please sign in to comment.