blacklight 6.0.0.pre4 → 6.0.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de33efb7e9513e4348986f8e64b4f2cfec107802
4
- data.tar.gz: 74ac4159ee1072f93f3f54b8115e14d501d68773
3
+ metadata.gz: 7626335c66be4201927a8a1afbe8df051da1b4b0
4
+ data.tar.gz: 5bd3bfaac1b8b69940573d3172c7e0e8a97522af
5
5
  SHA512:
6
- metadata.gz: f23fb77ae90ed8cbb00a6461643a4e3da47771ce25d02a717944722fe239b8d045d73206305e499d2b282f7cd6913eff624707c91adfba2721f83cd6ac37d1f9
7
- data.tar.gz: 4c752134df04876f6bcc9831fe03071df4a7976657a5a15780226a02bc76d1b4ca5d77ab59d5b0f6c5e9cc67f8475ff0478a4f45643fd70312e414e51ff480b8
6
+ metadata.gz: 814188a4b39df6c79dc2c993e0bc1ab879028b071b4341efcd4ebdb30594d1c3a8efb64b317d2f8e808d9dbc7ad029f5d313aff387711f2c21d6e8d7ac9107b0
7
+ data.tar.gz: 11a6ea22038b58e3240397a7e36dfe16c8c28730e18cbcedbe6fca188887fcce3ad8ff511757b5fe0d7c013420a458a424de3cb0c10fc4d01415c6c703248b3a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.0.pre4
1
+ 6.0.0.pre5
@@ -12,7 +12,7 @@ module Blacklight::Bookmarks
12
12
 
13
13
  copy_blacklight_config_from(CatalogController)
14
14
 
15
- before_filter :verify_user
15
+ before_action :verify_user
16
16
 
17
17
  blacklight_config.add_results_collection_tool(:clear_bookmarks_widget)
18
18
 
@@ -97,7 +97,7 @@ module Blacklight::Bookmarks
97
97
  # Beware, :id is the Solr document_id, not the actual Bookmark id.
98
98
  # idempotent, as DELETE is supposed to be.
99
99
  def destroy
100
- bookmark = current_or_guest_user.bookmarks.find_by(document_id: params[:id], document_type: blacklight_config.document_model)
100
+ bookmark = current_or_guest_user.bookmarks.find_by(document_id: params[:id], document_type: blacklight_config.document_model.to_s)
101
101
 
102
102
  if bookmark && bookmark.delete && bookmark.destroyed?
103
103
  if request.xhr?
@@ -249,6 +249,8 @@ module Blacklight::Catalog
249
249
  # CatalogController to do something else -- older BL displayed a Catalog#inde
250
250
  # page with a flash message and a 404 status.
251
251
  def invalid_document_id_error(exception)
252
+ raise exception unless Pathname.new("#{Rails.root}/public/404.html").exist?
253
+
252
254
  error_info = {
253
255
  "status" => "404",
254
256
  "error" => "#{exception.class}: #{exception.message}"
@@ -11,7 +11,7 @@ module Blacklight::SearchContext
11
11
  module ClassMethods
12
12
  # Save the submitted search parameters in the search session
13
13
  def record_search_parameters opts = { only: :index}
14
- before_filter :current_search_session, opts
14
+ before_action :current_search_session, opts
15
15
  end
16
16
  end
17
17
 
@@ -93,7 +93,7 @@ module Blacklight::SearchContext
93
93
  def setup_next_and_previous_documents
94
94
  if search_session['counter'] and current_search_session
95
95
  index = search_session['counter'].to_i - 1
96
- response, documents = get_previous_and_next_documents_for_search index, current_search_session.query_params.with_indifferent_access
96
+ response, documents = get_previous_and_next_documents_for_search index, ActiveSupport::HashWithIndifferentAccess.new(current_search_session.query_params)
97
97
 
98
98
  search_session['total'] = response.total
99
99
  @search_context_response = response
@@ -48,7 +48,7 @@ module Blacklight::SearchHelper
48
48
  include Blacklight::RequestBuilders
49
49
 
50
50
  # a solr query method
51
- # @param [Hash,HashWithIndifferentAccess] user_params ({}) the user provided parameters (e.g. query, facets, sort, etc)
51
+ # @param [Hash] user_params ({}) the user provided parameters (e.g. query, facets, sort, etc)
52
52
  # @yield [search_builder] optional block yields configured SearchBuilder, caller can modify or create new SearchBuilder to be used. Block should return SearchBuilder to be used.
53
53
  # @return [Blacklight::Solr::Response] the solr response object
54
54
  def search_results(user_params)
@@ -2,8 +2,8 @@ class SavedSearchesController < ApplicationController
2
2
  include Blacklight::Configurable
3
3
 
4
4
  copy_blacklight_config_from(CatalogController)
5
- before_filter :require_user_authentication_provider
6
- before_filter :verify_user
5
+ before_action :require_user_authentication_provider
6
+ before_action :verify_user
7
7
 
8
8
  def index
9
9
  @searches = current_user.searches
@@ -13,7 +13,7 @@ module Blacklight::UrlHelperBehavior
13
13
 
14
14
  # link_to_document(doc, 'VIEW', :counter => 3)
15
15
  # Use the catalog_path RESTful route to create a link to the show page for a specific item.
16
- # catalog_path accepts a HashWithIndifferentAccess object. The solr query params are stored in the session,
16
+ # catalog_path accepts a hash. The solr query params are stored in the session,
17
17
  # so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results.
18
18
  def link_to_document(doc, field_or_opts = nil, opts={:counter => nil})
19
19
  if field_or_opts.is_a? Hash
@@ -14,7 +14,9 @@ class Bookmark < ActiveRecord::Base
14
14
  end
15
15
 
16
16
  def document_type
17
- (super.constantize if defined?(super)) || default_document_type
17
+ value = super if defined?(super)
18
+ value &&= value.constantize
19
+ value ||= default_document_type
18
20
  end
19
21
 
20
22
  def default_document_type
@@ -39,7 +39,7 @@ module Blacklight::Document
39
39
  alias_method :solr_response, :response
40
40
 
41
41
  def initialize(source_doc={}, response=nil)
42
- @_source = source_doc.with_indifferent_access
42
+ @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc)
43
43
  @response = response
