blacklight_range_limit 7.5.0 → 7.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7193a46aebab2a5537bd404162533d288a54f1817122a2207aaad88265245136
4
- data.tar.gz: ca8afcd5b456dbb7a769a3169b405f63f37cd0003a41d905749072726a74110d
3
+ metadata.gz: 8e1997f0d260501d40769b046bfaa9a31492bb4398bbb144a37d2eb4cc9e6513
4
+ data.tar.gz: 46c9a11dbf347c2d9a5554f0d92e1b7e324bb6158acffe98908b8ecc4f519713
5
5
  SHA512:
6
- metadata.gz: 70f3f8ac356959bd04dadd3f998e5a5551dd3f2cbb4efb0f5e1ebc35783fb0a579739a4ffd4184188ebf2b195906443da54d828fc393ff8f01bbc16382aba5f8
7
- data.tar.gz: 9794d80970199368df6f9f6ce84544d6d88a392b8de7e59195e6402857d94462a82fe38cd46c88ee7a9b8bf0ae3abc208de4c6c26f0a8c033e6ebe1cfbbc9efb
6
+ metadata.gz: c9ff387fa687d752654314b976e82e2528c71403374febc52e38e07f22042514d0564ea08d46a4ec6e3f27dead5bf3db2a8942f529af1bd3fbc3a64b6a8516cb
7
+ data.tar.gz: b186d9febaad180fb2ac5347cd87ec098738a9e8a4a90c54c8305153edb3553bcfb0d83411c3a4f6303229d35efcada3e495f6ec8879da658d95246a762a8a31
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.5.0
1
+ 7.6.0
@@ -23,6 +23,8 @@ module BlacklightRangeLimit
23
23
  solr_params["stats.field"] ||= []
24
24
  solr_params["stats.field"] << config.field
25
25
 
26
+ range_config = BlacklightRangeLimit.range_config(blacklight_config, config.field)
27
+
26
28
  hash = blacklight_params["range"] && blacklight_params["range"][field_key] ?
27
29
  blacklight_params["range"][field_key] :
28
30
  {}
@@ -40,13 +42,13 @@ module BlacklightRangeLimit
40
42
  solr_params[:fq] ||= []
41
43
  solr_params[:fq] << "#{config.field}: [#{start} TO #{finish}]"
42
44
 
43
- if (config.segments != false && start != "*" && finish != "*")
45
+ if (range_config[:segments] != false && start != "*" && finish != "*")
44
46
  # Add in our calculated segments, can only do with both boundaries.
45
47
  add_range_segments_to_solr!(solr_params, field_key, start.to_i, finish.to_i)
46
48
  end
47
49
 
48
- elsif (config.segments != false &&
49
- boundaries = config.assumed_boundaries)
50
+ elsif (range_config[:segments] != false &&
51
+ boundaries = range_config[:assumed_boundaries])
50
52
  # assumed_boundaries in config
51
53
  add_range_segments_to_solr!(solr_params, field_key, boundaries[0], boundaries[1])
52
54
  end
@@ -15,6 +15,8 @@ module BlacklightRangeLimit
15
15
  raise InvalidRange, "The min date must be before the max date" if min > max
16
16
  field_config = blacklight_config.facet_fields[facet_field.to_s]
17
17
 
18
+ return solr_params unless field_config
19
+
18
20
  range_config = BlacklightRangeLimit.range_config(blacklight_config, facet_field)
19
21
 
20
22
  solr_params[:"facet.query"] ||= []
@@ -29,7 +31,7 @@ module BlacklightRangeLimit
29
31
  solr_params[:"facet.query"] << "#{field_config.field}:[#{first} TO #{last}]"
30
32
  end
31
33
 
32
- return solr_params
34
+ solr_params
33
35
  end
34
36
 
35
37
  # returns an array of 'boundaries' for producing approx num_div
@@ -29,39 +29,26 @@
29
29
  end
30
30
 
31
31
  def render_constraints_filters(my_params = params)
32
- content = super(my_params)
33
32
  # add a constraint for ranges?
34
- unless my_params[:range].blank?
35
- my_params[:range].each_pair do |solr_field, hash|
36
-
37
- next unless hash["missing"] || (!hash["begin"].blank?) || (!hash["end"].blank?)
38
- content << render_constraint_element(
39
- facet_field_label(solr_field),
40
- range_display(solr_field, my_params),
41
- :escape_value => false,
42
- :remove => remove_range_param(solr_field, my_params)
43
- )
44
- end
33
+ range_params(my_params).keys.each_with_object(super) do |solr_field, content|
34
+ content << render_constraint_element(
35
+ facet_field_label(solr_field),
36
+ range_display(solr_field, my_params),
37
+ escape_value: false,
38
+ remove: remove_range_param(solr_field, my_params)
39
+ )
45
40
  end
46
- return content
47
41
  end
48
42
 
49
43
  def render_search_to_s_filters(my_params)
50
- content = super(my_params)
51
44
  # add a constraint for ranges?
