blacklight 6.4.0 → 6.4.1

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
  SHA1:
3
- metadata.gz: 08a32b124f67c2eee4651aa298a0c04c6cc1b0a3
4
- data.tar.gz: 99eb3c4e5a513755c0b44572d3f59e43ad46ae84
3
+ metadata.gz: 48b6e29df0426d17771b97c8cef4084c11e2398c
4
+ data.tar.gz: 6b1bd2738314e8b9966c31625455bd4cd6da99f5
5
5
  SHA512:
6
- metadata.gz: 36debbcf121bb69692fd23a4f3183fa11a463cf33d754e2dd25589ef3fed03b2d89ef8c12a695bbc6666f42ecb67b2d6cc00600fbec0eeb1e2d2bd12970c993c
7
- data.tar.gz: 4efcffee2bac9324aa344f2671a987e5628f1be7444c3517c4f8b63ea6917a7b8fee38dc796d616fb5a637dfca961382d89e6e0bca6512c49733f60a7c891874
6
+ metadata.gz: a930acfc5fb45d28e874e569f2efe499e4cdb46ee5bafa3370be6f9ec2c9840b52ac243a6844777418cd709b2337377543bf89dd74451b509bb5b4d90f1ee0b7
7
+ data.tar.gz: d2783d8e3661d95f9aa758b0b0ea6d3fbf3b80ac32320d53d8a37640d7b7dab5651f1251edd155eefa188084440d8ae73dc3ce4fb9e6c5866afbc02ee70f6e1d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.4.0
1
+ 6.4.1
@@ -1,7 +1,7 @@
1
1
  .twitter-typeahead {
2
2
  float: left;
3
3
  width: 100%;
4
- z-index: 10000;
4
+ z-index: 500;
5
5
 
6
6
  input.tt-input.form-control {
7
7
  width: 100%;
@@ -10,22 +10,25 @@ module Blacklight
10
10
  # @param [ActionController::Parameters] params
11
11
  # @param [Blacklight::Config] blacklight_config
12
12
  def initialize(params, blacklight_config)
13
- if params.instance_of? Hash
14
- # This is an ActionView::TestCase workaround. Will be resolved by
15
- # https://github.com/rails/rails/pull/22913 (Rails > 4.2.5)
16
- @params = params.with_indifferent_access
17
- else
13
+ if params.respond_to?(:to_unsafe_h)
18
14
  # This is the typical (not-ActionView::TestCase) code path.
19
15
  @params = params.to_unsafe_h
20
16
  # In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
21
17
  @params = @params.with_indifferent_access if @params.instance_of? Hash
18
+ elsif params.is_a? Hash
19
+ # This is an ActionView::TestCase workaround for Rails 4.2.
20
+ @params = params.dup.with_indifferent_access
21
+ else
22
+ @params = params.dup.to_h.with_indifferent_access
22
23
  end
24
+
23
25
  @blacklight_config = blacklight_config
24
26
  end
25
27
 
26
- def to_h
28
+ def to_hash
27
29
  @params
28
30
  end
31
+ alias to_h to_hash
29
32
 
30
33
  def reset
31
34
  Blacklight::SearchState.new(ActionController::Parameters.new, blacklight_config)
@@ -112,7 +115,7 @@ module Blacklight
112
115
  # @yield [params] The merged parameters hash before being sanitized
113
116
  def params_for_search(params_to_merge={}, &block)
114
117
  # params hash we'll return
115
- my_params = params.dup.merge(params_to_merge.dup)
118
+ my_params = params.dup.merge(Blacklight::SearchState.new(params_to_merge, blacklight_config))
116
119
 
117
120
  if block_given?
118
121
  yield my_params
@@ -9,27 +9,61 @@ describe Blacklight::SearchState do
9
9
  end
10
10
 
11
11
  let(:parameter_class) { ActionController::Parameters }
12
- let(:helper) { described_class.new(params, blacklight_config) }
12
+ let(:search_state) { described_class.new(params, blacklight_config) }
13
13
  let(:params) { parameter_class.new }
14
14
 
15
+ describe '#to_h' do
16
+ let(:data) { { a: '1'} }
17
+ let(:params) { parameter_class.new data }
18
+
19
+ it 'returns a copy of the original parameters' do
20
+ expect(search_state.to_h).to eq data.with_indifferent_access
21
+ expect(search_state.to_h.object_id).not_to eq params.object_id
22
+ end
23
+
24
+ context 'with AC::Parameters' do
25
+ let(:parameter_class) { ActionController::Parameters }
26
+
27
+ it 'returns the hash data' do
28
+ expect(search_state.to_h).to eq data.with_indifferent_access
29
+ end
30
+ end
31
+
32
+ context 'with HashWithIndifferentAccess' do
33
+ let(:parameter_class) { HashWithIndifferentAccess }
34
+
35
+ it 'returns the hash data' do
36
+ expect(search_state.to_h).to eq data.with_indifferent_access
37
+ end
38
+ end
39
+
40
+ context 'with Hash' do
41
+ let(:params) { data }
42
+
43
+ it 'returns the hash data' do
44
+ expect(search_state.to_h).to eq data.with_indifferent_access
45
+ end
46
+ end
47
+ end
48
+
15
49
  describe "params_for_search" do
16
50
  let(:params) { parameter_class.new 'default' => 'params' }
17
51
 
18
52
  it "takes original params" do
19
- result = helper.params_for_search
53
+ result = search_state.params_for_search
20
54
  expect(result).to eq({ 'default' => 'params' })
21
55
  expect(params.object_id).to_not eq result.object_id
22
56
  end
23
57
 
24
58
  it "accepts params to merge into the controller's params" do
25
- result = helper.params_for_search(q: 'query')
59
+ result = search_state.params_for_search(q: 'query')
26
60
  expect(result).to eq('q' => 'query', 'default' => 'params')
27
61
  end
28
62
 
29
63
  context "when params have blacklisted keys" do
30
64
  let(:params) { parameter_class.new action: 'action', controller: 'controller', id: "id", commit: 'commit' }
31
65
  it "removes them" do
32
- result = helper.params_for_search
66
+ result = search_state.params_for_search
33
67
  expect(result.keys).to_not include(:action, :controller, :commit, :id)
34
68
  end
35
69
  end
@@ -38,7 +72,7 @@ describe Blacklight::SearchState do
38
72
  context "and per_page changed" do
39
73
  let(:params) { parameter_class.new per_page: 20, page: 5 }
40
74
  it "adjusts the current page" do
41
- result = helper.params_for_search(per_page: 100)
75
+ result = search_state.params_for_search(per_page: 100)
42
76
  expect(result[:page]).to eq 1
43
77
  end
44
78
  end
@@ -46,7 +80,7 @@ describe Blacklight::SearchState do
46
80
  context "and per_page didn't change" do
47
81
  let(:params) { parameter_class.new per_page: 20, page: 5 }
48
82
  it "doesn't change the current page" do
49
- result = helper.params_for_search(per_page: 20)
83
+ result = search_state.params_for_search(per_page: 20)
50
84
  expect(result[:page]).to eq 5
51
85
  end
52
86
  end
@@ -54,7 +88,7 @@ describe Blacklight::SearchState do
54
88
  context "and the sort changes" do
55
89
  let(:params) { parameter_class.new sort: 'field_a', page: 5 }
56
90
  it "adjusts the current page" do
57
- result = helper.params_for_search(sort: 'field_b')
91
+ result = search_state.params_for_search(sort: 'field_b')
58
92
  expect(result[:page]).to eq 1
59
93
  end
60
94
  end
@@ -62,7 +96,7 @@ describe Blacklight::SearchState do
62
96
  context "and the sort didn't change" do
63
97
  let(:params) { parameter_class.new sort: 'field_a', page: 5 }
64
98
  it "doesn't change the current page" do
65
- result = helper.params_for_search(sort: 'field_a')
99
+ result = search_state.params_for_search(sort: 'field_a')
66
100
  expect(result[:page]).to eq 5
67
101
  end
68
102
  end
@@ -71,7 +105,7 @@ describe Blacklight::SearchState do
71
105
  context "with a block" do
72
106
  let(:params) { parameter_class.new a: 1, b: 2 }
73
107
  it "evalutes the block and allow it to add or remove keys" do
74
- result = helper.params_for_search(c: 3) do |params|
108
+ result = search_state.params_for_search(c: 3) do |params|
75
109
  params.extract! :a, :b
76
110
  params[:d] = 'd'
77
111
  end
@@ -100,14 +134,14 @@ describe Blacklight::SearchState do
100
134
  context "when there are no pre-existing facets" do
101
135
  let(:params) { params_no_existing_facet }
102
136
  it "adds facet value" do
103
- result_params = helper.add_facet_params("facet_field", "facet_value")
137
+ result_params = search_state.add_facet_params("facet_field", "facet_value")
104
138
  expect(result_params[:f]).to be_a Hash
105
139
  expect(result_params[:f]["facet_field"]).to be_a_kind_of(Array)
106
140
  expect(result_params[:f]["facet_field"]).to eq ["facet_value"]
107
141
  end
108
142
 
109
143
  it "leaves non-facet params alone" do
110
- result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
144
+ result_params = search_state.add_facet_params("facet_field_2", "new_facet_value")
111
145
 
112
146
  params.each_pair do |key, value|
113
147
  next if key == :f
@@ -116,9 +150,9 @@ describe Blacklight::SearchState do
116
150
  end
117
151
 
118
152
  it "uses the facet's key in the url" do
119
- allow(helper).to receive(:facet_configuration_for_field).with('some_field').and_return(double(single: true, field: "a_solr_field", key: "some_key"))
153
+ allow(search_state).to receive(:facet_configuration_for_field).with('some_field').and_return(double(single: true, field: "a_solr_field", key: "some_key"))
120
154
 
121
- result_params = helper.add_facet_params('some_field', 'my_value')
155
+ result_params = search_state.add_facet_params('some_field', 'my_value')
122
156
 
123
157
  expect(result_params[:f]['some_key']).to have(1).item
124
158
  expect(result_params[:f]['some_key'].first).to eq 'my_value'
@@ -128,7 +162,7 @@ describe Blacklight::SearchState do
128
162
  context "when there are pre-existing facets" do
129
163
  let(:params) { params_existing_facets }
130
164
  it "adds a facet param to existing facet constraints" do
131
- result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
165
+ result_params = search_state.add_facet_params("facet_field_2", "new_facet_value")
132
166
 
133
167
  expect(result_params[:f]).to be_a Hash
134
168
 
@@ -143,7 +177,7 @@ describe Blacklight::SearchState do
143
177
  end
144
178
 
145
179
  it "leaves non-facet params alone" do
146
- result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
180
+ result_params = search_state.add_facet_params("facet_field_2", "new_facet_value")
147
181
 
148
182
  params.each_pair do |key, value|
149
183
  next if key == 'f'
@@ -155,8 +189,8 @@ describe Blacklight::SearchState do
155
189
  context "with a facet selected in the params" do
156
190
  let(:params) { parameter_class.new f: { 'single_value_facet_field' => 'other_value' } }
157
191
  it "replaces facets configured as single" do
158
- allow(helper).to receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(single: true, key: "single_value_facet_field"))
159
- result_params = helper.add_facet_params('single_value_facet_field', 'my_value')
192
+ allow(search_state).to receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(single: true, key: "single_value_facet_field"))
193
+ result_params = search_state.add_facet_params('single_value_facet_field', 'my_value')
160
194
 