44
44
  apply_extensions
45
45
  end
@@ -59,6 +59,10 @@ module Blacklight::Document
59
59
  false
60
60
  end
61
61
 
62
+ def marked_for_destruction?
63
+ false
64
+ end
65
+
62
66
  ##
63
67
  # #to_partial_path is also defined in Blacklight::Document, but
64
68
  # ActiveModel::Conversion (included above) will overwrite that..
@@ -56,13 +56,9 @@ module Blacklight::Document::Export
56
56
  # registered. This is a bit sketchy though.
57
57
  def will_export_as(short_name, content_type = nil)
58
58
  #Lookup in Rails Mime::Type, register if needed, otherwise take
59
- # content-type from registration if needed. This uses
60
- # some 'api' to Mime::Type that may or may not be entirely
61
- # public, the fact that a Mime::CONST is registered for every
62
- # type. But that's the only way to do the kind of check we need, sorry.
63
- if defined?(Mime) && Mime.const_defined?(short_name.to_s.upcase)
64
- mime_type = "Mime::#{short_name.to_s.upcase}".constantize
65
- content_type ||= mime_type.to_s
59
+ # content-type from registration if needed.
60
+ if defined?(Mime) && Mime[short_name.to_sym]
61
+ content_type ||= Mime[short_name.to_sym]
66
62
  else
67
63
  # not registered, we need to register. Use register_alias to be least
68
64
  # likely to interfere with host app.
@@ -12,7 +12,7 @@ module Blacklight::User
12
12
 
13
13
  def bookmarks_for_documents documents = []
14
14
  if documents.length > 0
15
- bookmarks.where(document_type: documents.first.class.base_class, document_id: documents.map(&:id))
15
+ bookmarks.where(document_type: documents.first.class.base_class.to_s, document_id: documents.map(&:id))
16
16
  else
17
17
  []
18
18
  end
@@ -18,7 +18,7 @@
18
18
 
19
19
  <title><%= render_page_title %></title>
20
20
  <%= opensearch_description_tag application_name, opensearch_catalog_url(:format => 'xml') %>
21
- <%= favicon_link_tag 'favicon.ico' %>
21
+ <%= favicon_link_tag %>
22
22
  <%= stylesheet_link_tag "application", media: "all" %>
23
23
  <%= javascript_include_tag "application" %>
24
24
  <%= csrf_meta_tags %>
data/lib/blacklight.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'kaminari'
2
2
  require 'deprecation'
3
3
  require 'blacklight/utils'
4
+ require 'active_support/hash_with_indifferent_access'
4
5
 
5
6
  module Blacklight
6
7
  autoload :AbstractRepository, 'blacklight/abstract_repository'
@@ -16,6 +16,21 @@ module Blacklight
16
16
  @connection ||= build_connection
17
17
  end
18
18
 
19
+ ##
20
+ # Find a single document result by a known id
21
+ # @param [String] document's unique key value
22
+ # @param [Hash] additional query parameters
23
+ def find(id, params = {})
24
+ fail NotImplementedError
25
+ end
26
+
27
+ ##
28
+ # Execute a search query against a search index
29
+ # @param [Hash] query parameters
30
+ def search(params = {})
31
+ fail NotImplementedError
32
+ end
33
+
19
34
  protected
20
35
  def connection_config
21
36
  blacklight_config.connection_config
