Skip to content

Commit

Permalink
rename blacklight_path to search_state
Browse files Browse the repository at this point in the history
blacklight_path is already used by a built in Rails routing helper, and
the routing helper was getting precidence over our method.
  • Loading branch information
jcoyne committed Nov 6, 2015
1 parent d5c644b commit 939bb35
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def action_documents
end

def action_success_redirect_path
blacklight_path.url_for_document(blacklight_config.document_model.new(id: params[:id]))
search_state.url_for_document(blacklight_config.document_model.new(id: params[:id]))
end

##
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Blacklight::Controller
helper_method :has_user_authentication_provider?
helper_method :blacklight_config, :blacklight_configuration_context
helper_method :search_action_url, :search_action_path, :search_facet_url
helper_method :blacklight_path
helper_method :search_state


# This callback runs when a user first logs in
Expand Down Expand Up @@ -64,9 +64,9 @@ def render_saved_searches?
has_user_authentication_provider? and current_user
end

# @return [Blacklight::Path] a memoized instance of the parameter state.
def blacklight_path
@blacklight_path ||= Blacklight::Path.new(params, blacklight_config)
# @return [Blacklight::SearchState] a memoized instance of the parameter state.
def search_state
@search_state ||= Blacklight::SearchState.new(params, blacklight_config)
end

# Default route to the search action (used e.g. in global partials). Override this method
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/facets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def path_for_facet(facet_field, item)
if facet_config.url_method
send(facet_config.url_method, facet_field, item)
else
search_action_path(blacklight_path.add_facet_params_and_redirect(facet_field, item))
search_action_path(search_state.add_facet_params_and_redirect(facet_field, item))
end
end

##
# Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
# @params (see #render_facet_value)
def render_selected_facet_value(facet_field, item)
remove_href = search_action_path(blacklight_path.remove_facet_params(facet_field, item))
remove_href = search_action_path(search_state.remove_facet_params(facet_field, item))
content_tag(:span, class: "facet-label") do
content_tag(:span, facet_display_value(facet_field, item), class: "selected") +
# remove link
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/render_constraints_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def render_constraints_query(localized_params = params)
# @return [String]
def render_constraints_filters(localized_params = params)
return "".html_safe unless localized_params[:f]
path = Blacklight::Path.new(localized_params, blacklight_config)
path = Blacklight::SearchState.new(localized_params, blacklight_config)
content = []
localized_params[:f].each_pair do |facet,values|
content << render_filter_element(facet, values, path)
Expand All @@ -61,7 +61,7 @@ def render_constraints_filters(localized_params = params)
# Render a single facet's constraint
# @param [String] facet field
# @param [Array<String>] values selected facet values
# @param [Blacklight::Path] path query parameters
# @param [Blacklight::SearchState] path query parameters
# @return [String]
def render_filter_element(facet, values, path)
facet_config = facet_configuration_for_field(facet)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Blacklight::UrlHelperBehavior
# to provide more interesting routing to
# documents
def url_for_document(doc, options = {})
blacklight_path.url_for_document(doc, options)
search_state.url_for_document(doc, options)
end

# link_to_document(doc, 'VIEW', :counter => 3)
Expand Down Expand Up @@ -146,7 +146,7 @@ def link_to_previous_search(params)
# @param [Blacklight::SolrResponse::Group]
# @return [Hash]
def add_group_facet_params_and_redirect group
blacklight_path.add_facet_params_and_redirect(group.field, group.key, params)
search_state.add_facet_params_and_redirect(group.field, group.key, params)
end