161
195
  expect(result_params[:f]['single_value_facet_field']).to have(1).item
162
196
  expect(result_params[:f]['single_value_facet_field'].first).to eq 'my_value'
@@ -164,20 +198,20 @@ describe Blacklight::SearchState do
164
198
  end
165
199
 
166
200
  it "accepts a FacetItem instead of a plain facet value" do
167
- result_params = helper.add_facet_params('facet_field_1', double(value: 123))
201
+ result_params = search_state.add_facet_params('facet_field_1', double(value: 123))
168
202
 
169
203
  expect(result_params[:f]['facet_field_1']).to include(123)
170
204
  end
171
205
 
172
206
  it "defers to the field set on a FacetItem" do
173
- result_params = helper.add_facet_params('facet_field_1', double(:field => 'facet_field_2', :value => 123))
207
+ result_params = search_state.add_facet_params('facet_field_1', double(:field => 'facet_field_2', :value => 123))
174
208
 
175
209
  expect(result_params[:f]['facet_field_1']).to be_blank
176
210
  expect(result_params[:f]['facet_field_2']).to include(123)
177
211
  end
178
212
 
179
213
  it "adds any extra fq parameters from the FacetItem" do
180
- result_params = helper.add_facet_params('facet_field_1', double(:value => 123, fq: { 'facet_field_2' => 'abc' }))
214
+ result_params = search_state.add_facet_params('facet_field_1', double(:value => 123, fq: { 'facet_field_2' => 'abc' }))
181
215
 
