blacklight_range_limit 8.2.0 → 8.2.3

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
  SHA256:
3
- metadata.gz: '00179d23555229bb58884ff2625e599307bbda4404fe0ebab00fa460a95b0e58'
4
- data.tar.gz: 742c87c6be6c52491abda708761027e68986bb0cf7ae1c95cff2605f779e5fd0
3
+ metadata.gz: 3ffae79e3156b14c7ad9b8c1c98bfb4862a9976996c9fafb9962d2f03d9688e4
4
+ data.tar.gz: 37bec61cbc86e6facaa7052e9a84a561664a0538fdfbd53c71960be16c35b5f3
5
5
  SHA512:
6
- metadata.gz: 668f99b158ff431e50e484d851f59d24aa55580699b7e1e2338d326d9346b59a29ac4d9031cf8d61d5e28a4aa0629b6776c6da40f553791a13cf165eb03afbc7
7
- data.tar.gz: ed441dacce85f39b0b7ecffecf0afdd14d1174eb8f5d5ab1e7a3832002e5bd3c46d9753779b0b1119e79d916633590f9228672694e1a821c0409cb35de699983
6
+ metadata.gz: d3e17cf2f4a0a4851f585c2309a5f2c4dde6ff1ab24c0f168b17fd56e7fe3c416facede0bb6c9fa7e4a9e60842f0fa04b7c2d3f525e035d4374879dada9988a9
7
+ data.tar.gz: 5d8b218cb0063215f452f1debc5b7ba5e04530fb3fc16b7eae90ca670dd45684a223bf49261d8fbd2b4cb36a7807125141365a86aa89618891558a38a13e73e3
@@ -9,9 +9,9 @@ name: CI
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ master ]
12
+ branches: [ main ]
13
13
  pull_request:
14
- branches: [ master ]
14
+ branches: [ main ]
15
15
 
16
16
  jobs:
17
17
  test:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.2.0
1
+ 8.2.3
@@ -1,12 +1,12 @@
1
1
  <%= form_tag search_action_path, method: :get, class: [@classes[:form], "range_#{@facet_field.key} d-flex justify-content-center"].join(' ') do %>
2
- <%= render Blacklight::HiddenSearchStateComponent.new(params: @facet_field.search_state.params_for_search.except(:utf8, :page)) %>
2
+ <%= render hidden_search_state %>
3
3
 
4
4
  <div class="input-group input-group-sm mb-3 flex-nowrap range-limit-input-group">
5
5
  <%= render_range_input(:begin, begin_label) %>
6
6
  <%= render_range_input(:end, end_label) %>
7
7
  <div class="input-group-append visually-hidden">
8
- <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit] %>
8
+ <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit], name: nil %>
9
9
  </div>
10
- <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit] + " sr-only", "aria-hidden": "true" %>
10
+ <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit] + " sr-only", "aria-hidden": "true", name: nil %>
11
11
  </div>
12
12
  <% end %>
@@ -39,6 +39,17 @@ module BlacklightRangeLimit
39
39
 
40
40
  private
41
41
 
42
+ ##
43
+ # the form needs to serialize any search parameters, including other potential range filters,
44
+ # as hidden fields. The parameters for this component's range filter are serialized as number
45
+ # inputs, and should not be in the hidden params.
46
+ # @return [Blacklight::HiddenSearchStateComponent]
47
+ def hidden_search_state
48
+ hidden_search_params = @facet_field.search_state.params_for_search.except(:utf8, :page)
49
+ hidden_search_params[:range]&.except!(@facet_field.key)
50
+ Blacklight::HiddenSearchStateComponent.new(params: hidden_search_params)
51
+ end
52
+
42
53
  def range_config
43
54
  @facet_field.range_config
44
55
  end
@@ -50,17 +50,16 @@ module BlacklightRangeLimit
50
50
  def values(except: [])
51
51
  params = search_state.params
52
52
  param_key = filters_key
53
- return [] unless params.dig(param_key, config.key)
54
-
55
53
  range = if params.dig(param_key, config.key).is_a? Range
56
54
  params.dig(param_key, config.key)