@@ -26,6 +26,10 @@ module Blacklight
26
26
  end
27
27
  end
28
28
 
29
+ initializer "blacklight.assets.precompile" do |app|
30
+ app.config.assets.precompile += %w(favicon.ico)
31
+ end
32
+
29
33
  Blacklight::Engine.config.sms_mappings = {
30
34
  'Virgin' => 'vmobl.com',
31
35
  'AT&T' => 'txt.att.net',
@@ -1,4 +1,8 @@
1
1
  module Blacklight
2
+ ##
3
+ # Blacklight's SearchBuilder converts blacklight request parameters into
4
+ # query parameters appropriate for search index. It does so by evaluating a
5
+ # chain of processing methods to populate a result hash (see {#to_hash}).
2
6
  class SearchBuilder
3
7
  extend Deprecation
4
8
  class_attribute :default_processor_chain
@@ -106,7 +110,7 @@ module Blacklight
106
110
  delegate :[], :key?, to: :to_hash
107
111
 
108
112
  # a solr query method
109
- # @param [Hash,HashWithIndifferentAccess] extra_controller_params (nil) extra parameters to add to the search
113
+ # @param [Hash] extra_controller_params (nil) extra parameters to add to the search
110
114
  # @return [Blacklight::Solr::Response] the solr response object
111
115
  def to_hash
112
116
  if params_need_update?
@@ -115,7 +115,7 @@ module Blacklight
115
115
  # Reset any search parameters that store search context
116
116
  # and need to be reset when e.g. constraints change
117
117
  def reset_search_params
118
- Parameters.sanitize(params).except(:page, :counter).with_indifferent_access
118
+ ActiveSupport::HashWithIndifferentAccess.new(Parameters.sanitize(params).except(:page, :counter))
119
119
  end
120
120
 
121
121
  # TODO: this code is duplicated in Blacklight::FacetsHelperBehavior
@@ -1,6 +1,6 @@
1
1
  class Blacklight::Solr::InvalidParameter < ArgumentError; end
2
2
 
3
- class Blacklight::Solr::Request < HashWithIndifferentAccess
3
+ class Blacklight::Solr::Request < ActiveSupport::HashWithIndifferentAccess
4
4
 
5
5
  SINGULAR_KEYS = %w{facet fl q qt rows start spellcheck spellcheck.q sort per_page wt hl group defType}
6
6
  ARRAY_KEYS = %w{facet.field facet.query facet.pivot fq hl.fl}
@@ -1,4 +1,4 @@
1
- class Blacklight::Solr::Response < HashWithIndifferentAccess
1
+ class Blacklight::Solr::Response < ActiveSupport::HashWithIndifferentAccess
2
2
  extend Deprecation
3
3
 
4
4
  # Using required_dependency to work around Rails autoloading
@@ -22,8 +22,8 @@ class Blacklight::Solr::Response < HashWithIndifferentAccess
22
22
  attr_accessor :document_model, :blacklight_config
23
23
 
24
24
  def initialize(data, request_params, options = {})
25
- super(force_to_utf8(data))
26
- @request_params = request_params
25
+ super(force_to_utf8(ActiveSupport::HashWithIndifferentAccess.new(data)))
26
+ @request_params = ActiveSupport::HashWithIndifferentAccess.new(request_params)
27
27
  self.document_model = options[:solr_document_model] || options[:document_model] || SolrDocument
28
28
  self.blacklight_config = options[:blacklight_config]
29
29
  end
@@ -153,7 +153,21 @@ module Blacklight
153
153
  # @return [OpenStructWithHashAccess] a new instance of an OpenStructWithHashAccess
154
154
  def merge! other_hash
155
155
  @table.merge!(nested_class, (other_hash if other_hash.is_a? Hash) || other_hash.to_h)
156
- end
156
+ end
157
+
158
+ ##
159
+ # Override #method_missing from OpenStruct to ensure the default_proc logic
160
+ # gets triggered.
161
+ def method_missing(mid, *args)
162
+ len = args.length
163
+
164
+ if len == 0
165
+ new_ostruct_member(mid)
166
+ @table[mid]
167
+ else
168
+ super
169
+ end
170
+ end
157
171
 
158
172
  private
159
173
  def set_default_proc!
@@ -3,6 +3,15 @@ class <%= controller_name.classify %>Controller < ApplicationController
3
3
  include Blacklight::Catalog
4
4
 
5
5
  configure_blacklight do |config|
6
+ ## Class for sending and receiving requests from a search index
7
+ # config.repository_class = Blacklight::Solr::Repository
8
+ #
9
+ ## Class for converting Blacklight's url parameters to into request parameters for the search index
10
+ # config.search_builder_class = ::SearchBuilder
11
+ #
12
+ ## Model that maps search index responses to the blacklight response model
13
+ # config.response_model = Blacklight::Solr::Response
14
+
6
15
  ## Default parameters to send to solr for all search-like requests. See also SearchBuilder#processed_parameters
7
16
  config.default_solr_params = {
8
17
  rows: 10
@@ -5,7 +5,7 @@ describe Blacklight::Base do
5
5
  subject { controller}
6
6
 
7
7
  describe "#search_state" do
8
- let(:params) { double }
8
+ let(:params) { { a: 1 } }
9
9
  before { allow(controller).to receive_messages(params: params) }
10
10
  subject { controller.send(:search_state) }
11
11
 
@@ -10,7 +10,7 @@ describe CatalogHelper do
10
10
  total = args[:total]
11
11
  start = (current_page - 1) * per_page
12
12
 
13
- mock_docs = (1..total).to_a.map { {}.with_indifferent_access }
13
+ mock_docs = (1..total).to_a.map { ActiveSupport::HashWithIndifferentAccess.new }
14
14
 
15
15
  mock_response = Kaminari.paginate_array(mock_docs).page(current_page).per(per_page)
16
16
 
@@ -111,7 +111,7 @@ describe FacetsHelper do
111
111
  end
112
112
 
113
113
  it "should not be collapsed if it is in the params" do
114
- params[:f] = { basic_field: [1], no_collapse: [2] }.with_indifferent_access
114
+ params[:f] = ActiveSupport::HashWithIndifferentAccess.new(basic_field: [1], no_collapse: [2])
115
115
  expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be false
116
116
  expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be false
117
117
  end
@@ -51,11 +51,11 @@ describe Blacklight::Solr::Repository do
51
51
  end
52
52
 
53
53
  it "should preserve the class of the incoming params" do
54
- doc_params = HashWithIndifferentAccess.new
54
+ doc_params = ActiveSupport::HashWithIndifferentAccess.new
55
55
  allow(subject.connection).to receive(:send_and_receive).with('select', anything).and_return(mock_response)
56
56
  response = subject.find("123", doc_params)
57
57
  expect(response).to be_a_kind_of Blacklight::Solr::Response
58
- expect(response.params).to be_a_kind_of HashWithIndifferentAccess
58
+ expect(response.params).to be_a_kind_of ActiveSupport::HashWithIndifferentAccess
59
59
  end
60
60
  end
61
61
 
@@ -84,13 +84,13 @@ describe Blacklight::Solr::Repository do
84
84
  end
85
85
 
86
86
  it "should preserve the class of the incoming params" do
87
- search_params = HashWithIndifferentAccess.new
87
+ search_params = ActiveSupport::HashWithIndifferentAccess.new
88
88
  search_params[:q] = "query"
89
89
  allow(subject.connection).to receive(:send_and_receive).with('select', anything).and_return(mock_response)
90
90
 
91
91
  response = subject.search(search_params)
92
92
  expect(response).to be_a_kind_of Blacklight::Solr::Response
93
- expect(response.params).to be_a_kind_of HashWithIndifferentAccess
93
+ expect(response.params).to be_a_kind_of ActiveSupport::HashWithIndifferentAccess
94
94
  end
95
95
  end
96
96
 
@@ -26,7 +26,7 @@ describe Blacklight::Solr::Response::Facets do
26
26
  let(:facet_field) { ['my_field', []] }
27
27
  let(:response_header) { { params: request_params }}
28
28
  let(:request_params) { Hash.new }
29
- subject { Blacklight::Solr::Response.new({responseHeader: response_header, facet_counts: { facet_fields: [facet_field] }}.with_indifferent_access, request_params) }
29
+ subject { Blacklight::Solr::Response.new({responseHeader: response_header, facet_counts: { facet_fields: [facet_field] }}, request_params) }
30
30
 
31
31
  describe "#limit" do
32
32
  it "should extract a field-specific limit value" do
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "catalog/_paginate_compact.html.erb" do
4
+ let(:user) { User.new.tap { |u| u.save(validate: false) } }
4
5
 
5
6
  describe "with a real solr response", :integration => true do
6
7
  def blacklight_config
@@ -33,7 +34,7 @@ describe "catalog/_paginate_compact.html.erb" do
33
34
  end
34
35
 
35
36
  it "should render ActiveRecord collections" do
36
- 50.times { b = Bookmark.new; b.user_id = 1; b.save! }
37
+ 50.times { b = Bookmark.new; b.user = user; b.save! }
37
38
  render :partial => 'catalog/paginate_compact', :object => Bookmark.page(1).per(25)
38
39
  expect(rendered).to have_selector ".page_entries"
39
40
  expect(rendered).to have_selector "a[@rel=next]"
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.0.0.pre4
4
+ version: 6.0.0.pre5
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: 2015-11-17 00:00:00.000000000 Z
20
+ date: 2015-12-22 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails