blacklight 5.13.0 → 5.13.1

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +16 -0
  3. data/.rubocop_hound.yml +1063 -0
  4. data/.rubocop_todo.yml +253 -0
  5. data/.travis.yml +7 -9
  6. data/Rakefile +1 -1
  7. data/VERSION +1 -1
  8. data/app/helpers/blacklight/blacklight_helper_behavior.rb +9 -13
  9. data/app/helpers/blacklight/catalog_helper_behavior.rb +14 -3
  10. data/app/helpers/blacklight/configuration_helper_behavior.rb +1 -1
  11. data/app/helpers/blacklight/facets_helper_behavior.rb +13 -13
  12. data/app/helpers/blacklight/render_partials_helper.rb +3 -0
  13. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +3 -5
  14. data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
  15. data/app/helpers/blacklight_configuration_helper.rb +1 -1
  16. data/app/helpers/blacklight_url_helper.rb +1 -1
  17. data/app/helpers/component_helper.rb +1 -1
  18. data/app/models/bookmark.rb +1 -1
  19. data/app/models/search.rb +2 -2
  20. data/app/views/catalog/_bookmark_control.html.erb +1 -1
  21. data/app/views/catalog/_document_default.atom.builder +2 -2
  22. data/app/views/catalog/_document_default.rss.builder +3 -3
  23. data/blacklight.gemspec +1 -1
  24. data/lib/blacklight.rb +10 -10
  25. data/lib/blacklight/bookmarks.rb +11 -10
  26. data/lib/blacklight/catalog.rb +7 -15
  27. data/lib/blacklight/catalog/component_configuration.rb +1 -1
  28. data/lib/blacklight/catalog/search_context.rb +1 -1
  29. data/lib/blacklight/configuration.rb +3 -3
  30. data/lib/blacklight/configuration/tool_config.rb +1 -1
  31. data/lib/blacklight/configuration/view_config.rb +1 -1
  32. data/lib/blacklight/controller.rb +0 -1
  33. data/lib/blacklight/document/active_model_shim.rb +1 -1
  34. data/lib/blacklight/document/dublin_core.rb +11 -6
  35. data/lib/blacklight/document/export.rb +5 -13
  36. data/lib/blacklight/document/schema_org.rb +1 -1
  37. data/lib/blacklight/document/semantic_fields.rb +9 -13
  38. data/lib/blacklight/document_presenter.rb +2 -2
  39. data/lib/blacklight/engine.rb +11 -0
  40. data/lib/blacklight/exceptions.rb +2 -2
  41. data/lib/blacklight/solr/document.rb +1 -2
  42. data/lib/blacklight/solr/document/more_like_this.rb +1 -1
  43. data/lib/blacklight/solr/document/schema_org.rb +1 -1
  44. data/lib/blacklight/solr/facet_paginator.rb +8 -5
  45. data/lib/blacklight/solr/request.rb +2 -3
  46. data/lib/blacklight/solr/search_builder_behavior.rb +14 -7
  47. data/lib/blacklight/solr_repository.rb +3 -3
  48. data/lib/blacklight/solr_response.rb +1 -1
  49. data/lib/blacklight/solr_response/group.rb +1 -1
  50. data/lib/blacklight/solr_response/group_response.rb +1 -1
  51. data/lib/blacklight/solr_response/more_like_this.rb +1 -1
  52. data/lib/blacklight/solr_response/pagination_methods.rb +1 -1
  53. data/lib/blacklight/solr_response/spelling.rb +1 -3
  54. data/lib/blacklight/token_based_user.rb +1 -3
  55. data/lib/blacklight/user.rb +1 -1
  56. data/lib/generators/blacklight/assets_generator.rb +22 -7
  57. data/lib/railties/blacklight.rake +5 -5
  58. data/spec/controllers/bookmarks_controller_spec.rb +1 -1
  59. data/spec/helpers/catalog_helper_spec.rb +3 -3
  60. data/spec/lib/blacklight/solr_response/facets_spec.rb +2 -2
  61. data/spec/lib/blacklight/solr_response/group_response_spec.rb +1 -1
  62. data/spec/lib/blacklight/solr_response/group_spec.rb +1 -1
  63. metadata +5 -2
@@ -2,7 +2,7 @@
2
2
  module Blacklight
3
3
  module Exceptions
4
4
 
5
- class AccessDenied < Exception
5
+ class AccessDenied < StandardError
6
6
  end
7
7
 
8
8
  # When a request for a single solr document by id