57
- else
58
- begins = Array(params.dig(param_key, config.key, :begin)).map(&:to_i)
59
- ends = Array(params.dig(param_key, config.key, :end)).map(&:to_i)
60
- begins.zip(ends).map { |b_bound, e_bound| Range.new(b_bound, e_bound) }
55
+ elsif params.dig(param_key, config.key).is_a? Hash
56
+ b_bound = params.dig(param_key, config.key, :begin).presence
57
+ e_bound = params.dig(param_key, config.key, :end).presence
58
+ Range.new(b_bound&.to_i, e_bound&.to_i) if b_bound && e_bound
61
59
  end
62
60
 
63
- f = except.include?(:filters) ? [] : Array(range)
61
+ f = except.include?(:filters) ? [] : [range].compact
62
+
64
63
  f_missing = [] if except.include?(:missing)
65
64
  f_missing ||= [Blacklight::SearchState::FilterField::MISSING] if params.dig(filters_key, "-#{key}")&.any? { |v| v == Blacklight::Engine.config.blacklight.facet_missing_param }
66
65
 
@@ -76,9 +75,8 @@ module BlacklightRangeLimit
76
75
  # this filter should allow (expect) hashes if the keys include 'begin' or 'end'
77
76
  def permitted_params
78
77
  {
79
- # { begin: [], end: [] } or [:begin, :end]
80
- filters_key => { config.key => { begin: [], end: [] }, "-#{config.key}" => [] },
81
- inclusive_filters_key => { config.key => { begin: [], end: [] } }
78
+ filters_key => { config.key => [:begin, :end], "-#{config.key}" => [] },
79
+ inclusive_filters_key => { config.key => [:begin, :end] }
82
80
  }
83
81
  end
84
82
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.license = 'Apache 2.0'
19
19
 
20
- s.add_dependency 'blacklight', '>= 7.22.2', '< 9'
20
+ s.add_dependency 'blacklight', '>= 7.25.2', '< 9'
21
21
 
22
22
  s.add_development_dependency 'rspec', '~> 3.0'
23
23
  s.add_development_dependency 'rspec-rails'
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe BlacklightRangeLimit::RangeFormComponent, type: :component do
6
+ subject(:component) do
7
+ described_class.new(facet_field: facet_field)
8
+ end
9
+
10
+ let(:rendered) do
11
+ Capybara::Node::Simple.new(render_inline(component))
12
+ end
13
+
14
+ let(:facet_field_params) { {} }
15
+ let(:selected_range) { nil }
16
+ let(:search_params) { { another_field: 'another_value' } }
17
+
18
+ let(:facet_field) do
19
+ instance_double(
20
+ BlacklightRangeLimit::FacetFieldPresenter,
21
+ key: 'key',
22
+ html_id: 'id',
23
+ active?: false,
24
+ collapsed?: false,
25
+ in_modal?: false,
26
+ label: 'My facet field',
27
+ selected_range: selected_range,
28
+ selected_range_facet_item: nil,
29
+ missing_facet_item: nil,
30
+ missing_selected?: false,
31
+ min: nil,
32
+ max: nil,
33
+ search_state: Blacklight::SearchState.new(search_params, nil),
34
+ range_config: {},
35
+ modal_path: nil,
36
+ facet_field: facet_config,
37
+ **facet_field_params
38
+ )
39
+ end
40
+
41
+ let(:facet_config) do
42
+ Blacklight::Configuration::FacetField.new(key: 'key', item_presenter: BlacklightRangeLimit::FacetItemPresenter)
43
+ end
44
+
45
+ it 'renders a form with no selected range' do
46
+ expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
47
+ .and have_field('range[key][begin]', type: 'number')
48
+ .and have_field('range[key][end]', type: 'number')
49
+ .and have_field('another_field', type: 'hidden', with: 'another_value', visible: false)
50
+ expect(rendered.find_field('range[key][begin]', type: 'number').value).to be_blank
51
+ expect(rendered.find_field('range[key][end]', type: 'number').value).to be_blank
52
+ expect(rendered).not_to have_field('range[key][begin]', type: 'hidden')
53
+ end
54
+
55
+ it 'renders submit controls without a name to suppress from formData' do
56
+ anon_submit = rendered.find('input', visible: true) { |ele| ele[:type] == 'submit' && !ele[:'aria-hidden'] && !ele[:name] }
57
+ expect(anon_submit).to be_present
58
+ expect { rendered.find('input') { |ele| ele[:type] == 'submit' && ele[:name] } }.to raise_error(Capybara::ElementNotFound)
59
+ end
60
+
61
+ context 'with range data' do
62
+ let(:selected_range) { (100..300) }
63
+ let(:search_params) do
64
+ {
65
+ another_field: 'another_value',
66
+ range: {
67
+ another_range: { begin: 128, end: 1024 },
68
+ key: { begin: selected_range.first, end: selected_range.last }
69
+ }
70
+ }
71
+ end
72
+
73
+ it 'renders a form for the selected range' do
74
+ expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
75
+ .and have_field('range[key][begin]', type: 'number', with: selected_range.first)
76
+ .and have_field('range[key][end]', type: 'number', with: selected_range.last)
77
+ .and have_field('another_field', type: 'hidden', with: 'another_value', visible: false)
78
+ .and have_field('range[another_range][begin]', type: 'hidden', with: 128, visible: false)
79
+ .and have_field('range[another_range][end]', type: 'hidden', with: 1024, visible: false)
80
+ expect(rendered).not_to have_field('range[key][begin]', type: 'hidden')
81
+ end
82
+ end
83
+ end
@@ -42,6 +42,7 @@ describe "Blacklight Range Limit" do
42
42
  click_link '2000 to 2008'