182
216
  expect(result_params[:f]['facet_field_1']).to include(123)
183
217
  expect(result_params[:f]['facet_field_2']).to include('abc')
@@ -197,7 +231,7 @@ describe Blacklight::SearchState do
197
231
  }
198
232
 
199
233
  it "does not include request parameters used by the facet paginator" do
200
- params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
234
+ params = search_state.add_facet_params_and_redirect("facet_field_2", "facet_value")
201
235
 
202
236
  bad_keys = Blacklight::Solr::FacetPaginator.request_keys.values + [:id]
203
237
  bad_keys.each do |paginator_key|
@@ -206,13 +240,13 @@ describe Blacklight::SearchState do
206
240
  end
207
241
 
208
242
  it 'removes :page request key' do
209
- params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
243
+ params = search_state.add_facet_params_and_redirect("facet_field_2", "facet_value")
210
244
  expect(params).to_not have_key(:page)
211
245
  end
212
246
 
213
247
  it "otherwise does the same thing as add_facet_params" do
214
- added_facet_params = helper.add_facet_params("facet_field_2", "facet_value")
215
- added_facet_params_from_facet_action = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
248
+ added_facet_params = search_state.add_facet_params("facet_field_2", "facet_value")
249
+ added_facet_params_from_facet_action = search_state.add_facet_params_and_redirect("facet_field_2", "facet_value")
216
250
 