# A URL to refworks export, with an embedded callback URL to this app.
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_per_page_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</button>
<ul class="dropdown-menu" role="menu">
<%- per_page_options_for_select.each do |(label, count)| %>
<li><%= link_to(label, url_for(blacklight_path.params_for_search(per_page: count))) %></li>
<li><%= link_to(label, url_for(search_state.params_for_search(per_page: count))) %></li>
<%- end -%>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_tag search_action_url, method: :get, class: 'search-query-form clearfix navbar-form', role: 'search' do %>
<%= render_hash_as_hidden_fields(blacklight_path.params_for_search.except(:q, :search_field, :qt, :page, :utf8)) %>
<%= render_hash_as_hidden_fields(search_state.params_for_search.except(:q, :search_field, :qt, :page, :utf8)) %>
<div class="input-group">
<% if search_fields.length > 1 %>
<span class="input-group-addon for-search-field">
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_sort_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ul class="dropdown-menu" role="menu">
<%- active_sort_fields.each do |sort_key, field_config| %>
<li><%= link_to(field_config.label, url_for(blacklight_path.params_for_search(sort: sort_key))) %></li>
<li><%= link_to(field_config.label, url_for(search_state.params_for_search(sort: sort_key))) %></li>
<%- end -%>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_zero_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<%- if params[:q] and params[:search_field] and params[:search_field] != blacklight_config.default_search_field.try(:key) -%>
<li><%= t 'blacklight.search.zero_results.search_fields', :search_fields => search_field_label(params) %> -
<%= link_to t('blacklight.search.zero_results.search_everything', field: blacklight_config.default_search_field.label), url_for(blacklight_path.params_for_search(search_field: blacklight_config.default_search_field.key)) %>
<%= link_to t('blacklight.search.zero_results.search_everything', field: blacklight_config.default_search_field.label), url_for(search_state.params_for_search(search_field: blacklight_config.default_search_field.key)) %>
</li>
<%- end %>

Expand Down
8 changes: 4 additions & 4 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require 'blacklight/utils'

module Blacklight
autoload :Exceptions, 'blacklight/exceptions'
autoload :Path, 'blacklight/path'
autoload :Parameters, 'blacklight/parameters'
autoload :Routes, 'blacklight/routes'
autoload :Exceptions, 'blacklight/exceptions'
autoload :SearchState, 'blacklight/search_state'
autoload :Parameters, 'blacklight/parameters'
autoload :Routes, 'blacklight/routes'

extend Deprecation

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/path.rb → lib/blacklight/search_state.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Blacklight
# This class encapsulates the search state as represented by the query
# parameters namely: :f, :q, :page, :per_page and, :sort
class Path
class SearchState
include Blacklight::Facet
attr_reader :blacklight_config # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config.
attr_reader :params
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/blacklight/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
let(:controller) { (Class.new(ApplicationController) { include Blacklight::Base }).new }
subject { controller}

describe "#blacklight_path" do
describe "#search_state" do
let(:params) { double }
before { allow(controller).to receive_messages(params: params) }
subject { controller.send(:blacklight_path) }
subject { controller.send(:search_state) }

it "creates a path object" do
expect(subject).to be_kind_of Blacklight::Path
expect(subject).to be_kind_of Blacklight::SearchState
expect(subject.params).to be params
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/facets_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@

describe "render_facet_value" do
let(:item) { double(:value => 'A', :hits => 10) }
let(:blacklight_path) { double(add_facet_params_and_redirect: { controller: 'catalog' }) }
let(:search_state) { double(add_facet_params_and_redirect: { controller: 'catalog' }) }
before do
allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false, :url_method => nil))
allow(helper).to receive(:facet_display_value).and_return('Z')
allow(helper).to receive(:blacklight_path).and_return(blacklight_path)
allow(helper).to receive(:search_state).and_return(search_state)
allow(helper).to receive(:search_action_path) do |*args|
search_catalog_path *args
end
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/render_constraints_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end
subject { helper.render_filter_element('type', ['journal'], path) }

let(:path) { Blacklight::Path.new({:q=>'biz'}, config) }
let(:path) { Blacklight::SearchState.new({:q=>'biz'}, config) }

it "should have a link relative to the current url" do
expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Blacklight::Path do
describe Blacklight::SearchState do
let(:blacklight_config) do
Blacklight::Configuration.new.configure do |config|
config.index.title_field = 'title_display'
Expand Down
4 changes: 2 additions & 2 deletions spec/support/controller_level_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module ControllerLevelHelpers
module ControllerViewHelpers
include Blacklight::Facet

def blacklight_path
@blacklight_path ||= Blacklight::Path.new(params, blacklight_config)
def search_state
@search_state ||= Blacklight::SearchState.new(params, blacklight_config)
end

def blacklight_configuration_context
Expand Down

0 comments on commit 939bb35

Please sign in to comment.