43
43
  click_button 'Apply', match: :first
44
44
  expect(page.current_url).not_to include('page')
45
+ expect(page.current_url).not_to include('commit')
45
46
  end
46
47
 
47
48
  context 'when I18n translation is available' do
@@ -56,14 +56,32 @@ RSpec.describe BlacklightRangeLimit::FilterField do
56
56
  end
57
57
  end
58
58
 
59
+ describe '#permitted_params' do
60
+ let(:rails_params) { ActionController::Parameters.new(param_values) }
61
+ let(:blacklight_params) { Blacklight::Parameters.new(rails_params, search_state) }
62
+ let(:permitted_params) { blacklight_params.permit_search_params.to_h }
63
+ it 'sanitizes single begin/end values as scalars' do
64
+ expect(permitted_params.dig(:range, 'some_field')).to include 'begin' => '2013', 'end' => '2022'
65
+ end
66
+ end
59
67
  end
60
68
 
61
- context 'with array-mangled data' do
62
- let(:param_values) { { range: { some_field: { begin: { '0' => '2013' }, end: { '0' => '2022' } } } } }
69
+ context 'with empty data' do
70
+ let(:param_values) { { range: { some_field: { begin: '', end: '' } } } }
63
71
 
64
72
  describe '#values' do
65
- it 'converts the parameters to a Range' do
66
- expect(filter.values).to eq [2013..2022]
73
+ it 'drops the empty range' do
74
+ expect(filter.values).to be_empty
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'with missing data' do
80
+ let(:param_values) { { range: { '-some_field': ['[* TO *]']} } }
81
+
82
+ describe '#values' do
83
+ it 'uses the missing special value' do
84
+ expect(filter.values).to eq [Blacklight::SearchState::FilterField::MISSING]
67
85
  end
68
86
  end
69
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_range_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.0
4
+ version: 8.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-07 00:00:00.000000000 Z
12
+ date: 2022-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -17,7 +17,7 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 7.22.2
20
+ version: 7.25.2
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
23
  version: '9'
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 7.22.2
30
+ version: 7.25.2
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '9'
@@ -247,6 +247,7 @@ files:
247
247
  - solr/conf/xslt/luke.xsl
248
248
  - solr/sample_solr_documents.yml
249
249
  - spec/components/range_facet_component_spec.rb
250
+ - spec/components/range_form_component_spec.rb
250
251
  - spec/features/a_javascript_spec.rb
251
252
  - spec/features/blacklight_range_limit_spec.rb
252
253
  - spec/fixtures/solr_documents/unknown_year.yml
@@ -291,12 +292,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
292
  - !ruby/object:Gem::Version
292
293
  version: '0'
293
294
  requirements: []
294
- rubygems_version: 3.1.2
295
+ rubygems_version: 3.3.19
295
296
  signing_key:
296
297
  specification_version: 4
297
298
  summary: Blacklight Range Limit plugin
298
299
  test_files:
299
300
  - spec/components/range_facet_component_spec.rb
301
+ - spec/components/range_form_component_spec.rb
300
302
  - spec/features/a_javascript_spec.rb
301
303
  - spec/features/blacklight_range_limit_spec.rb
302
304
  - spec/fixtures/solr_documents/unknown_year.yml