blacklight_range_limit 8.2.2 → 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: 96efdd2c39ae998b673a2fb74ffbccad22029baf46d3e712550c84c726b93d82
4
- data.tar.gz: a27043d01e1b52f8d7a9a648e14aed7c71c6f42c0b94f7329f77a128d8867659
3
+ metadata.gz: 3ffae79e3156b14c7ad9b8c1c98bfb4862a9976996c9fafb9962d2f03d9688e4
4
+ data.tar.gz: 37bec61cbc86e6facaa7052e9a84a561664a0538fdfbd53c71960be16c35b5f3
5
5
  SHA512:
6
- metadata.gz: e933468fe64cbabfdc2a0d7e9dbdd9ff1980e8c7537538ae275b5f49b95759bab53f08980f4d6438aa9dfb667ed7ae119d748e1e57b6cd9b6b36029991f0e5e8
7
- data.tar.gz: adfc06b26edefc9f9389c4c111830905af993256877fbc58acd91784fcd09cecf815360172e30b71a8242ccf5a398fe86ced25c5ec05523acf9931437d80fd27
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.2
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
@@ -53,12 +53,12 @@ module BlacklightRangeLimit
53
53
  range = if params.dig(param_key, config.key).is_a? Range
54
54
  params.dig(param_key, config.key)
55
55
  elsif params.dig(param_key, config.key).is_a? Hash
56
- begins = Array(params.dig(param_key, config.key, :begin)).map(&:presence)
57
- ends = Array(params.dig(param_key, config.key, :end)).map(&:presence)
58
- begins.zip(ends).map { |b_bound, e_bound| Range.new(b_bound&.to_i, e_bound&.to_i) if b_bound && e_bound }.compact
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
59
59
  end
60
60
 
61
- f = except.include?(:filters) ? [] : Array(range)
61
+ f = except.include?(:filters) ? [] : [range].compact
62
62
 
63
63
  f_missing = [] if except.include?(:missing)
64
64
  f_missing ||= [Blacklight::SearchState::FilterField::MISSING] if params.dig(filters_key, "-#{key}")&.any? { |v| v == Blacklight::Engine.config.blacklight.facet_missing_param }
@@ -75,9 +75,8 @@ module BlacklightRangeLimit
75
75
  # this filter should allow (expect) hashes if the keys include 'begin' or 'end'
76
76
  def permitted_params
77
77
  {
78
- # { begin: [], end: [] } or [:begin, :end]
79
- filters_key => { config.key => { begin: [], end: [] }, "-#{config.key}" => [] },
80
- inclusive_filters_key => { config.key => { begin: [], end: [] } }
78
+ filters_key => { config.key => [:begin, :end], "-#{config.key}" => [] },
79
+ inclusive_filters_key => { config.key => [:begin, :end] }
81
80
  }
82
81
  end
83
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
@@ -55,6 +55,15 @@ RSpec.describe BlacklightRangeLimit::FilterField do
55
55
  expect(filter.include?(1234..2345)).to eq false
56
56
  end
57
57
  end
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
58
67
  end
59
68
 
60
69
  context 'with empty data' do
@@ -76,15 +85,4 @@ RSpec.describe BlacklightRangeLimit::FilterField do
76
85
  end
77
86
  end
78
87
  end
79
-
80
-
81
- context 'with array-mangled data' do
82
- let(:param_values) { { range: { some_field: { begin: { '0' => '2013' }, end: { '0' => '2022' } } } } }
83
-
84
- describe '#values' do
85
- it 'converts the parameters to a Range' do
86
- expect(filter.values).to eq [2013..2022]
87
- end
88
- end
89
- end
90
88
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_range_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.2
4
+ version: 8.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
8
8
  - Chris Beer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-06 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'
@@ -171,7 +171,7 @@ dependencies:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
- description:
174
+ description:
175
175
  email:
176
176
  - blacklight-development@googlegroups.com
177
177
  executables: []
@@ -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
@@ -276,7 +277,7 @@ homepage: https://github.com/projectblacklight/blacklight_range_limit
276
277
  licenses:
277
278
  - Apache 2.0
278
279
  metadata: {}
279
- post_install_message:
280
+ post_install_message:
280
281
  rdoc_options: []
281
282
  require_paths:
282
283
  - lib
@@ -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.2.32
295
- signing_key:
295
+ rubygems_version: 3.3.19
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