blacklight 7.26.1 → 7.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +6 -6
- data/VERSION +1 -1
- data/app/components/blacklight/advanced_search_form_component.rb +1 -1
- data/app/components/blacklight/facet_component.rb +18 -3
- data/app/components/blacklight/search_context_component.html.erb +2 -2
- data/app/components/blacklight/search_context_component.rb +4 -4
- data/app/controllers/concerns/blacklight/catalog.rb +12 -3
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +19 -1
- data/app/helpers/blacklight/url_helper_behavior.rb +4 -4
- data/app/models/search.rb +2 -1
- data/app/presenters/blacklight/clause_presenter.rb +1 -1
- data/app/services/blacklight/search_params_yaml_coder.rb +48 -0
- data/app/views/bookmarks/_tools.html.erb +1 -1
- data/app/views/catalog/_advanced_search_help.html.erb +1 -1
- data/lib/blacklight/engine.rb +2 -0
- data/lib/blacklight/solr/response/facets.rb +6 -0
- data/spec/components/blacklight/facet_component_spec.rb +102 -0
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +16 -0
- data/spec/models/search_spec.rb +33 -14
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e57b2c0a5ca770fa8fbc0560072609b5db93d10c952d33af0db3d69ae2dfc6
|
4
|
+
data.tar.gz: 231146a7df38ba031b116075b75bf9abe7f91e760485524fb8678a624d9be893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95bc567df4947b3a11b37749c0c9a123da3c5a20552e78195a77775638bc5075d1db2c6d11d8158864346a1346a29a296a3ce8a873b497a9946eb011cd53843f
|
7
|
+
data.tar.gz: 28efc83fd658e1e43a3f85c8bea5ec389ee913b540b413ce967925b98b48a5d4d9422a2df1fcbf14d905ba0e31cba3fe9267a3cee38e6371adaf83b963183f41
|
data/.github/workflows/ruby.yml
CHANGED
@@ -76,11 +76,11 @@ jobs:
|
|
76
76
|
- name: Install dependencies
|
77
77
|
run: bundle install
|
78
78
|
env:
|
79
|
-
RAILS_VERSION: 6.0.
|
79
|
+
RAILS_VERSION: 6.0.5.1
|
80
80
|
- name: Run tests
|
81
81
|
run: bundle exec rake ci
|
82
82
|
env:
|
83
|
-
RAILS_VERSION: 6.0.
|
83
|
+
RAILS_VERSION: 6.0.5.1
|
84
84
|
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
|
85
85
|
test_rails5_2:
|
86
86
|
runs-on: ubuntu-latest
|
@@ -96,11 +96,11 @@ jobs:
|
|
96
96
|
- name: Install dependencies
|
97
97
|
run: bundle install
|
98
98
|
env:
|
99
|
-
RAILS_VERSION: 5.2.
|
99
|
+
RAILS_VERSION: 5.2.8.1
|
100
100
|
- name: Run tests
|
101
101
|
run: bundle exec rake ci
|
102
102
|
env:
|
103
|
-
RAILS_VERSION: 5.2.
|
103
|
+
RAILS_VERSION: 5.2.8.1
|
104
104
|
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
|
105
105
|
|
106
106
|
test_rails6_1:
|
@@ -117,11 +117,11 @@ jobs:
|
|
117
117
|
- name: Install dependencies
|
118
118
|
run: bundle install
|
119
119
|
env:
|
120
|
-
RAILS_VERSION: 6.1.
|
120
|
+
RAILS_VERSION: 6.1.6.1
|
121
121
|
- name: Run tests
|
122
122
|
run: bundle exec rake ci
|
123
123
|
env:
|
124
|
-
RAILS_VERSION: 6.1.
|
124
|
+
RAILS_VERSION: 6.1.6.1
|
125
125
|
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-keeps --skip-action-cable --skip-test'
|
126
126
|
api_test:
|
127
127
|
runs-on: ubuntu-latest
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.28.0
|
@@ -43,7 +43,7 @@ module Blacklight
|
|
43
43
|
search_field_control do
|
44
44
|
fields_for('clause[]', i, include_id: false) do |f|
|
45
45
|
content_tag(:div, class: 'form-group advanced-search-field row') do
|
46
|
-
f.label(:query, field.display_label('search'), class: "col-
|
46
|
+
f.label(:query, field.display_label('search'), class: "col-sm-3 col-form-label text-md-right") +
|
47
47
|
content_tag(:div, class: 'col-sm-9') do
|
48
48
|
f.hidden_field(:field, value: field.key) +
|
49
49
|
f.text_field(:query, value: query_for_search_clause(field.key), class: 'form-control')
|
@@ -11,11 +11,19 @@ module Blacklight
|
|
11
11
|
# @param [Blacklight::Solr::Response::Facets::FacetField] display_facet
|
12
12
|
# @param [Blacklight::Configuration] blacklight_config
|
13
13
|
# @param [Boolean] layout
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
14
15
|
def initialize(display_facet_or_field_config: nil, display_facet: nil, field_config: nil, response: nil, blacklight_config: nil, **component_args)
|
15
|
-
if display_facet_or_field_config.is_a?
|
16
|
+
if display_facet_or_field_config.is_a? Blacklight::FacetFieldPresenter
|
17
|
+
@facet_field_presenter = display_facet_or_field_config
|
18
|
+
@field_config = @facet_field_presenter.facet_field
|
19
|
+
@display_facet = @facet_field_presenter.display_facet
|
20
|
+
elsif display_facet_or_field_config.is_a?(Blacklight::Configuration::Field) || field_config
|
21
|
+
@facet_field_presenter = nil # we need the view context to generate this
|
16
22
|
@field_config = display_facet_or_field_config || field_config
|
17
|
-
@display_facet = display_facet ||
|
23
|
+
@display_facet = display_facet ||
|
24
|
+
response&.aggregations&.fetch(@field_config.field) { Blacklight::Solr::Response::Facets::NullFacetField.new(@field_config.field, response: response) }
|
18
25
|
elsif (display_facet || display_facet_or_field_config).respond_to?(:name)
|
26
|
+
@facet_field_presenter = nil # we need the view context to generate this
|
19
27
|
@display_facet = display_facet || display_facet_or_field_config
|
20
28
|
@field_config = field_config || blacklight_config&.facet_configuration_for_field(@display_facet.name)
|
21
29
|
else
|
@@ -24,20 +32,27 @@ module Blacklight
|
|
24
32
|
|
25
33
|
@component_args = component_args
|
26
34
|
end
|
35
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
27
36
|
|
28
37
|
def render?
|
29
38
|
helpers.should_render_field?(@field_config, @display_facet)
|
30
39
|
end
|
31
40
|
|
32
41
|
def call
|
42
|
+
return render_partial if @field_config.partial
|
43
|
+
|
33
44
|
component = @field_config.component == true ? Blacklight::FacetFieldListComponent : @field_config.component
|
34
45
|
|
35
46
|
render(
|
36
47
|
component.new(
|
37
|
-
facet_field: helpers.facet_field_presenter(@field_config, @display_facet),
|
48
|
+
facet_field: @facet_field_presenter || helpers.facet_field_presenter(@field_config, @display_facet),
|
38
49
|
**@component_args
|
39
50
|
)
|
40
51
|
)
|
41
52
|
end
|
53
|
+
|
54
|
+
def render_partial
|
55
|
+
helpers.render(@field_config.partial, locals: { field_name: @field_config.field, facet_field: @field_config, display_facet: @display_facet }.merge(@component_args))
|
56
|
+
end
|
42
57
|
end
|
43
58
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<div class='pagination-search-widgets'>
|
2
2
|
|
3
3
|
<div class="page-links">
|
4
|
-
<%= link_to_previous_document
|
4
|
+
<%= link_to_previous_document %> |
|
5
5
|
|
6
6
|
<%= item_page_entry_info %> |
|
7
7
|
|
8
|
-
<%= link_to_next_document
|
8
|
+
<%= link_to_next_document %>
|
9
9
|
</div>
|
10
10
|
</div>
|
@@ -19,15 +19,15 @@ module Blacklight
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def link_to_previous_document(*args)
|
22
|
+
def link_to_previous_document(document = nil, *args, **kwargs)
|
23
23
|
Deprecation.silence(Blacklight::UrlHelperBehavior) do
|
24
|
-
helpers.link_to_previous_document(*args)
|
24
|
+
helpers.link_to_previous_document(document || @search_context[:prev], *args, **kwargs)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def link_to_next_document(*args)
|
28
|
+
def link_to_next_document(document = nil, *args, **kwargs)
|
29
29
|
Deprecation.silence(Blacklight::UrlHelperBehavior) do
|
30
|
-
helpers.link_to_next_document(*args)
|
30
|
+
helpers.link_to_next_document(document || @search_context[:next], *args, **kwargs)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -60,9 +60,7 @@ module Blacklight::Catalog
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def advanced_search
|
63
|
-
|
64
|
-
|
65
|
-
(@response, _deprecated_document_list) = empty_service.search_results
|
63
|
+
(@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results
|
66
64
|
end
|
67
65
|
|
68
66
|
# get a single document from the index
|
@@ -255,6 +253,7 @@ module Blacklight::Catalog
|
|
255
253
|
# By default, any search action from a Blacklight::Catalog controller
|
256
254
|
# should use the current controller when constructing the route.
|
257
255
|
def search_action_url options = {}
|
256
|
+
options = options.to_h if options.is_a? Blacklight::SearchState
|
258
257
|
url_for(options.reverse_merge(action: 'index'))
|
259
258
|
end
|
260
259
|
|
@@ -334,4 +333,14 @@ module Blacklight::Catalog
|
|
334
333
|
flash[:notice] = flash_notice
|
335
334
|
redirect_to search_action_url
|
336
335
|
end
|
336
|
+
|
337
|
+
def blacklight_advanced_search_form_search_service
|
338
|
+
form_search_state = search_state_class.new(blacklight_advanced_search_form_params, blacklight_config, self)
|
339
|
+
|
340
|
+
search_service_class.new(config: blacklight_config, search_state: form_search_state, user_params: form_search_state.to_h, **search_service_context)
|
341
|
+
end
|
342
|
+
|
343
|
+
def blacklight_advanced_search_form_params
|
344
|
+
{}
|
345
|
+
end
|
337
346
|
end
|
@@ -35,7 +35,7 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
35
35
|
end
|
36
36
|
|
37
37
|
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
38
|
-
render_constraints_query(params_or_search_state) + render_constraints_filters(params_or_search_state)
|
38
|
+
render_constraints_query(params_or_search_state) + render_constraints_clauses(params_or_search_state) + render_constraints_filters(params_or_search_state)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -60,6 +60,24 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
##
|
64
|
+
# Render the query constraints
|
65
|
+
#
|
66
|
+
# @deprecated
|
67
|
+
# @param [Blacklight::SearchState,ActionController::Parameters] params_or_search_state query parameters
|
68
|
+
# @return [String]
|
69
|
+
def render_constraints_clauses(params_or_search_state = search_state)
|
70
|
+
search_state = convert_to_search_state(params_or_search_state)
|
71
|
+
|
72
|
+
clause_presenters = search_state.clause_params.map do |key, clause|
|
73
|
+
field_config = blacklight_config.search_fields[clause[:field]]
|
74
|
+
Blacklight::ClausePresenter.new(key, clause, field_config, self, search_state)
|
75
|
+
end
|
76
|
+
|
77
|
+
render(Blacklight::ConstraintComponent.with_collection(clause_presenters))
|
78
|
+
end
|
79
|
+
deprecation_deprecate :render_constraints_clauses
|
80
|
+
|
63
81
|
##
|
64
82
|
# Provide a url for removing a particular constraint. This can be overriden
|
65
83
|
# in the case that you want parameters other than the defaults to be removed
|
@@ -52,8 +52,8 @@ module Blacklight::UrlHelperBehavior
|
|
52
52
|
##
|
53
53
|
# Link to the previous document in the current search context
|
54
54
|
# @deprecated
|
55
|
-
def link_to_previous_document(previous_document)
|
56
|
-
link_opts = session_tracking_params(previous_document, search_session['counter'].to_i - 1).merge(class:
|
55
|
+
def link_to_previous_document(previous_document, classes: 'previous', **addl_link_opts)
|
56
|
+
link_opts = session_tracking_params(previous_document, search_session['counter'].to_i - 1).merge(class: classes, rel: 'prev').merge(addl_link_opts)
|
57
57
|
link_to_unless previous_document.nil?, raw(t('views.pagination.previous')), url_for_document(previous_document), link_opts do
|
58
58
|
tag.span raw(t('views.pagination.previous')), class: 'previous'
|
59
59
|
end
|
@@ -63,8 +63,8 @@ module Blacklight::UrlHelperBehavior
|
|
63
63
|
##
|
64
64
|
# Link to the next document in the current search context
|
65
65
|
# @deprecated
|
66
|
-
def link_to_next_document(next_document)
|
67
|
-
link_opts = session_tracking_params(next_document, search_session['counter'].to_i + 1).merge(class:
|
66
|
+
def link_to_next_document(next_document, classes: 'next', **addl_link_opts)
|
67
|
+
link_opts = session_tracking_params(next_document, search_session['counter'].to_i + 1).merge(class: classes, rel: 'next').merge(addl_link_opts)
|
68
68
|
link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do
|
69
69
|
tag.span raw(t('views.pagination.next')), class: 'next'
|
70
70
|
end
|
data/app/models/search.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
class Search < ApplicationRecord
|
4
4
|
belongs_to :user, optional: true
|
5
5
|
|
6
|
-
|
6
|
+
# use a backwards-compatible serializer until the Rails API stabilizes and we can evaluate for major-revision compatibility
|
7
|
+
serialize :query_params, Blacklight::SearchParamsYamlCoder
|
7
8
|
|
8
9
|
# A Search instance is considered a saved search if it has a user_id.
|
9
10
|
def saved?
|
@@ -25,7 +25,7 @@ module Blacklight
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def remove_href(path = search_state)
|
28
|
-
view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)))
|
28
|
+
view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)).to_h)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
# This is a custom YAML coder for (de)serializing blacklight search parameters that
|
5
|
+
# supports deserializing HashWithIndifferentAccess parameters (as was historically done by Blacklight).
|
6
|
+
class SearchParamsYamlCoder
|
7
|
+
# Serializes an attribute value to a string that will be stored in the database.
|
8
|
+
def self.dump(obj)
|
9
|
+
# Convert HWIA to an ordinary hash so we have some hope of using the regular YAML encoder in the future
|
10
|
+
obj = obj.to_hash if obj.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
11
|
+
|
12
|
+
YAML.dump(obj)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Deserializes a string from the database to an attribute value.
|
16
|
+
def self.load(yaml)
|
17
|
+
return yaml unless yaml.is_a?(String) && yaml.start_with?("---")
|
18
|
+
|
19
|
+
params = yaml_load(yaml)
|
20
|
+
|
21
|
+
params.with_indifferent_access
|
22
|
+
end
|
23
|
+
|
24
|
+
# rubocop:disable Security/YAMLLoad
|
25
|
+
if YAML.respond_to?(:unsafe_load)
|
26
|
+
def self.yaml_load(payload)
|
27
|
+
if ActiveRecord.try(:use_yaml_unsafe_load) || ActiveRecord::Base.try(:use_yaml_unsafe_load)
|
28
|
+
YAML.unsafe_load(payload)
|
29
|
+
else
|
30
|
+
permitted_classes = (ActiveRecord.try(:yaml_column_permitted_classes) || ActiveRecord::Base.try(:yaml_column_permitted_classes) || []) +
|
31
|
+
Blacklight::Engine.config.blacklight.search_params_permitted_classes
|
32
|
+
YAML.safe_load(payload, permitted_classes: permitted_classes, aliases: true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
def self.yaml_load(payload)
|
37
|
+
if ActiveRecord.try(:use_yaml_unsafe_load) || ActiveRecord::Base.try(:use_yaml_unsafe_load)
|
38
|
+
YAML.load(payload)
|
39
|
+
else
|
40
|
+
permitted_classes = (ActiveRecord.try(:yaml_column_permitted_classes) || ActiveRecord::Base.try(:yaml_column_permitted_classes) || []) +
|
41
|
+
Blacklight::Engine.config.blacklight.search_params_permitted_classes
|
42
|
+
YAML.safe_load(payload, permitted_classes: permitted_classes, aliases: true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
# rubocop:enable Security/YAMLLoad
|
47
|
+
end
|
48
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if render_show_doc_actions_method_from_blacklight? %>
|
2
|
-
<%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools",
|
2
|
+
<%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools", link_classes: 'btn btn-outline-primary', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
|
3
3
|
<% else %>
|
4
4
|
<% Deprecation.warn(self, '#render_show_doc_actions is deprecated; use ActionComponents instead') %>
|
5
5
|
<ul class="<%= controller_name %>Tools nav nav-pills">
|
data/lib/blacklight/engine.rb
CHANGED
@@ -59,6 +59,8 @@ module Blacklight
|
|
59
59
|
outer_window: 2
|
60
60
|
}
|
61
61
|
|
62
|
+
bl_global_config.search_params_permitted_classes = [ActiveSupport::HashWithIndifferentAccess, Symbol]
|
63
|
+
|
62
64
|
# Anything that goes into Blacklight::Engine.config is stored as a class
|
63
65
|
# variable on Railtie::Configuration. we're going to encapsulate all the
|
64
66
|
# Blacklight specific stuff in this single struct:
|
@@ -99,6 +99,12 @@ module Blacklight::Solr::Response::Facets
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
class NullFacetField < FacetField
|
103
|
+
def initialize name, items = [], response: nil, **kwargs
|
104
|
+
super(name, items, response: response, **kwargs)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
102
108
|
##
|
103
109
|
# Get all the Solr facet data (fields, queries, pivots) as a hash keyed by
|
104
110
|
# both the Solr field name and/or by the blacklight field name
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::FacetComponent, type: :component do
|
6
|
+
subject(:rendered) do
|
7
|
+
render_inline_to_capybara_node(component)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:component) { described_class.new(**component_kwargs) }
|
11
|
+
let(:component_kwargs) { { field_config: facet_config, display_facet: display_facet } }
|
12
|
+
let(:items) { [{ label: "Book", value: 'Book', hits: 20 }] }
|
13
|
+
|
14
|
+
let(:display_facet) do
|
15
|
+
instance_double(Blacklight::Solr::Response::Facets::FacetField, name: 'field', items: items, limit: nil, sort: :index, offset: 0, prefix: nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'field', component: Blacklight::FacetFieldListComponent).normalize! }
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(controller).to receive(:view_context).and_return(controller.view_context)
|
22
|
+
allow(controller.view_context).to receive(:facet_limit_for).and_return(20)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'delegates to the configured component to render something' do
|
26
|
+
expect(rendered).to have_selector 'ul.facet-values'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a facet configured to use a partial' do
|
30
|
+
let(:facet_config) do
|
31
|
+
Blacklight::Configuration::FacetField.new(key: 'field', partial: 'catalog/facet_partial').normalize!
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
controller.view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('catalog/_facet_partial.html.erb' => 'facet partial'))
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'renders the partial' do
|
39
|
+
expect(rendered).to have_content 'facet partial'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a field and response' do
|
44
|
+
let(:component_kwargs) do
|
45
|
+
{ display_facet_or_field_config: facet_config, response: response }
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:response) { instance_double(Blacklight::Solr::Response, aggregations: { 'field' => display_facet }) }
|
49
|
+
|
50
|
+
it 'extracts the facet data from the response to pass on to the rendering component' do
|
51
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
52
|
+
|
53
|
+
rendered
|
54
|
+
|
55
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the field is not in the response' do
|
59
|
+
let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'some_other_field', component: Blacklight::FacetFieldListComponent).normalize! }
|
60
|
+
|
61
|
+
it 'uses a null field to pass through the response information anyway' do
|
62
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
63
|
+
|
64
|
+
rendered
|
65
|
+
|
66
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: have_attributes(items: [], response: response)))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with a display facet and configuration' do
|
72
|
+
let(:component_kwargs) do
|
73
|
+
{ display_facet_or_field_config: display_facet, blacklight_config: blacklight_config }
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.facet_fields['field'] = facet_config } }
|
77
|
+
|
78
|
+
it 'pulls the facet config from the blacklight config' do
|
79
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
80
|
+
|
81
|
+
rendered
|
82
|
+
|
83
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with a presenter' do
|
88
|
+
let(:component_kwargs) do
|
89
|
+
{ display_facet_or_field_config: presenter }
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:presenter) { Blacklight::FacetFieldPresenter.new(facet_config, display_facet, controller.view_context) }
|
93
|
+
|
94
|
+
it 'renders the component with the provided presenter' do
|
95
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
96
|
+
|
97
|
+
rendered
|
98
|
+
|
99
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: presenter)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -6,6 +6,7 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
6
6
|
let(:config) do
|
7
7
|
Blacklight::Configuration.new do |config|
|
8
8
|
config.add_facet_field 'type'
|
9
|
+
config.add_search_field 'title'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -31,6 +32,21 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
describe '#render_constraints_clauses' do
|
36
|
+
subject { helper.render_constraints_clauses(params) }
|
37
|
+
|
38
|
+
let(:my_engine) { double("Engine") }
|
39
|
+
let(:params) { ActionController::Parameters.new(clause: { "0": { field: 'title', query: 'nature' } }, f: { type: 'journal' }) }
|
40
|
+
|
41
|
+
it 'renders the clause constraint' do
|
42
|
+
expect(subject).to have_selector '.constraint-value', text: /Title\s+nature/
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has a link relative to the current url" do
|
46
|
+
expect(subject).to have_link 'Remove constraint Title: nature', href: '/catalog?f%5Btype%5D%5B%5D=journal'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
34
50
|
describe '#render_filter_element' do
|
35
51
|
subject { helper.render_filter_element('type', ['journal'], path) }
|
36
52
|
|
data/spec/models/search_spec.rb
CHANGED
@@ -1,32 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Search do
|
4
|
+
let(:search) { described_class.new(user: user) }
|
4
5
|
let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345' }
|
6
|
+
let(:hash_params) { { q: "query", f: { facet: "filter" } } }
|
7
|
+
let(:query_params) { hash_params }
|
5
8
|
|
6
9
|
describe "query_params" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
shared_examples "persisting query_params" do
|
11
|
+
it "can save and retrieve the hash" do
|
12
|
+
search.query_params = query_params
|
13
|
+
search.save!
|
14
|
+
expect(described_class.find(search.id).query_params).to eq query_params.with_indifferent_access
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
context "are an indifferent hash" do
|
19
|
+
include_context "persisting query_params" do
|
20
|
+
let(:query_params) { hash_params.with_indifferent_access }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "are a string-keyed hash" do
|
25
|
+
include_context "persisting query_params" do
|
26
|
+
let(:query_params) { hash_params.with_indifferent_access.to_hash }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "include symbol keys" do
|
31
|
+
include_context "persisting query_params" do
|
32
|
+
let(:query_params) { hash_params }
|
33
|
+
end
|
16
34
|
end
|
17
35
|
end
|
18
36
|
|
19
37
|
describe "saved?" do
|
20
38
|
it "is true when user_id is not NULL and greater than 0" do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
expect(@search).to be_saved
|
39
|
+
search.save!
|
40
|
+
expect(search).to be_saved
|
25
41
|
end
|
26
42
|
|
27
|
-
|
28
|
-
|
29
|
-
|
43
|
+
context "when user_id is NULL or less than 1" do
|
44
|
+
let(:search) { described_class.create }
|
45
|
+
|
46
|
+
it "is false" do
|
47
|
+
expect(search).not_to be_saved
|
48
|
+
end
|
30
49
|
end
|
31
50
|
end
|
32
51
|
|
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: 7.
|
4
|
+
version: 7.28.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: 2022-
|
20
|
+
date: 2022-07-13 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -577,6 +577,7 @@ files:
|
|
577
577
|
- app/presenters/blacklight/thumbnail_presenter.rb
|
578
578
|
- app/services/blacklight/document_factory.rb
|
579
579
|
- app/services/blacklight/field_retriever.rb
|
580
|
+
- app/services/blacklight/search_params_yaml_coder.rb
|
580
581
|
- app/services/blacklight/search_service.rb
|
581
582
|
- app/values/blacklight/types.rb
|
582
583
|
- app/views/blacklight/nav/_bookmark.html.erb
|
@@ -780,6 +781,7 @@ files:
|
|
780
781
|
- spec/components/blacklight/document/group_component_spec.rb
|
781
782
|
- spec/components/blacklight/document_component_spec.rb
|
782
783
|
- spec/components/blacklight/document_metadata_component_spec.rb
|
784
|
+
- spec/components/blacklight/facet_component_spec.rb
|
783
785
|
- spec/components/blacklight/facet_field_checkboxes_component_spec.rb
|
784
786
|
- spec/components/blacklight/facet_field_list_component_spec.rb
|
785
787
|
- spec/components/blacklight/facet_item_component_spec.rb
|
@@ -960,6 +962,7 @@ test_files:
|
|
960
962
|
- spec/components/blacklight/document/group_component_spec.rb
|
961
963
|
- spec/components/blacklight/document_component_spec.rb
|
962
964
|
- spec/components/blacklight/document_metadata_component_spec.rb
|
965
|
+
- spec/components/blacklight/facet_component_spec.rb
|
963
966
|
- spec/components/blacklight/facet_field_checkboxes_component_spec.rb
|
964
967
|
- spec/components/blacklight/facet_field_list_component_spec.rb
|
965
968
|
- spec/components/blacklight/facet_item_component_spec.rb
|