@@ -17,7 +17,7 @@ module Blacklight
17
17
  class InvalidRequest < StandardError
18
18
  end
19
19
 
20
- class ExpiredSessionToken < Exception
20
+ class ExpiredSessionToken < StandardError
21
21
  end
22
22
 
23
23
  class ECONNREFUSED < ::Errno::ECONNREFUSED; end
@@ -36,8 +36,7 @@ module Blacklight::Solr::Document
36
36
  end
37
37
 
38
38
  def highlight_field k
39
- return nil unless has_highlight_field? k
40
- response['highlighting'][self.id][k.to_s].map { |x| x.html_safe }
39
+ response['highlighting'][self.id][k.to_s].map(&:html_safe) if has_highlight_field? k
41
40
  end
42
41
 
43
42
  end
@@ -2,4 +2,4 @@ module Blacklight::Solr::Document::MoreLikeThis
2
2
  def more_like_this
3
3
  response.more_like(self).map { |doc| self.class.new(doc, response) }
4
4
  end
5
- end
5
+ end
@@ -4,4 +4,4 @@ module Blacklight::Solr::Document::SchemaOrg
4
4
  def self.extended(document)
5
5
  Deprecation.warn Blacklight::Solr::Document::SchemaOrg, "Blacklight::Solr::Document::SchemaOrg is deprecated; use Blacklight::Document::SchemaOrg instead."
6
6
  end
7
- end
7
+ end
@@ -20,11 +20,14 @@ module Blacklight::Solr
20
20
  # make sure they do NOT conflict with catalog/index request params,
21
21
  # and need to make them accessible in a list so we can easily
22
22
  # strip em out before redirecting to catalog/index.
23
- # class variable (via class-level ivar)
24
- @request_keys = {:sort => :'facet.sort', :page => :'facet.page'}
25
- class << self; attr_accessor :request_keys end # create a class method
26
- def request_keys ; self.class.request_keys ; end # shortcut
27
-
23
+ mattr_accessor :request_keys do
24
+ { sort: :'facet.sort', page: :'facet.page' }
25
+ end
26
+
27
+ if Rails.version < "4.1"
28
+ self.request_keys = { sort: :'facet.sort', page: :'facet.page' }
29
+ end
30
+
28
31
  attr_reader :offset, :limit, :sort
29
32
 
30
33
  # all_facet_values is a list of facet value objects returned by solr,
@@ -2,9 +2,8 @@ class Blacklight::Solr::InvalidParameter < ArgumentError; end
2
2
 
3
3
  class Blacklight::Solr::Request < HashWithIndifferentAccess
4
4
 
5
- SINGULAR_KEYS = %W{ facet fl q qt rows start spellcheck spellcheck.q sort
6
- per_page wt hl group defType}
7
- ARRAY_KEYS = %W{facet.field facet.query facet.pivot fq hl.fl }
5
+ SINGULAR_KEYS = %w{facet fl q qt rows start spellcheck spellcheck.q sort per_page wt hl group defType}
6
+ ARRAY_KEYS = %w{facet.field facet.query facet.pivot fq hl.fl}
8
7
 
9
8
  def initialize(constructor = {})
10
9
  if constructor.is_a?(Hash)
@@ -112,9 +112,7 @@ module Blacklight::Solr
112
112
  solr_parameters[:"facet.field"].concat( [blacklight_params["facet.field"], blacklight_params["facets"]].flatten.compact ).uniq!
113
113
  end
114
114
 
115
- blacklight_config.facet_fields.select { |field_name,facet|
116
- facet.include_in_request || (facet.include_in_request.nil? && blacklight_config.add_facet_fields_to_solr_request)
117
- }.each do |field_name, facet|
115
+ facet_fields_to_include_in_request.each do |field_name, facet|
118
116
  solr_parameters[:facet] ||= true
119
117
 
120
118
  case
@@ -243,17 +241,20 @@ module Blacklight::Solr
243
241
  local_params = []
244
242
  local_params << "tag=#{facet_config.tag}" if facet_config and facet_config.tag
245
243
 
246
- prefix = ""
247
244
  prefix = "{!#{local_params.join(" ")}}" unless local_params.empty?
248
245
 
249
- fq = case
246
+ case
250
247
  when (facet_config and facet_config.query)
251
248
  facet_config.query[value][:fq]
252
249
  when (facet_config and facet_config.date)
253
250
  # in solr 3.2+, this could be replaced by a !term query
254
251
  "#{prefix}#{solr_field}:#{RSolr.solr_escape(value)}"
255
- when (value.is_a?(DateTime) or value.is_a?(Date) or value.is_a?(Time))
256
- "#{prefix}#{solr_field}:#{RSolr.solr_escape(value.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ"))}"
252
+ when (value.is_a?(DateTime) or value.is_a?(Time))
253
+ "#{prefix}#{solr_field}:#{RSolr.solr_escape(value.utc.strftime("%Y-%m-%dT%H:%M:%SZ"))}"
254
+ when value.is_a?(Date)
255
+ # rubocop:disable Rails/Date
256
+ "#{prefix}#{solr_field}:#{RSolr.solr_escape(value.to_time(:local).strftime("%Y-%m-%dT%H:%M:%SZ"))}"
257
+ # rubocop:enable Rails/Date
257
258
  when (value.is_a?(TrueClass) or value.is_a?(FalseClass) or value == 'true' or value == 'false'),
258
259
  (value.is_a?(Integer) or (value.to_i.to_s == value if value.respond_to? :to_i)),
259
260
  (value.is_a?(Float) or (value.to_f.to_s == value if value.respond_to? :to_f))
@@ -270,5 +271,11 @@ module Blacklight::Solr
270
271
  def grouped_key_for_results
271
272
  blacklight_config.index.group
272
273
  end
274
+
275
+ def facet_fields_to_include_in_request
276
+ blacklight_config.facet_fields.select do |field_name,facet|
277
+ facet.include_in_request || (facet.include_in_request.nil? && blacklight_config.add_facet_fields_to_solr_request)
278
+ end
279
+ end
273
280
  end
274
281
  end
@@ -41,16 +41,16 @@ module Blacklight
41
41
  def send_and_receive(path, solr_params = {})
42
42
  benchmark("Solr fetch", level: :debug) do
43
43
  key = blacklight_config.http_method == :post ? :data : :params
44
- res = connection.send_and_receive(path, {key=>solr_params.to_hash, method:blacklight_config.http_method})
44
+ res = connection.send_and_receive(path, {key=>solr_params.to_hash, method: blacklight_config.http_method})
45
45
 
46
46
  solr_response = blacklight_config.response_model.new(res, solr_params, document_model: blacklight_config.document_model, blacklight_config: blacklight_config)
47
47
 
48
- Blacklight.logger.debug("Solr query: #{solr_params.inspect}")
48
+ Blacklight.logger.debug("Solr query: #{blacklight_config.http_method} #{path} #{solr_params.to_hash.inspect}")
49
49
  Blacklight.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
50
50
  solr_response
51
51
  end
52
52
  rescue Errno::ECONNREFUSED => e
53
- raise Blacklight::Exceptions::ECONNREFUSED.new("Unable to connect to Solr instance using #{connection.inspect}")
53
+ raise Blacklight::Exceptions::ECONNREFUSED.new("Unable to connect to Solr instance using #{connection.inspect}: #{e.inspect}")
54
54
  rescue RSolr::Error::Http => e
55
55
  raise Blacklight::Exceptions::InvalidRequest.new(e.message)
56
56
  end
@@ -69,7 +69,7 @@ class Blacklight::SolrResponse < HashWithIndifferentAccess
69
69
  end
70
70
 
71
71
  def group key
72
- grouped.select { |x| x.key == key }.first
72
+ grouped.find { |x| x.key == key }
73
73
  end
74
74
 
75
75
  def grouped?
@@ -30,4 +30,4 @@ class Blacklight::SolrResponse::Group
30
30
  def field
31
31
  response.group_field
32
32
  end
33
- end
33
+ end
@@ -46,4 +46,4 @@ class Blacklight::SolrResponse::GroupResponse
46
46
  response.respond_to?(meth) || super
47
47
  end
48
48
 
49
- end
49
+ end
@@ -11,4 +11,4 @@ module Blacklight::SolrResponse::MoreLikeThis
11
11
 
12
12
  self[:moreLikeThis]
13
13
  end
14
- end
14
+ end
@@ -14,4 +14,4 @@ module Blacklight::SolrResponse::PaginationMethods
14
14
  def total_count #:nodoc:
15
15
  total
16
16
  end
17
- end
17
+ end
@@ -57,10 +57,9 @@ module Blacklight::SolrResponse::Spelling
57
57
  # origFreq =>
58
58
  # suggestion => [{ frequency =>, word => }] # for extended results
59
59
  # suggestion => ['word'] # for non-extended results
60
- origFreq = term_info['origFreq']
61
60
  if suggestions.index("correctlySpelled")
62
61
  word_suggestions << term_info['suggestion'].map do |suggestion|
63
- suggestion['word'] if suggestion['freq'] > origFreq
62
+ suggestion['word'] if suggestion['freq'] > term_info['origFreq']
64
63
  end
65
64
  else
66
65
  # only extended suggestions have frequency so we just return all suggestions
@@ -89,4 +88,3 @@ module Blacklight::SolrResponse::Spelling
89
88
  end
90
89
 
91
90
  end
92
-
@@ -20,8 +20,6 @@ module Blacklight::TokenBasedUser
20
20
  @token_user ||= if params[:encrypted_user_id]
21
21
  user_id = decrypt_user_id params[:encrypted_user_id]
22
22
  User.find(user_id)
23
- else
24
- nil
25
23
  end
26
24
  end
27
25
 
@@ -39,7 +37,7 @@ module Blacklight::TokenBasedUser
39
37
  # Used for #export action with encrypted user_id, available
40
38
  # as a helper method for views.
41
39
  def encrypt_user_id(user_id)
42
- message_encryptor.encrypt_and_sign([user_id, Time.now])
40
+ message_encryptor.encrypt_and_sign([user_id, Time.zone.now])
43
41
  end
44
42
 
45
43
  ##
@@ -17,7 +17,7 @@ module Blacklight::User
17
17
 
18
18
  def bookmarks_for_documents documents = []
19
19
  if documents.length > 0
20
- bookmarks.where(document_type: documents.first.class.base_class, document_id: documents.map { |x| x.id})
20
+ bookmarks.where(document_type: documents.first.class.base_class, document_id: documents.map(&:id))
21
21
  else
22
22
  []
23
23
  end
@@ -6,17 +6,32 @@ module Blacklight
6
6
  def assets
7
7
  copy_file "blacklight.css.scss", "app/assets/stylesheets/blacklight.css.scss"
8
8
 
9
- unless IO.read("app/assets/javascripts/application.js").include?('blacklight/blacklight')
10
- marker = IO.read("app/assets/javascripts/application.js").include?('turbolinks') ?
11
- '//= require turbolinks' : "//= require jquery_ujs"
12
- insert_into_file "app/assets/javascripts/application.js", :after => marker do
13
- %q{
9
+ return if has_blacklight_assets?
10
+
11
+ marker = if turbolinks?
12
+ '//= require turbolinks'
13
+ else
14
+ '//= require jquery_ujs'
15
+ end
16
+
17
+ insert_into_file "app/assets/javascripts/application.js", :after => marker do
18
+ <<-EOF
14
19
  //
15
20
  // Required by Blacklight
16
- //= require blacklight/blacklight}
17
- end
21
+ //= require blacklight/blacklight
22
+ EOF
18
23
  end
19
24
 
20
25
  end
26
+
27
+ private
28
+
29
+ def turbolinks?
30
+ @turbolinks ||= IO.read("app/assets/javascripts/application.js").include?('turbolinks')
31
+ end
32
+
33
+ def has_blacklight_assets?
34
+ IO.read("app/assets/javascripts/application.js").include?('blacklight/blacklight')
35
+ end
21
36
  end
22
37
  end
@@ -41,7 +41,7 @@ namespace :blacklight do
41
41
  response = conn.send_and_receive 'admin/ping', {}
42
42
  puts response['status']
43
43
  errors += 1 unless response['status'] == "OK"
44
- rescue Exception => e
44
+ rescue => e
45
45
  errors += 1
46
46
  puts e.to_s
47
47
  end
@@ -55,7 +55,7 @@ namespace :blacklight do
55
55
  controller = args[:controller_name].constantize.new if args[:controller_name]
56
56
  controller ||= CatalogController.new
57
57
 
58
- puts "[#{controller.class.to_s}]"
58
+ puts "[#{controller.class}]"
59
59
 
60
60
  print " - find: "
61
61
 
@@ -73,7 +73,7 @@ namespace :blacklight do
73
73
  puts "\tdoc count: #{response.docs.length}"
74
74
  puts "\tfacet fields: #{response.facets.length}"
75
75
  end
76
- rescue Exception => e
76
+ rescue => e
77
77
  errors += 1
78
78
  puts e.to_s
79
79
  end
@@ -95,7 +95,7 @@ namespace :blacklight do
95
95
  puts "\tdoc count: #{docs.length}"
96
96
  puts "\tfacet fields: #{response.facets.length}"
97
97
  end
98
- rescue Exception => e
98
+ rescue => e
99
99
  errors += 1
100
100
  puts e.to_s
101
101
  end
@@ -115,7 +115,7 @@ namespace :blacklight do
115
115
  if verbose
116
116
  puts "\tstatus: #{response.header['status']}"
117
117
  end
118
- rescue Exception => e
118
+ rescue => e
119
119
  errors += 1
120
120
  puts e.to_s
121
121
  end
@@ -36,7 +36,7 @@ describe BookmarksController do
36
36
  it "has a 500 status code when delete is not success" do
37
37
  bm = double(Bookmark)
38
38
  allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
39
- allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :first).and_return(double('bookmark', delete: nil, destroyed?: false))
39
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :find_by).and_return(double('bookmark', delete: nil, destroyed?: false))
40
40
 
41
41
  xhr :delete, :destroy, :id => 'pleasekillme', :format => :js
42
42
 
@@ -305,7 +305,7 @@ describe CatalogHelper do
305
305
  end
306
306
  end
307
307
 
308
- describe "#is_bookmarked?" do
308
+ describe "#bookmarked?" do
309
309
 
310
310
  let(:bookmark) { Bookmark.new document: bookmarked_document }
311
311
  let(:bookmarked_document) { SolrDocument.new(id: 'a') }
@@ -315,11 +315,11 @@ describe CatalogHelper do
315
315
  end
316
316
 
317
317
  it "should be bookmarked if the document is in the bookmarks" do
318
- expect(helper.is_bookmarked?(bookmarked_document)).to eq true
318
+ expect(helper.bookmarked?(bookmarked_document)).to eq true
319
319
  end
320
320
 
321
321
  it "should not be bookmarked if the document is not listed in the bookmarks" do
322
- expect(helper.is_bookmarked?(SolrDocument.new(id: 'b'))).to eq false
322
+ expect(helper.bookmarked?(SolrDocument.new(id: 'b'))).to eq false
323
323
  end
324
324
  end
325
325
 
@@ -124,7 +124,7 @@ describe Blacklight::SolrResponse::Facets do
124
124
  subject { Blacklight::SolrResponse.new(response, {}) }
125
125
 
126
126
  it "should mark the facet.missing field with a human-readable label and fq" do
127
- missing = subject.aggregations["some_field"].items.select { |i| i.value.nil? }.first
127
+ missing = subject.aggregations["some_field"].items.find { |i| i.value.nil? }
128
128
 
129
129
  expect(missing.label).to eq "[Missing]"
130
130
  expect(missing.fq).to eq "-some_field:[* TO *]"
@@ -169,7 +169,7 @@ describe Blacklight::SolrResponse::Facets do
169
169
  expect(field.items.size).to eq 2
170
170
  expect(field.items.map { |x| x.value }).to_not include 'field:not_appearing_in_the_config'
171
171
 
172
- facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first
172
+ facet_item = field.items.find { |x| x.value == 'a_simple_query' }
173
173
 
174
174
  expect(facet_item.value).to eq 'a_simple_query'
175
175
  expect(facet_item.hits).to eq 10
@@ -7,7 +7,7 @@ describe Blacklight::SolrResponse::GroupResponse do
7
7
  end
8
8
 
9
9
  let(:group) do
10
- response.grouped.select { |x| x.key == "result_group_ssi" }.first
10
+ response.grouped.find { |x| x.key == "result_group_ssi" }
11
11
  end
12
12
 
13
13
  describe "groups" do
@@ -7,7 +7,7 @@ describe Blacklight::SolrResponse::Group do
7
7
  end
8
8
 
9
9
  let(:group) do
10
- response.grouped.select { |x| x.key == "result_group_ssi" }.first
10
+ response.grouped.find { |x| x.key == "result_group_ssi" }
11
11
  end
12
12
 
13
13
  subject do
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: 5.13.0
4
+ version: 5.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2015-04-10 00:00:00.000000000 Z
20
+ date: 2015-04-16 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -246,6 +246,9 @@ extra_rdoc_files: []
246
246
  files:
247
247
  - ".gitignore"
248
248
  - ".rspec"
249
+ - ".rubocop.yml"
250
+ - ".rubocop_hound.yml"
251
+ - ".rubocop_todo.yml"
249
252
  - ".travis.yml"
250
253
  - ".yardopts"
251
254
  - Gemfile