blacklight 6.10.0 → 6.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60df91a78d3181795975d6b62bb92482e1b05151
4
- data.tar.gz: 6c20566992ac377318609c742c12a5786db2f3db
3
+ metadata.gz: 741267e0943b9248b05baca938f10fe8c3454717
4
+ data.tar.gz: 333367da063309c42774d31396aadaa17480bc43
5
5
  SHA512:
6
- metadata.gz: 6f8b43752993d04d66797cb247c542a3f1ec5b881a6f869ea6ad557cdf329c74039de7e9d7cd10a5664d12d2c88524df86c82a9e2cb324dce0973c6aea914fd2
7
- data.tar.gz: 26aa1ebc30886fcda720c4df6b00b728d8cd7a186887c6eda806de0c3680f18956438c795d2a67b17d7868ce30e51f12394abe0e12f96cc0ff4cede008984b7a
6
+ metadata.gz: 9e86f64f778efb7e43db4b0acd10999bb8c151ba30f59272522354469ad79ba28b04979864d381b2532c478b28fac33e712961bd5ca85aef41a04c0849e1dbe6
7
+ data.tar.gz: b6c6bc62fa20aeb936610a14de238f99f39f66cc3597255f7ab8c440897526bd95d6aad5eecb56f43ce50716f3af4eac7700147203cd367c13ab78be7f83d3a7
data/.rubocop_todo.yml CHANGED
@@ -86,12 +86,12 @@ Metrics/BlockLength:
86
86
  Metrics/BlockNesting:
87
87
  Max: 4
88
88
 
89
- # Offense count: 2
90
89
  # Configuration parameters: CountComments.
91
90
  Metrics/ClassLength:
92
- Max: 186
91
+ Max: 100
93
92
  Exclude:
94
93
  - 'lib/blacklight/configuration.rb'
94
+ - 'lib/blacklight/search_builder.rb'
95
95
 
96
96
  # Offense count: 20
97
97
  Metrics/CyclomaticComplexity:
data/.travis.yml CHANGED
@@ -9,6 +9,8 @@ rvm:
9
9
 
10
10
  matrix:
11
11
  include:
12
+ - rvm: 2.4.1
13
+ env: "RAILS_VERSION=4.2.8"
12
14
  - rvm: 2.2.7
13
15
  env: "RAILS_VERSION=5.0.3"
14
16
  - rvm: 2.3.4
@@ -23,6 +25,9 @@ before_install:
23
25
  - gem update --system
24
26
  - gem install bundler
25
27
 