52
- unless my_params[:range].blank?
53
- my_params[:range].each_pair do |solr_field, hash|
54
- next unless hash["missing"] || (!hash["begin"].blank?) || (! hash["end"].blank?)
55
-
56
- content << render_search_to_s_element(
57
- facet_field_label(solr_field),
58
- range_display(solr_field, my_params),
59
- :escape_value => false
60
- )
61
-
62
- end
45
+ range_params(my_params).keys.each_with_object(super) do |solr_field, content|
46
+ content << render_search_to_s_element(
47
+ facet_field_label(solr_field),
48
+ range_display(solr_field, my_params),
49
+ escape_value: false
50
+ )
63
51
  end
64
- return content
65
52
  end
66
53
 
67
54
  def remove_range_param(solr_field, my_params = params)
@@ -97,4 +84,17 @@
97
84
  BlacklightRangeLimit.range_config(blacklight_config, solr_field)
98
85
  end
99
86
 
87
+ private
88
+
89
+ def range_params(my_params = params)
90
+ return {} unless my_params[:range].is_a?(ActionController::Parameters)
91
+
92
+ my_params[:range].select do |_solr_field, range_options|
93
+ next unless range_options
94
+
95
+ [range_options['missing'],
96
+ range_options['begin'],
97
+ range_options['end']].any?
98
+ end
99
+ end
100
100
  end
@@ -21,6 +21,25 @@ describe 'JavaScript', js: true do
21
21
  end
22
22
  end
23
23
 
24
+ context 'when assumed boundaries configured' do
25
+ before do
26
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range = {
27
+ assumed_boundaries: [1990, 2000]
28
+ }
29
+ end
30
+
31
+ after do
32
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range = true
33
+ end
34
+
35
+ it 'should show the range limit with set boundaries' do
36
+ visit '/catalog'
37
+ click_button 'Publication Date Sort'
38
+ expect(page).to have_field :range_pub_date_si_begin, with: '1990'
39
+ expect(page).to have_field :range_pub_date_si_end, with: '2000'
40
+ end
41
+ end
42
+
24
43
  describe '"Unknown" link' do
25
44
  context 'when in the facet (e.g. non-xhr)' do
26
45
  it 'is displayed' do
@@ -40,6 +40,10 @@ describe "Blacklight Range Limit" do
40
40
  I18n.backend.store_translations(:en, blacklight: {search: {fields: {facet: {pub_date_si: 'Publication Date I18n'}}}})
41
41
  end
42
42
 
43
+ after do
44
+ I18n.backend.store_translations(:en, blacklight: {search: {fields: {facet: {pub_date_si: 'Publication Date Sort'}}}})
45
+ end
46
+
43
47
  it 'should render the I18n label' do
44
48
  visit search_catalog_path
45
49
  click_link 'View distribution'
@@ -4,6 +4,10 @@ RSpec.describe BlacklightRangeLimit::SegmentCalculation do
4
4
  let(:dummy_class) do
5
5
  Class.new do
6
6
  include BlacklightRangeLimit::SegmentCalculation
7
+
8
+ def blacklight_config
9
+ Blacklight::Configuration.new
10
+ end
7
11
  end
8
12
  end
9
13
 
@@ -45,5 +49,15 @@ RSpec.describe BlacklightRangeLimit::SegmentCalculation do
45
49
  'The min date must be before the max date'
46
50
  end
47
51
  end
52
+
53
+ context 'when a field that does not exist is passed in' do
54
+ let(:min) { 100 }
55
+ let(:max) { 800 }
56
+ let(:solr_field) { 'i_am_not_real' }
57
+
58
+ it 'returns the original solr_params (and does not raise an error)' do
59
+ expect(subject).to eq({})
60
+ end
61
+ end
48
62
  end
49
63
  end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe BlacklightRangeLimit::ViewHelperOverride, type: :helper do
