ansr_blacklight 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ansr::Blacklight::Relation do
4
+
5
+ class ConfiguredTable < Ansr::Arel::BigTable
6
+
7
+ end
8
+
9
+ class OtherTable < ConfiguredTable
10
+ def name
11
+ 'outside'
12
+ end
13
+
14
+ end
15
+
16
+ context "a bunch of query stuff" do
17
+
18
+ before(:each) do
19
+ Object.const_set('QueryTestModel', Class.new(TestModel))
20
+ QueryTestModel.configure do |config|
21
+ config[:table_class] = ConfiguredTable
22
+ end
23
+ QueryTestModel.solr = stub_solr
24
+ other_table.configure_fields do |config|
25
+ hash = (config[:configured] ||= {})
26
+ hash[:local] = {:property => 'test', :escape => 'tes"t'}
27
+ end
28
+ @visitor = Ansr::Blacklight::Arel::Visitors::ToNoSql.new(QueryTestModel.table)
29
+
30
+ ## COMMON AREL CONCEPTS ##
31
+ # from() indicates the big table name for the relation; in BL/Solr this maps to the request path
32
+ @relation = QueryTestModel.from(ConfiguredTable.new(QueryTestModel))
33
+ # as() indicates an alias for the big table; in BL/Solr this maps to the :qt param
34
+ @relation.as!('hey')
35
+ # constraints map directly
36
+ @relation.where!(:configured=> "what's")
37
+
38
+ # as do offsets and limits
39
+ @relation.offset!(21)
40
+ @relation.limit!(12)
41
+ @relation.group!("I")
42
+ ## COMMON NO-SQL CONCEPTS ##
43
+ # facets are a kind of projection with attributes (attribute support is optional)
44
+ @relation.facet!("title_facet", limit: "vest")
45
+ # filters are a type of constraint
46
+ @relation.filter!({"name_facet" => "Fedo"})
47
+ @relation.facet!("name_facet", limit: 10)
48
+ @relation.facet!(limit: 20)
49
+ @relation.highlight!("I", 'fl' => "wish")
50
+ @relation.spellcheck!("a", q: "fleece")
51
+ ## SOLR ECCENTRICITIES ##
52
+ # these are present for compatibility, but not expected to be used generically
53
+ @relation.wt!("going")
54
+ @relation.defType!("had")
55
+ end
56
+
57
+ after(:each) do
58
+ @relation = nil
59
+ Object.send(:remove_const, :QueryTestModel)
60
+ end
61
+
62
+ let(:table) { QueryTestModel.table }
63
+ let(:other_table) { OtherTable.new(QueryTestModel) }
64
+ describe "#from" do
65
+
66
+ let(:visitor) { @visitor }
67
+ subject {@relation.from(other_table)}
68
+
69
+ it "should set the path to the table name" do
70
+ query = visitor.accept subject.build_arel.ast
71
+ expect(query.path).to eql('outside')
72
+ end
73
+
74
+ it "should change the table" do
75
+ expect(subject.from_value.first).to be_a ConfiguredTable
76
+ end
77
+ end
78
+
79
+ describe "#as" do
80
+
81
+ subject {@relation.as('hey')}
82
+ let(:visitor) { @visitor }
83
+
84
+ it "should set the :qt parameter" do
85
+ query = visitor.accept subject.build_arel.ast
86
+ expect(query.to_hash[:qt]).to eql 'hey'
87
+ end
88
+ end
89
+
90
+ describe "#facet" do
91
+
92
+ subject { @relation.facet(limit: 20)}
93
+ let(:visitor) { @visitor }
94
+
95
+ it "should set default facet parms when no field expr is given" do
96
+ rel = subject.facet(limit: 20)
97
+ query = visitor.accept rel.build_arel.ast
98
+ end
99
+
100
+ it "should set facet field params" do
101
+ end
102
+ end
103
+
104
+ context "a mix of queryable relations" do
105
+ subject { @relation.from(other_table) }
106
+ let(:visitor) { @visitor }
107
+
108
+ it "should accept valid parameters" do
109
+ config = Blacklight::Configuration.new
110
+ query = visitor.accept subject.build_arel.ast
111
+ expect(query.path).to eq('outside')
112
+ expect(query.to_hash).to eq({"defType" => "had",
113
+ "f.name_facet.facet.limit" => "10",
114
+ "f.title_facet.facet.limit" => "vest",
115
+ "facet" => true,
116
+ "facet.field" => [:title_facet,:name_facet],
117
+ "facet.limit" => "20",
118
+ "fq" => ["{!raw f=name_facet}Fedo"],
119
+ "group" => "I",
120
+ "hl" => "I",
121
+ "hl.fl" => "wish",
122
+ "q" => "{!property=test escape='tes\\\"t'}what's",
123
+ "qt" => "hey",
124
+ "rows" => "13",
125
+ "spellcheck" => "a",
126
+ "spellcheck.q" => "fleece",
127
+ "start" => "21",
128
+ "wt" => "going"
129
+ })
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,475 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ # check the methods that do solr requests. Note that we are not testing if
5
+ # solr gives "correct" responses, as that's out of scope (it's a part of
6
+ # testing the solr code itself). We *are* testing if blacklight code sends
7
+ # queries to solr such that it gets appropriate results. When a user does a search,
8
+ # do we get data back from solr (i.e. did we properly configure blacklight code
9
+ # to talk with solr and get results)? when we do a document request, does
10
+ # blacklight code get a single document returned?)
11
+ #
12
+ describe Ansr::Blacklight do
13
+
14
+ class TestTable < Ansr::Arel::BigTable
15
+ def name
16
+ 'outside'
17
+ end
18
+
19
+ def [](val)
20
+ key = (Arel::Attributes::Attribute === val) ? val.name.to_sym : val.to_sym
21
+ key == :configured ? Ansr::Arel::ConfiguredField.new(key, {:property => 'test', :escape => 'tes"t'}) : super(val)
22
+ end
23
+
24
+ def fields
25
+ [:id]
26
+ end
27
+
28
+ end
29
+
30
+ before do
31
+ Object.const_set('FacetModel', Class.new(TestModel))
32
+ FacetModel.solr = stub_solr
33
+ FacetModel.configure do |config|
34
+ config[:table_class] = TestTable
35
+ end
36
+ end
37
+
38
+ after do
39
+ Object.send(:remove_const, :FacetModel)
40
+ end
41
+
42
+ subject {
43
+ Ansr::Blacklight::Arel::Visitors::ToNoSql.new(TestTable.new(FacetModel)).query_builder
44
+ }
45
+
46
+ let(:blacklight_solr) { subject.solr }
47
+ let(:copy_of_catalog_config) { ::CatalogController.blacklight_config.deep_copy }
48
+ let(:blacklight_config) { copy_of_catalog_config }
49
+
50
+ before(:each) do
51
+ @all_docs_query = ''
52
+ @no_docs_query = 'zzzzzzzzzzzz'
53
+ @single_word_query = 'include'
54
+ @mult_word_query = 'tibetan history'
55
+ # f[format][]=Book&f[language_facet][]=English
56
+ @single_facet = {:format=>'Book'}
57
+ @multi_facets = {:format=>'Book', :language_facet=>'Tibetan'}
58
+ @bad_facet = {:format=>'666'}
59
+ @subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
60
+ @abc_resp = {'response' =>{ 'docs' => [id: 'abc']}}.to_json
61
+ @no_docs_resp = {'response' =>{'docs' => []}}.to_json
62
+ end
63
+
64
+ def subject_search_params(rel)
65
+ rel.limit(10).where!(q: 'wome')
66
+ end
67
+
68
+ describe "http_method configuration", :integration => true do
69
+ subject { FacetModel }
70
+
71
+ it "should send a post request to solr and get a response back" do
72
+ rel = subject.where(:q => @all_docs_query)
73
+ subject.solr= stub_solr(JSON.parse(@abc_resp).inspect)
74
+ expect(rel.length).to be >= 1
75
+ end
76
+ end
77
+
78
+ # SPECS for actual search parameter generation
79
+ describe "solr_search_params" do
80
+
81
+ subject { FacetModel }
82
+
83
+ it "allows customization of solr_search_params_logic" do
84
+ # Normally you'd include a new module into (eg) your CatalogController
85
+ # but a sub-class defininig it directly is simpler for test.
86
+ subject.stub(:add_foo_to_solr_params) do |rel|
87
+ rel.wt!("TESTING")
88
+ end
89
+
90
+ subject.solr_search_params_logic += [:add_foo_to_solr_params]
91
+
92
+ expect(subject.build_default_scope.wt_value).to eql("TESTING")
93
+ end
94
+
95
+ describe "for an empty string search" do
96
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(FacetModel.table) }
97
+ it "should return empty string q in solr parameters" do
98
+ rel = TestModel.where(q: "")
99
+ solr_params = subject.accept(rel.build_arel.ast)
100
+ expect(solr_params[:q]).to eq ""
101
+ expect(solr_params["spellcheck.q"]).to eq ""
102
+ end
103
+ end
104
+
105
+ describe "for request params also passed in as argument" do
106
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(FacetModel.table) }
107
+ it "should only have one value for the key 'q' regardless if a symbol or string" do
108
+ rel = FacetModel.where(q: "some query").where('q' => 'another value')
109
+ solr_params = subject.accept(rel.build_arel.ast)
110
+ expect(solr_params[:q]).to eq 'another value'
111
+ expect(solr_params['q']).to eq 'another value'
112
+ end
113
+ end
114
+
115
+
116
+ describe "for one facet, no query" do
117
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(FacetModel.table) }
118
+ it "should have proper solr parameters" do
119
+ rel = FacetModel.filter(@single_facet)
120
+ solr_params = subject.accept(rel.build_arel.ast)
121
+
122
+ expect(solr_params[:q]).to be_blank
123
+ expect(solr_params["spellcheck.q"]).to be_blank
124
+
125
+ @single_facet.each_value do |value|
126
+ expect(solr_params[:fq]).to include("{!raw f=#{@single_facet.keys[0]}}#{value}")
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "with Multi Facets, No Query" do
132
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(FacetModel.table) }
133
+ it 'should have fq set properly' do
134
+ rel = FacetModel.filter(@multi_facets)
135
+ solr_params = subject.accept(rel.build_arel.ast)
136
+
137
+ @multi_facets.each_pair do |facet_field, value_list|
138
+ value_list ||= []
139
+ value_list = [value_list] unless value_list.respond_to? :each
140
+ value_list.each do |value|
141
+ expect(solr_params[:fq]).to include("{!raw f=#{facet_field}}#{value}" )
142
+ end
143
+ end
144
+
145
+ end
146
+ end
147
+
148
+ describe "with Multi Facets, Multi Word Query" do
149
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(FacetModel.table) }
150
+ it 'should have fq and q set properly' do
151
+ rel = FacetModel.filter(@multi_facets).where(q: @mult_word_query)
152
+ solr_params = subject.accept(rel.build_arel.ast)
153
+
154
+ @multi_facets.each_pair do |facet_field, value_list|
155
+ value_list ||= []
156
+ value_list = [value_list] unless value_list.respond_to? :each
157
+ value_list.each do |value|
158
+ expect(solr_params[:fq]).to include("{!raw f=#{facet_field}}#{value}" )
159
+ end
160
+ end
161
+ expect(solr_params[:q]).to eq @mult_word_query
162
+ end
163
+ end
164
+
165
+ describe "facet_value_to_fq_string" do
166
+ let(:table) { FacetModel.table }
167
+ subject { Ansr::Blacklight::Arel::Visitors::QueryBuilder.new(table) }
168
+ it "should use the raw handler for strings" do
169
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "my value")).to eq "{!raw f=facet_name}my value"
170
+ end
171
+
172
+ it "should pass booleans through" do
173
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", true)).to eq "facet_name:true"
174
+ end
175
+
176
+ it "should pass boolean-like strings through" do
177
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "true")).to eq "facet_name:true"
178
+ end
179
+
180
+ it "should pass integers through" do
181
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", 1)).to eq "facet_name:1"
182
+ end
183
+
184
+ it "should pass integer-like strings through" do
185
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "1")).to eq "facet_name:1"
186
+ end
187
+
188
+ it "should pass floats through" do
189
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", 1.11)).to eq "facet_name:1.11"
190
+ end
191
+
192
+ it "should pass floats through" do
193
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "1.11")).to eq "facet_name:1.11"
194
+ end
195
+
196
+ it "should pass date-type fields through" do
197
+ table.configure_fields do |config|
198
+ config[:facet_name] = {date: true}
199
+ end
200
+
201
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "2012-01-01")).to eq "facet_name:2012-01-01"
202
+ end
203
+
204
+ it "should handle range requests" do
205
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", 1..5)).to eq "facet_name:[1 TO 5]"
206
+ end
207
+
208
+ it "should add tag local parameters" do
209
+ table.configure_fields do |config|
210
+ config[:facet_name] = {local: {tag: 'asdf'}}
211
+ end
212
+
213
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", true)).to eq "{!tag=asdf}facet_name:true"
214
+ expect(subject.send(:filter_value_to_fq_string, "facet_name", "my value")).to eq "{!raw f=facet_name tag=asdf}my value"
215
+ end
216
+ end
217
+
218
+ describe "solr parameters for a field search from config (subject)" do
219
+ let(:table) { FacetModel.table }
220
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
221
+ let(:rel) { FacetModel.build_default_scope.spawn }
222
+ let(:blacklight_config) { copy_of_catalog_config }
223
+ before do
224
+ #@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
225
+ table.configure_fields do |config|
226
+ hash = (config[:subject] ||= {local: {}, query: {}})
227
+ hash[:query][:'spellcheck.dictionary'] = 'subject'
228
+ hash[:query][:qt] = 'search'
229
+ hash[:local][:pf] = '$subject_pf'
230
+ hash[:local][:qf] = '$subject_qf'
231
+ end
232
+ rel.where!(subject: 'wome')
233
+ end
234
+ after do
235
+ table.configure_fields { |config| config.clear }
236
+ end
237
+ it "should look up qt from field definition" do
238
+ solr_params = subject.accept(rel.build_arel.ast)
239
+ expect(solr_params[:qt]).to eq "search"
240
+ end
241
+ it "should not include weird keys not in field definition" do
242
+ solr_params = subject.accept(rel.build_arel.ast)
243
+ solr_params.to_hash.tap do |h|
244
+ expect(h[:phrase_filters]).to be_nil
245
+ expect(h[:fq]).to be_nil
246
+ expect(h[:commit]).to be_nil
247
+ expect(h[:action]).to be_nil
248
+ expect(h[:controller]).to be_nil
249
+ end
250
+ end
251
+ it "should include proper 'q', possibly with LocalParams" do
252
+ solr_params = subject.accept(rel.build_arel.ast)
253
+ expect(solr_params[:q]).to match(/(\{[^}]+\})?wome/)
254
+ end
255
+ it "should include proper 'q' when LocalParams are used" do
256
+ solr_params = subject.accept(rel.build_arel.ast)
257
+ if solr_params[:q] =~ /\{[^}]+\}/
258
+ expect(solr_params[:q]).to match(/\{[^}]+\}wome/)
259
+ end
260
+ end
261
+ it "should include spellcheck.q, without LocalParams" do
262
+ solr_params = subject.accept(rel.build_arel.ast)
263
+ expect(solr_params["spellcheck.q"]).to eq "wome"
264
+ end
265
+
266
+ it "should include spellcheck.dictionary from field def solr_parameters" do
267
+ solr_params = subject.accept(rel.build_arel.ast)
268
+ expect(solr_params[:"spellcheck.dictionary"]).to eq "subject"
269
+ end
270
+ it "should add on :solr_local_parameters using Solr LocalParams style" do
271
+ solr_params = subject.accept(rel.build_arel.ast)
272
+
273
+ #q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure
274
+ #the LocalParams are really there
275
+ solr_params[:q] =~ /^\{!([^}]+)\}/
276
+ key_value_pairs = $1.split(" ")
277
+ expect(key_value_pairs).to include("pf=$subject_pf")
278
+ expect(key_value_pairs).to include("qf=$subject_qf")
279
+ end
280
+ end
281
+
282
+ describe "overriding of qt parameter" do
283
+ let(:table) { FacetModel.table }
284
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
285
+ let(:rel) { FacetModel.build_default_scope.as('overriden') }
286
+ let(:blacklight_config) { copy_of_catalog_config }
287
+ it "should return the correct overriden parameter" do
288
+ solr_params = subject.accept(rel.build_arel.ast)
289
+ expect(solr_params[:qt]).to eq "overriden"
290
+ end
291
+ end
292
+
293
+ describe "converts a String fq into an Array" do
294
+ let(:table) { FacetModel.table }
295
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
296
+ let(:rel) { FacetModel.build_default_scope }
297
+ it "should return the correct overriden parameter" do
298
+ solr_params = subject.accept(rel.facet('a string').build_arel.ast)
299
+ expect(solr_params[:fq]).to be_a_kind_of Array
300
+ end
301
+ end
302
+
303
+ describe "#add_solr_fields_to_query" do
304
+ let(:table) { FacetModel.table }
305
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
306
+ let(:rel) { FacetModel.build_default_scope}
307
+ before do
308
+ FacetModel.table.configure_fields do |config|
309
+ config[:an_index_field] = {select: { 'hl.alternativeField' => 'field_x'}}
310
+ config[:a_show_field] = {select: { 'hl.alternativeField' => 'field_y'}}
311
+ end
312
+ end
313
+ after do
314
+ FacetModel.table.configure_fields.clear
315
+ end
316
+
317
+ it "should add any extra solr parameters from index and show fields" do
318
+ solr_params = subject.accept(rel.select(:an_index_field, :a_show_field).build_arel.ast)
319
+ expect(solr_params[:'f.an_index_field.hl.alternativeField']).to eq "field_x"
320
+ expect(solr_params[:'f.a_show_field.hl.alternativeField']).to eq "field_y"
321
+ end
322
+ end
323
+
324
+ describe "#add_facetting_to_solr" do
325
+
326
+ let(:table) { FacetModel.table }
327
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
328
+ let(:rel) {
329
+ FacetModel.build_default_scope.spawn
330
+ .facet('test_field', :sort => 'count')
331
+ .facet('some-query', :query => {'x' => {:fq => 'some:query'}} , :ex => 'xyz')
332
+ .facet('some-pivot', :pivot => ['a','b'], :ex => 'xyz')
333
+ .facet('some-field', mincount: 15 )
334
+ }
335
+
336
+ it "should add sort parameters" do
337
+ solr_params = subject.accept(rel.build_arel.ast)
338
+ expect(solr_params[:facet]).to be_true
339
+
340
+ expect(solr_params[:'facet.field']).to include(:'test_field')
341
+ expect(solr_params[:'f.test_field.facet.sort']).to eq 'count'
342
+ end
343
+
344
+ it "should add facet exclusions" do
345
+ solr_params = subject.accept(rel.build_arel.ast)
346
+ expect(solr_params[:'facet.query']).to include('{!ex=xyz}some:query')
347
+ expect(solr_params[:'facet.pivot']).to include('{!ex=xyz}a,b')
348
+ end
349
+
350
+ it "should add any additional solr_params" do
351
+ solr_params = subject.accept(rel.build_arel.ast)
352
+ expect(solr_params[:'f.some-field.facet.mincount']).to eq '15'
353
+ end
354
+ end
355
+
356
+ describe "for :solr_local_parameters config" do
357
+ let(:table) { FacetModel.table }
358
+ subject { Ansr::Blacklight::Arel::Visitors::ToNoSql.new(table) }
359
+ let(:rel) { FacetModel.build_default_scope.spawn }
360
+ let(:result) { subject.accept rel.where(:custom_author_key => "query").build_arel.ast }
361
+ before do
362
+ #@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
363
+ table.configure_fields do |config|
364
+ hash = (config[:custom_author_key] ||= {local: {}, query: {}, select: {}})
365
+ hash[:query][:'spellcheck.dictionary'] = 'subject'
366
+ hash[:query][:qt] = 'author_qt'
367
+ hash[:query][:qf] = 'someField^1000'
368
+ hash[:query][:ps] = '2'
369
+ hash[:local][:pf] = "you'll have \" to escape this"
370
+ hash[:local][:pf2] = '$pf2_do_not_escape_or_quote'
371
+ hash[:local][:qf] = '$author_qf'
372
+ end
373
+ rel.where!(subject: 'wome')
374
+ end
375
+ after do
376
+ table.configure_fields { |config| config.clear }
377
+ end
378
+
379
+ it "should pass through ordinary params" do
380
+ expect(result[:qt]).to eq "author_qt"
381
+ expect(result[:ps]).to eq "2"
382
+ expect(result[:qf]).to eq "someField^1000"
383
+ end
384
+
385
+ it "should include include local params with escaping" do
386
+ expect(result[:q]).to include('qf=$author_qf')
387
+ expect(result[:q]).to include('pf=\'you\\\'ll have \\" to escape this\'')
388
+ expect(result[:q]).to include('pf2=$pf2_do_not_escape_or_quote')
389
+ end
390
+ end
391
+ end
392
+
393
+ describe "solr_facet_params" do
394
+ before do
395
+ @facet_field = 'format'
396
+ @generated_solr_facet_params = subject.solr_facet_params(@facet_field)
397
+
398
+ @sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
399
+ @page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
400
+ end
401
+
402
+ let(:blacklight_config) do
403
+ Blacklight::Configuration.new do |config|
404
+ config.add_facet_fields_to_solr_request!
405
+ config.add_facet_field 'format'
406
+ config.add_facet_field 'format_ordered', :sort => :count
407
+ config.add_facet_field 'format_limited', :limit => 5
408
+
409
+ end
410
+ end
411
+
412
+ pending 'sets rows to 0' do
413
+ expect(@generated_solr_facet_params[:rows]).to eq 0
414
+ end
415
+ pending 'sets facets requested to facet_field argument' do
416
+ expect(@generated_solr_facet_params["facet.field".to_sym]).to eq @facet_field
417
+ end
418
+ pending 'defaults offset to 0' do
419
+ expect(@generated_solr_facet_params[:"f.#{@facet_field}.facet.offset"]).to eq 0
420
+ end
421
+ pending 'uses offset manually set, and converts it to an integer' do
422
+ solr_params = subject.solr_facet_params(@facet_field, @page_key => 2)
423
+ expect(solr_params[:"f.#{@facet_field}.facet.offset"]).to eq 20
424
+ end
425
+ pending 'defaults limit to 20' do
426
+ solr_params = subject.solr_facet_params(@facet_field)
427
+ expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 21
428
+ end
429
+
430
+ describe 'if facet_list_limit is defined in controller' do
431
+ before do
432
+ subject.stub facet_list_limit: 1000
433
+ end
434
+ pending 'uses controller method for limit' do
435
+ solr_params = subject.solr_facet_params(@facet_field)
436
+ expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
437
+ end
438
+
439
+ pending 'uses controller method for limit when a ordinary limit is set' do
440
+ solr_params = subject.solr_facet_params(@facet_field)
441
+ expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
442
+ end
443
+ end
444
+
445
+ pending 'uses the default sort' do
446
+ solr_params = subject.solr_facet_params(@facet_field)
447
+ expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to be_blank
448
+ end
449
+
450
+ pending "uses the field-specific sort" do
451
+ solr_params = subject.solr_facet_params('format_ordered')
452
+ expect(solr_params[:"f.format_ordered.facet.sort"]).to eq :count
453
+ end
454
+
455
+ pending 'uses sort provided in the parameters' do
456
+ solr_params = subject.solr_facet_params(@facet_field, @sort_key => "index")
457
+ expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to eq 'index'
458
+ end
459
+ pending "comes up with the same params as #solr_search_params to constrain context for facet list" do
460
+ search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
461
+ solr_search_params = subject.solr_search_params( search_params )
462
+ solr_facet_params = subject.solr_facet_params('format', search_params)
463
+
464
+ solr_search_params.each_pair do |key, value|
465
+ # The specific params used for fetching the facet list we
466
+ # don't care about.
467
+ next if ['facets', "facet.field", 'rows', 'facet.limit', 'facet.offset', 'facet.sort'].include?(key)
468
+ # Everything else should match
469
+ expect(solr_facet_params[key]).to eq value
470
+ end
471
+
472
+ end
473
+ end
474
+
475
+ end