28
+ before_script:
29
+ - if [[ "${RAILS_VERSION}" =~ ^4.2.* ]]; then perl -pi -e "s/ActiveRecord::Migration\[[\d\.]+\]/ActiveRecord::Migration/" db/migrate/*; fi
30
+
26
31
  env:
27
32
  - "RAILS_VERSION=5.1.1"
28
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.10.0
1
+ 6.11.0
@@ -29,7 +29,11 @@ module Blacklight
29
29
  # Pagination parameters for selecting the previous and next documents
30
30
  # out of a result set.
31
31
  def previous_and_next_document_params(index, window = 1)
32
- solr_params = {}
32
+ solr_params = blacklight_config.document_pagination_params.dup
33
+
34
+ if solr_params.empty?
35
+ solr_params[:fl] = '*'
36
+ end
33
37
 
34
38
  if index > 0
35
39
  solr_params[:start] = index - window # get one before
@@ -39,7 +43,6 @@ module Blacklight
39
43
  solr_params[:rows] = 2*window # but there should be one after
40
44
  end
41
45
 
42
- solr_params[:fl] = '*'
43
46
  solr_params[:facet] = false
44
47
  solr_params
45
48
  end
@@ -36,7 +36,9 @@ module Blacklight::SearchContext
36
36
  end
37
37
 
38
38
  def find_search_session
39
- if params[:search_context].present?
39
+ if agent_is_crawler?
40
+ nil
41
+ elsif params[:search_context].present?
40
42
  find_or_initialize_search_session_from_params JSON.parse(params[:search_context])
41
43
  elsif params[:search_id].present?
42
44
  begin
@@ -63,6 +65,16 @@ module Blacklight::SearchContext
63
65
  false
64
66
  end
65
67
 
68
+ ##
69
+ # Determine if the current request is coming from an anonymous bot
70
+ # or search crawler
71
+ #
72
+ def agent_is_crawler?
73
+ crawler_proc = blacklight_config.crawler_detector
74
+ return false if crawler_proc.nil? || current_user.present?
75
+ crawler_proc.call(request)
76
+ end
77
+
66
78
  def find_or_initialize_search_session_from_params params
67
79
  params_copy = params.reject { |k,v| blacklisted_search_session_params.include?(k.to_sym) or v.blank? }
68
80
 
@@ -96,7 +108,7 @@ module Blacklight::SearchContext
96
108
  def setup_next_and_previous_documents
97
109
  if search_session['counter'] and current_search_session
98
110
  index = search_session['counter'].to_i - 1
99
- response, documents = get_previous_and_next_documents_for_search index, ActiveSupport::HashWithIndifferentAccess.new(current_search_session.query_params)
111
+ response, documents = get_previous_and_next_documents_for_search index, search_state.reset(current_search_session.query_params).to_hash
100
112
 
101
113
  search_session['total'] = response.total
102
114
  @search_context_response = response
@@ -17,7 +17,10 @@ module Blacklight::BlacklightHelperBehavior
17
17
  #
18
18
  # @return [String] the application name
19
19
  def application_name
20
- return Rails.application.config.application_name if Rails.application.config.respond_to? :application_name
20
+ if Rails.application.config.respond_to? :application_name
21
+ Deprecation.warn(self, "BlacklightHelper#application_name will no longer delegate to config.application_name in version 7.0. Set the i18n for blacklight.application_name instead")
22
+ return Rails.application.config.application_name
23
+ end
21
24
 
22
25
  t('blacklight.application_name')
23
26
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight::ConfigurationHelperBehavior
3
+ extend Deprecation
4
+ self.deprecation_horizon = 'blacklight 7.x'
5
+
3
6
  ##
4
7
  # Index fields to display for a type of document
5
8
  #
@@ -13,6 +16,7 @@ module Blacklight::ConfigurationHelperBehavior
13
16
  def sort_fields
14
17
  active_sort_fields.map { |key, x| [x.label, x.key] }
15
18
  end
19
+ deprecation_deprecate :sort_fields
16
20
 
17
21
  def active_sort_fields
18
22
  blacklight_config.sort_fields.select { |sort_key, field_config| should_render_field?(field_config) }
@@ -114,7 +114,7 @@ module Blacklight::UrlHelperBehavior
114
114
  # link_back_to_catalog(label: 'Back to Search', route_set: my_engine)
115
115
  def link_back_to_catalog(opts={:label=>nil})
116
116
  scope = opts.delete(:route_set) || self
117
- query_params = current_search_session.try(:query_params) || ActionController::Parameters.new
117
+ query_params = search_state.reset(current_search_session.try(:query_params)).to_hash
118
118
 
119
119
  if search_session['counter']
120
120
  per_page = (search_session['per_page'] || default_per_page).to_i
@@ -1,4 +1,4 @@
1
- <% if show_sort_and_per_page? and !active_sort_fields.blank? %>
1
+ <% if show_sort_and_per_page? and active_sort_fields.many? %>
2
2
  <div id="sort-dropdown" class="btn-group">
3
3
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
4
4
  <%= t('blacklight.search.sort.label', :field =>current_sort_field.label) %> <span class="caret"></span>
@@ -10,7 +10,7 @@
10
10
  <table class="table table-striped search_history">
11
11
  <%- @searches.each_with_index do |search,index| -%>
12
12
  <%= content_tag :tr, :id => "document_#{index + 1}" do %>
13
- <td class="query"><%= link_to_previous_search(search.query_params) %></td>
13
+ <td class="query"><%= link_to_previous_search(search_state.reset(search.query_params).to_hash) %></td>
14
14
  <%- if has_user_authentication_provider? -%>
15
15
  <td class="actions">
16
16
  <%- if current_or_guest_user && search.saved? -%>
data/blacklight.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
 
28
28
  s.add_dependency "rails", ">= 4.2", "< 6"
29
29
  s.add_dependency "globalid"
30
+ s.add_dependency "jbuilder"
30
31
  s.add_dependency "nokogiri", "~>1.6" # XML Parser
31
32
  s.add_dependency "kaminari", ">= 0.15" # the pagination (page 1,2,3, etc..) of our search results
32
33
  s.add_dependency "rsolr", ">= 1.0.6", "< 3" # Library for interacting with rSolr.
@@ -56,6 +56,7 @@ module Blacklight
56
56
  #facet: false,
57
57
  #rows: 1
58
58
  },
59
+ document_pagination_params: {},
59
60
  ##
60
61
  # == Response models
61
62
  ## Class for sending and receiving requests from a search index
@@ -137,7 +138,10 @@ module Blacklight
137
138
  # how many searches to save in session history
138
139
  search_history_window: 100,
139
140
  default_facet_limit: 10,
140
- default_more_limit: 20
141
+ default_more_limit: 20,
142
+ # proc for determining whether the session is a crawler/bot
143
+ # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ }
144
+ crawler_detector: nil
141
145
  }
142
146
  end
143
147
  end
@@ -37,8 +37,8 @@ module Blacklight
37
37
  end
38
38
  alias to_h to_hash
39
39
 
40
- def reset
41
- self.class.new(ActionController::Parameters.new, blacklight_config, controller)
40
+ def reset(params = nil)
41
+ self.class.new(params || ActionController::Parameters.new, blacklight_config, controller)
42
42
  end
43
43
 
44
44
  ##
@@ -32,6 +32,13 @@ class Blacklight::Solr::Response::GroupResponse
32
32
  params[:start].to_s.to_i
33
33
  end
34
34
 
35
+ ##
36
+ # Relying on a fallback (method missing) to @response is problematic as it
37
+ # will not evaluate the correct `total` method.
38
+ def empty?
39
+ total.zero?
40
+ end
41
+
35
42
  def method_missing meth, *args, &block
36
43
  if response.respond_to? meth
37
44
  response.send(meth, *args, &block)
@@ -73,10 +73,12 @@ module Blacklight::Solr::Response::Spelling
73
73
  return unless spellcheck && spellcheck[:suggestions]
74
74
  suggestions = spellcheck[:suggestions]
75
75
 
76
- if suggestions.index("collation")
76
+ if suggestions.is_a?(Array) && suggestions.index("collation")
77
+ # solr < 5 response
77
78
  suggestions[suggestions.index("collation") + 1]
78
79
  elsif spellcheck.key?("collations")
79
- spellcheck['collations'].last
80
+ # solr 5+ response
81
+ spellcheck['collations'].last if spellcheck.key?("collations")
80
82
  end
81
83
  end
82
84
  end
@@ -458,5 +458,13 @@ describe Blacklight::SearchHelper do
458
458
  expect(docs.last).to be_nil
459
459
  expect(docs.first).to be_nil
460
460
  end
461
+
462
+ it 'allows the query parameters to be customized using configuration' do
463
+ blacklight_config.document_pagination_params[:fl] = 'id,format'
464
+
465
+ response, docs = subject.get_previous_and_next_documents_for_search(0, :q => '')
466
+
467
+ expect(docs.last.to_h).to eq @all_docs[1].to_h.slice('id', 'format')
468
+ end
461
469
  end
462
470
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "Search History Page" do
4
+
5
+ describe "crawler search" do
6
+ let(:original_proc) { ::CatalogController.blacklight_config.crawler_detector }
7
+
8
+ before do
9
+ ::CatalogController.blacklight_config.crawler_detector = lambda { |req| req.env['HTTP_USER_AGENT'] =~ /Googlebot/ }
10
+ end
11
+
12
+ after do
13
+ ::CatalogController.blacklight_config.crawler_detector = original_proc
14
+ end
15
+
16
+ it "remembers human searches" do
17
+ visit root_path
18
+ fill_in "q", with: 'chicken'
19
+ expect { click_button 'search' }.to change { Search.count }.by(1)
20
+ end
21
+
22
+ it "doesn't remember bot searches" do
23
+ page.driver.header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
24
+ visit root_path
25
+ fill_in "q", with: 'chicken'
26
+ expect { click_button 'search' }.to_not change { Search.count }
27
+ end
28
+ end
29
+
30
+ end
@@ -8,9 +8,9 @@ describe Blacklight::SearchState do
8
8
  end
9
9
  end
10
10
 
11
+ subject(:search_state) { described_class.new(params, blacklight_config, controller) }
11
12
  let(:parameter_class) { ActionController::Parameters }
12
13
  let(:controller) { double }
13
- let(:search_state) { described_class.new(params, blacklight_config, controller) }
14
14
  let(:params) { parameter_class.new }
15
15
 
16
16
  describe '#to_h' do
@@ -297,4 +297,12 @@ describe Blacklight::SearchState do
297
297
  expect(params).not_to have_key :f
298
298
  end
299
299
  end
300
+
301
+ describe '#reset' do
302
+ it 'returns a search state with the given parameters' do
303
+ new_state = search_state.reset('a' => 1)
304
+
305
+ expect(new_state.to_hash).to eq({ 'a' => 1 })
306
+ end
307
+ end
300
308
  end
@@ -59,6 +59,12 @@ describe Blacklight::Solr::Response::GroupResponse do
59
59
  expect(group.group_limit).to eq 5
60
60
  end
61
61
  end
62
+
63
+ describe "empty?" do
64
+ it "uses the total from this object" do
65
+ expect(group.empty?).to be false
66
+ end
67
+ end
62
68
  end
63
69
 
64
70
  def create_response(response, params = {})
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "catalog/_sort_widget" do
4
+ let(:blacklight_config) { Blacklight::Configuration.new }
5
+ let(:response) { instance_double(Blacklight::Solr::Response, empty?: false, sort: 'one') }
6
+
7
+ before do
8
+ allow(view).to receive_messages(blacklight_config: blacklight_config)
9
+ assign(:response, response)
10
+ controller.request.path_parameters[:action] = 'index'
11
+ end
12
+
13
+ context 'with no sort fields configured' do
14
+ it 'renders nothing' do
15
+ render
16
+ expect(rendered).to be_blank
17
+ end
18
+ end
19
+
20
+ context 'with a single sort field configured' do
21
+ before do
22
+ blacklight_config.add_sort_field 'one'
23
+ end
24
+ it 'renders nothing' do
25
+ render
26
+ expect(rendered).to be_blank
27
+ end
28
+ end
29
+
30
+ context 'with multiple sort fields configured' do
31
+ before do
32
+ blacklight_config.add_sort_field 'one'
33
+ blacklight_config.add_sort_field 'two'
34
+ end
35
+ it 'renders a dropdown with the various options' do
36
+ render
37
+
38
+ expect(rendered).to have_button 'One'
39
+ expect(rendered).to have_link 'One'
40
+ expect(rendered).to have_link 'Two'
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.10.0
4
+ version: 6.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2017-05-17 00:00:00.000000000 Z
20
+ date: 2017-08-10 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: jbuilder
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: nokogiri
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -635,6 +649,7 @@ files:
635
649
  - spec/features/record_view_spec.rb
636
650
  - spec/features/saved_searches_spec.rb
637
651
  - spec/features/search_context_spec.rb
652
+ - spec/features/search_crawler_spec.rb
638
653
  - spec/features/search_filters_spec.rb
639
654
  - spec/features/search_formats_spec.rb
640
655
  - spec/features/search_history_spec.rb
@@ -717,6 +732,7 @@ files:
717
732
  - spec/views/catalog/_show_sidebar.erb_spec.rb
718
733
  - spec/views/catalog/_show_tools.html.erb_spec.rb
719
734
  - spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
735
+ - spec/views/catalog/_sort_widget.html.erb_spec.rb
720
736
  - spec/views/catalog/_thumbnail_default.erb_spec.rb
721
737
  - spec/views/catalog/_view_type_group.html.erb_spec.rb
722
738
  - spec/views/catalog/facet.html.erb_spec.rb
@@ -774,6 +790,7 @@ test_files:
774
790
  - spec/features/record_view_spec.rb
775
791
  - spec/features/saved_searches_spec.rb
776
792
  - spec/features/search_context_spec.rb
793
+ - spec/features/search_crawler_spec.rb
777
794
  - spec/features/search_filters_spec.rb
778
795
  - spec/features/search_formats_spec.rb
779
796
  - spec/features/search_history_spec.rb
@@ -856,6 +873,7 @@ test_files:
856
873
  - spec/views/catalog/_show_sidebar.erb_spec.rb
857
874
  - spec/views/catalog/_show_tools.html.erb_spec.rb
858
875
  - spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
876
+ - spec/views/catalog/_sort_widget.html.erb_spec.rb
859
877
  - spec/views/catalog/_thumbnail_default.erb_spec.rb
860
878
  - spec/views/catalog/_view_type_group.html.erb_spec.rb
861
879
  - spec/views/catalog/facet.html.erb_spec.rb