217
251
  expect(added_facet_params_from_facet_action).to eq added_facet_params.except(Blacklight::Solr::FacetPaginator.request_keys[:page], Blacklight::Solr::FacetPaginator.request_keys[:sort])
218
252
  end
@@ -225,7 +259,7 @@ describe Blacklight::SearchState do
225
259
  let(:facet_params) { { 'some_field' => ['some_value', 'another_value'] } }
226
260
 
227
261
  it "removes the facet / value tuple from the query parameters" do
228
- params = helper.remove_facet_params('some_field', 'some_value')
262
+ params = search_state.remove_facet_params('some_field', 'some_value')
229
263
  expect(params[:f]['some_field']).not_to include 'some_value'
230
264
  expect(params[:f]['some_field']).to include 'another_value'
231
265
  end
@@ -233,13 +267,13 @@ describe Blacklight::SearchState do
233
267
 
234
268
  context "when the facet has configuration" do
235
269
  before do
236
- allow(helper).to receive(:facet_configuration_for_field).with('some_field').and_return(
270
+ allow(search_state).to receive(:facet_configuration_for_field).with('some_field').and_return(
237
271
  double(single: true, field: "a_solr_field", key: "some_key"))
238
272
  end
239
273
  let(:facet_params) { { 'some_key' => ['some_value', 'another_value'] } }
240
274
 
241
275
  it "uses the facet's key configuration" do
242
- params = helper.remove_facet_params('some_field', 'some_value')
276
+ params = search_state.remove_facet_params('some_field', 'some_value')
243
277
  expect(params[:f]['some_key']).not_to eq 'some_value'
244
278
  expect(params[:f]['some_key']).to include 'another_value'
245
279
  end
@@ -249,7 +283,7 @@ describe Blacklight::SearchState do
249
283
  facet_params['another_field'] = ['some_value']
250
284
  facet_params['some_field'] = ['some_value']
251
285
 
252
- params = helper.remove_facet_params('some_field', 'some_value')
286
+ params = search_state.remove_facet_params('some_field', 'some_value')
253
287
 
254
288
  expect(params[:f]).not_to have_key 'some_field'
255
289
  end
@@ -257,7 +291,7 @@ describe Blacklight::SearchState do
257
291
  it "removes the 'f' parameter entirely when no facets remain" do
258
292
  facet_params['some_field'] = ['some_value']
259
293
 
260
- params = helper.remove_facet_params('some_field', 'some_value')
294
+ params = search_state.remove_facet_params('some_field', 'some_value')
261
295
 
262
296
  expect(params).not_to have_key :f
263
297
  end
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.4.0
4
+ version: 6.4.1
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: 2016-07-28 00:00:00.000000000 Z
20
+ date: 2016-08-09 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -688,7 +688,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
688
688
  version: '0'
689
689
  requirements: []
690
690
  rubyforge_project:
691
- rubygems_version: 2.6.4
691
+ rubygems_version: 2.5.1
692
692
  signing_key:
693
693
  specification_version: 4
694
694
  summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)