4
+ describe '#render_constraints_filters' do
5
+ before do
6
+ allow(helper).to receive_messages(
7
+ facet_field_label: 'Date Range',
8
+ remove_range_param: '/remove'
9
+ )
10
+ end
11
+
12
+ it 'does not return any content when the range parameter invalid' do
13
+ params = ActionController::Parameters.new(range: 'garbage')
14
+
15
+ expect(helper.render_constraints_filters(params)).to eq ''
16
+ end
17
+
18
+ it 'renders a constraint for the given data in the range param' do
19
+ params = ActionController::Parameters.new(
20
+ range: { range_field: { 'begin' => 1900, 'end' => 2000 } }
21
+ )
22
+ constraints = helper.render_constraints_filters(params)
23
+
24
+ expect(constraints).to have_css(
25
+ '.constraint .filter-name', text: 'Date Range'
26
+ )
27
+ expect(constraints).to have_css(
28
+ '.constraint .filter-value', text: '1900 to 2000'
29
+ )
30
+ end
31
+ end
32
+
33
+ describe 'render_search_to_s_filters' do
34
+ before do
35
+ allow(helper).to receive_messages(facet_field_label: 'Date Range')
36
+ end
37
+
38
+ it 'does not return any content when the range parameter invalid' do
39
+ params = ActionController::Parameters.new(range: 'garbage')
40
+
41
+ expect(helper.render_search_to_s_filters(params)).to eq ''
42
+ end
43
+
44
+ it 'renders a constraint for the given data in the range param' do
45
+ params = ActionController::Parameters.new(
46
+ range: { range_field: { 'begin' => 1900, 'end' => 2000 } }
47
+ )
48
+ constraints = helper.render_search_to_s_filters(params)
49
+
50
+ expect(constraints).to have_css(
51
+ '.constraint .filter-name', text: 'Date Range:'
52
+ )
53
+ expect(constraints).to have_css(
54
+ '.constraint .filter-values', text: '1900 to 2000'
55
+ )
56
+ end
57
+ end
58
+
59
+ describe '#range_params' do
60
+ it 'handles no range input' do
61
+ expect(
62
+ helper.send(:range_params, ActionController::Parameters.new(q: 'blah'))
63
+ ).to eq({})
64
+ end
65
+
66
+ it 'handles non-compliant range input' do
67
+ expect(
68
+ helper.send(:range_params, ActionController::Parameters.new(range: 'blah'))
69
+ ).to eq({})
70
+
71
+ expect(
72
+ helper.send(:range_params, ActionController::Parameters.new(range: ['blah']))
73
+ ).to eq({})
74
+
75
+ expect(
76
+ helper.send(:range_params, ActionController::Parameters.new(range: { 'wrong' => 'data' }))
77
+ ).to eq({})
78
+
79
+ expect(
80
+ helper.send(
81
+ :range_params,
82
+ ActionController::Parameters.new(range: { field_name: { 'wrong' => 'data' } })
83
+ )
84
+ ).to eq({})
85
+ end
86
+
87
+ it 'returns the range parameters that are present' do
88
+ expect(
89
+ helper.send(
90
+ :range_params,
91
+ ActionController::Parameters.new(range: { field_name: { 'missing' => true } })
92
+ ).permit!.to_h
93
+ ).to eq({ 'field_name' => { 'missing' => true } })
94
+
95
+ expect(
96
+ helper.send(
97
+ :range_params,
98
+ ActionController::Parameters.new(range: { field_name: { 'begin' => '1800', 'end' => '1900' } })
99
+ ).permit!.to_h
100
+ ).to eq({ 'field_name' => { 'begin' => '1800', 'end' => '1900' } })
101
+
102
+ expect(
103
+ helper.send(
104
+ :range_params,
105
+ ActionController::Parameters.new(
106
+ range: {
107
+ field_name: { 'begin' => '1800', 'end' => '1900' },
108
+ field_name2: { 'begin' => '1800', 'end' => '1900' }
109
+ }
110
+ )
111
+ ).permit!.to_h
112
+ ).to eq(
113
+ {
114
+ 'field_name' => { 'begin' => '1800', 'end' => '1900' },
115
+ 'field_name2' => { 'begin' => '1800', 'end' => '1900' }
116
+ }
117
+ )
118
+ end
119
+ end
120
+ end
@@ -30,4 +30,11 @@ class TestAppGenerator < Rails::Generators::Base
30
30
  "\n config.add_facet_field 'pub_date_si', label: 'Publication Date Sort', range: true"
31
31
  end
32
32
  end
33
+
34
+ def assets
35
+ return if !defined?(Sprockets::VERSION) || Sprockets::VERSION < '4'
36
+
37
+ append_to_file 'app/assets/config/manifest.js', "\n//= link application.js"
38
+ empty_directory 'app/assets/images'
39
+ end
33
40
  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: 7.5.0
4
+ version: 7.6.0
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: 2020-03-04 00:00:00.000000000 Z
12
+ date: 2020-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -222,6 +222,7 @@ files:
222
222
  - spec/fixtures/solr_documents/zero_year.yml
223
223
  - spec/helpers/blacklight_range_limit_helper_spec.rb
224
224
  - spec/lib/blacklight_range_limit/segment_calculation_spec.rb
225
+ - spec/lib/blacklight_range_limit/view_helper_override_helper_spec.rb
225
226
  - spec/spec_helper.rb
226
227
  - spec/test_app_templates/Gemfile.extra
227
228
  - spec/test_app_templates/lib/generators/test_app_generator.rb
@@ -266,6 +267,7 @@ test_files:
266
267
  - spec/fixtures/solr_documents/zero_year.yml
267
268
  - spec/helpers/blacklight_range_limit_helper_spec.rb
268
269
  - spec/lib/blacklight_range_limit/segment_calculation_spec.rb
270
+ - spec/lib/blacklight_range_limit/view_helper_override_helper_spec.rb
269
271
  - spec/spec_helper.rb
270
272
  - spec/test_app_templates/Gemfile.extra
271
273
  - spec/test_app_templates/lib/generators/test_app_generator.rb