blacklight 5.11.3 → 5.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -2
  4. data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -4
  5. data/app/helpers/blacklight/facets_helper_behavior.rb +10 -6
  6. data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
  7. data/app/views/bookmarks/_clear_bookmarks_widget.html.erb +1 -0
  8. data/app/views/bookmarks/index.html.erb +0 -1
  9. data/blacklight.gemspec +1 -1
  10. data/config/locales/blacklight.en.yml +1 -0
  11. data/lib/blacklight.rb +2 -1
  12. data/lib/blacklight/bookmarks.rb +2 -0
  13. data/lib/blacklight/catalog.rb +1 -1
  14. data/lib/blacklight/configuration.rb +8 -1
  15. data/lib/blacklight/configuration/fields.rb +20 -10
  16. data/lib/blacklight/document.rb +43 -13
  17. data/lib/blacklight/document_presenter.rb +8 -4
  18. data/lib/blacklight/facet.rb +6 -54
  19. data/lib/blacklight/request_builders.rb +2 -2
  20. data/lib/blacklight/search_builder.rb +48 -18
  21. data/lib/blacklight/search_helper.rb +10 -10
  22. data/lib/blacklight/solr.rb +1 -1
  23. data/lib/blacklight/solr/search_builder.rb +2 -265
  24. data/lib/blacklight/solr/search_builder_behavior.rb +274 -0
  25. data/lib/blacklight/solr_repository.rb +1 -1
  26. data/lib/blacklight/solr_response.rb +8 -16
  27. data/lib/blacklight/solr_response/facets.rb +133 -25
  28. data/lib/blacklight/solr_response/group_response.rb +1 -1
  29. data/lib/blacklight/solr_response/pagination_methods.rb +0 -17
  30. data/lib/generators/blacklight/install_generator.rb +6 -1
  31. data/lib/generators/blacklight/search_builder_generator.rb +20 -0
  32. data/lib/generators/blacklight/templates/search_builder.rb +3 -0
  33. data/lib/railties/blacklight.rake +1 -1
  34. data/spec/controllers/catalog_controller_spec.rb +9 -9
  35. data/spec/helpers/blacklight_helper_spec.rb +29 -179
  36. data/spec/helpers/facets_helper_spec.rb +37 -75
  37. data/spec/helpers/url_helper_spec.rb +1 -1
  38. data/spec/lib/blacklight/configuration_spec.rb +18 -1
  39. data/spec/lib/blacklight/document_spec.rb +62 -0
  40. data/spec/lib/blacklight/search_builder_spec.rb +15 -13
  41. data/spec/lib/blacklight/search_helper_spec.rb +15 -16
  42. data/spec/lib/blacklight/solr/document_spec.rb +5 -3
  43. data/spec/lib/blacklight/solr/search_builder_spec.rb +0 -5
  44. data/spec/lib/blacklight/solr_response/facets_spec.rb +144 -10
  45. data/spec/lib/blacklight/solr_response_spec.rb +5 -13
  46. data/spec/lib/document_presenter_spec.rb +23 -27
  47. data/spec/views/catalog/_facets.html.erb_spec.rb +1 -1
  48. data/spec/views/catalog/_index_default.erb_spec.rb +2 -13
  49. data/spec/views/catalog/_show_default.erb_spec.rb +1 -13
  50. metadata +10 -4
@@ -28,13 +28,13 @@ describe Blacklight::SolrResponse do
28
28
  end
29
29
 
30
30
  it 'should provide facet helpers' do
31
- expect(r.facets.size).to eq 2
31
+ expect(r.aggregations.size).to eq 2
32
32
 
33
- field_names = r.facets.collect{|facet|facet.name}
33
+ field_names = r.aggregations.collect{|key, facet|facet.name}
34
34
  expect(field_names.include?('cat')).to be true
35
35
  expect(field_names.include?('manu')).to be true
36
36
 
37
- first_facet = r.facets.select { |x| x.name == 'cat'}.first
37
+ first_facet = r.aggregations['cat']
38
38
  expect(first_facet.name).to eq 'cat'
39
39
 
40
40
  expect(first_facet.items.size).to eq 10
@@ -46,7 +46,7 @@ describe Blacklight::SolrResponse do
46
46
 
47
47
  expect(received).to eq expected
48
48
 
49
- r.facets.each do |facet|
49
+ r.aggregations.each do |key, facet|
50
50
  expect(facet).to respond_to :name
51
51
  expect(facet).to respond_to :sort
52
52
  expect(facet).to respond_to :offset
@@ -70,14 +70,6 @@ describe Blacklight::SolrResponse do
70
70
  expect(r).to be_a_kind_of Kaminari::PageScopeMethods
71
71
  end
72
72
 
73
- it "should provide a model name helper" do
74
- first_doc_model_name = double(:human => 'xyz')
75
-
76
- allow(r.docs.first).to receive(:model_name).and_return first_doc_model_name
77
-
78
- expect(r.model_name).to eq first_doc_model_name
79
- end
80
-
81
73
  describe "FacetItem" do
82
74
  it "should work with a field,value tuple" do
83
75
  item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15)
@@ -115,7 +107,7 @@ describe Blacklight::SolrResponse do
115
107
 
116
108
  it 'should return the correct value when calling facet_by_field_name' do
117
109
  r = create_response
118
- facet = r.facet_by_field_name('cat')
110
+ facet = r.aggregations['cat']
119
111
  expect(facet.name).to eq 'cat'
120
112
  end
121
113
 
@@ -3,10 +3,17 @@ require 'spec_helper'
3
3
  describe Blacklight::DocumentPresenter do
4
4
  include Capybara::RSpecMatchers
5
5
  let(:request_context) { double(:add_facet_params => '') }
6
- let(:document) { double }
7
6
  let(:config) { Blacklight::Configuration.new }
8
7
 
9
8
  subject { Blacklight::DocumentPresenter.new(document, request_context, config) }
9
+
10
+ let(:document) do
11
+ SolrDocument.new(id: 1,
12
+ 'link_to_search_true' => 'x',
13
+ 'link_to_search_named' => 'x',
14
+ 'qwer' => 'document qwer value',
15
+ 'mnbv' => 'document mnbv value')
16
+ end
10
17
 
11
18
  describe "render_index_field_value" do
12
19
  let(:config) do
@@ -20,23 +27,21 @@ describe Blacklight::DocumentPresenter do
20
27
  config.add_index_field 'explicit_accessor', :accessor => :solr_doc_accessor
21
28
  config.add_index_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
22
29
  config.add_index_field 'alias', field: 'qwer'
30
+ config.add_index_field 'with_default', default: 'value'
23
31
  end
24
32
  end
25
33
  it "should check for an explicit value" do
26
- expect(document).to_not receive(:get).with('asdf', :sep => nil)
27
34
  value = subject.render_index_field_value 'asdf', :value => 'asdf'
28
35
  expect(value).to eq 'asdf'
29
36
  end
30
37
 
31
38
  it "should check for a helper method to call" do
32
- allow(document).to receive(:get).with('asdf', :sep => nil)
33
39
  allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
34
40
  value = subject.render_index_field_value 'asdf'
35
41
  expect(value).to eq 'custom asdf value'
36
42
  end
37
43
 
38
44
  it "should check for a link_to_search" do
39
- allow(document).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
40
45
  allow(request_context).to receive(:add_facet_params).and_return(:f => { :link_to_search_true => ['x'] })
41
46
  allow(request_context).to receive(:search_action_path).with(:f => { :link_to_search_true => ['x'] }).and_return('/foo')
42
47
  allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
@@ -45,7 +50,6 @@ describe Blacklight::DocumentPresenter do
45
50
  end
46
51
 
47
52
  it "should check for a link_to_search with a field name" do
48
- allow(document).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
49
53
  allow(request_context).to receive(:add_facet_params).and_return(:f => { :some_field => ['x'] })
50
54
  allow(request_context).to receive(:search_action_path).with(:f => { :some_field => ['x'] }).and_return('/foo')
51
55
  allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
@@ -54,14 +58,12 @@ describe Blacklight::DocumentPresenter do
54
58
  end
55
59
 
56
60
  it "should gracefully handle when no highlight field is available" do
57
- expect(document).to_not receive(:get)
58
61
  allow(document).to receive(:has_highlight_field?).and_return(false)
59
62
  value = subject.render_index_field_value 'highlight'
60
63
  expect(value).to be_blank
61
64
  end
62
65
 
63
66
  it "should check for a highlighted field" do
64
- expect(document).to_not receive(:get)
65
67
  allow(document).to receive(:has_highlight_field?).and_return(true)
66
68
  allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
67
69
  value = subject.render_index_field_value 'highlight'
@@ -69,40 +71,42 @@ describe Blacklight::DocumentPresenter do
69
71
  end
70
72
 
71
73
  it "should check the document field value" do
72
- allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
73
74
  value = subject.render_index_field_value 'qwer'
74
75
  expect(value).to eq 'document qwer value'
75
76
  end
76
77
 
77
78
  it "should work with index fields that aren't explicitly defined" do
78
- allow(document).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
79
79
  value = subject.render_index_field_value 'mnbv'
80
80
  expect(value).to eq 'document mnbv value'
81
81
  end
82
82
 
83
83
  it "should call an accessor on the solr document" do
84
- allow(document).to receive_messages(:solr_doc_accessor => "123")
84
+ allow(document).to receive_messages(solr_doc_accessor: "123")
85
85
  value = subject.render_index_field_value 'solr_doc_accessor'
86
86
  expect(value).to eq "123"
87
87
  end
88
88
 
89
89
  it "should call an explicit accessor on the solr document" do
90
- allow(document).to receive_messages(:solr_doc_accessor => "123")
90
+ allow(document).to receive_messages(solr_doc_accessor: "123")
91
91
  value = subject.render_index_field_value 'explicit_accessor'
92
92
  expect(value).to eq "123"
93
93
  end
94
-
95
- it "should call an implicit accessor on the solr document" do
96
- expect(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
94
+
95
+ it "should call an accessor on the solr document with the field as an argument" do
96
+ allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
97
97
  value = subject.render_index_field_value 'explicit_accessor_with_arg'
98
98
  expect(value).to eq "123"
99
99
  end
100
100
 
101
101
  it "should support solr field configuration" do
102
- allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
103
102
  value = subject.render_index_field_value 'alias'
104
103
  expect(value).to eq "document qwer value"
105
104
  end
105
+
106
+ it "should support default values in the field configuration" do
107
+ value = subject.render_index_field_value 'with_default'
108
+ expect(value).to eq "value"
109
+ end
106
110
  end
107
111
 
108
112
  describe "render_document_show_field_value" do
@@ -121,21 +125,18 @@ describe Blacklight::DocumentPresenter do
121
125
  end
122
126
 
123
127
  it "should check for an explicit value" do
124
- expect(document).to_not receive(:get).with('asdf', :sep => nil)
125
128
  expect(request_context).to_not receive(:render_asdf_document_show_field)
126
129
  value = subject.render_document_show_field_value 'asdf', :value => 'val1'
127
130
  expect(value).to eq 'val1'
128
131
  end
129
132
 
130
133
  it "should check for a helper method to call" do
131
- allow(document).to receive(:get).with('asdf', :sep => nil)
132
134
  allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
133
135
  value = subject.render_document_show_field_value 'asdf'
134
136
  expect(value).to eq 'custom asdf value'
135
137
  end
136
138
 
137
139
  it "should check for a link_to_search" do
138
- allow(document).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
139
140
  allow(request_context).to receive(:search_action_path).with('').and_return('/foo')
140
141
  allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
141
142
  value = subject.render_document_show_field_value 'link_to_search_true'
@@ -143,7 +144,6 @@ describe Blacklight::DocumentPresenter do
143
144
  end
144
145
 
145
146
  it "should check for a link_to_search with a field name" do
146
- allow(document).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
147
147
  allow(request_context).to receive(:search_action_path).with('').and_return('/foo')
148
148
  allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
149
149
  value = subject.render_document_show_field_value 'link_to_search_named'
@@ -151,14 +151,12 @@ describe Blacklight::DocumentPresenter do
151
151
  end
152
152
 
153
153
  it "should gracefully handle when no highlight field is available" do
154
- expect(document).to_not receive(:get)
155
154
  allow(document).to receive(:has_highlight_field?).and_return(false)
156
155
  value = subject.render_document_show_field_value 'highlight'
157
156
  expect(value).to be_blank
158
157
  end
159
158
 
160
159
  it "should check for a highlighted field" do
161
- expect(document).to_not receive(:get)
162
160
  allow(document).to receive(:has_highlight_field?).and_return(true)
163
161
  allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
164
162
  value = subject.render_document_show_field_value 'highlight'
@@ -167,37 +165,35 @@ describe Blacklight::DocumentPresenter do
167
165
 
168
166
 
169
167
  it "should check the document field value" do
170
- allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
171
168
  value = subject.render_document_show_field_value 'qwer'
172
169
  expect(value).to eq 'document qwer value'
173
170
  end
174
171
 
175
172
  it "should work with show fields that aren't explicitly defined" do
176
- allow(document).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
177
173
  value = subject.render_document_show_field_value 'mnbv'
178
174
  expect(value).to eq 'document mnbv value'
179
175
  end
180
176
 
181
177
  it "should call an accessor on the solr document" do
182
- allow(document).to receive_messages(:solr_doc_accessor => "123")
178
+ allow(document).to receive_messages(solr_doc_accessor: "123")
183
179
  value = subject.render_document_show_field_value 'solr_doc_accessor'
184
180
  expect(value).to eq "123"
185
181
  end
186
182
 
187
183
  it "should call an explicit accessor on the solr document" do
188
- allow(document).to receive_messages(:solr_doc_accessor => "123")
184
+ allow(document).to receive_messages(solr_doc_accessor: "123")
189
185
  value = subject.render_document_show_field_value 'explicit_accessor'
190
186
  expect(value).to eq "123"
191
187
  end
192
188
 
193
189
  it "should call an explicit array-style accessor on the solr document" do
194
- allow(document).to receive_messages(:solr_doc_accessor => double(:some_method => "123"))
190
+ allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
195
191
  value = subject.render_document_show_field_value 'explicit_array_accessor'
196
192
  expect(value).to eq "123"
197
193
  end
198
194
 
199
195
  it "should call an accessor on the solr document with the field as an argument" do
200
- expect(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
196
+ allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
201
197
  value = subject.render_document_show_field_value 'explicit_accessor_with_arg'
202
198
  expect(value).to eq "123"
203
199
  end
@@ -31,7 +31,7 @@ describe "catalog/_facets" do
31
31
  :facet_limit_for => 10 )
32
32
 
33
33
  @response = double()
34
- allow(@response).to receive(:facet_by_field_name).with("facet_field_1") { @mock_display_facet_1 }
34
+ allow(@response).to receive(:aggregations).and_return("facet_field_1" => @mock_display_facet_1)
35
35
  end
36
36
 
37
37
  it "should have a header" do
@@ -20,20 +20,9 @@ describe "/catalog/_index_default.erb" do
20
20
  @fname_3 = "empty_field"
21
21
  @fname_4 = "four_field"
22
22
 
23
- @document = double("solr_doc")
24
- allow(@document).to receive(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
25
- allow(@document).to receive(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
26
- allow(@document).to receive(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
27
- allow(@document).to receive(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
28
-
29
- allow(@document).to receive(:has?).with(@fname_1).and_return(true)
30
- allow(@document).to receive(:has?).with(@fname_2).and_return(true)
31
- allow(@document).to receive(:has?).with(@fname_3).and_return(false)
32
- allow(@document).to receive(:has?).with(@fname_4).and_return(true)
33
-
34
- # cover any remaining fields in initalizer
35
- allow(@document).to receive(:[])
36
23
 
24
+ @document = SolrDocument.new(id: 1, @fname_1 => "val_1", @fname_2 => "val2", @fname_4 => "val_4")
25
+
37
26
  @flabel_1 = "One:"
38
27
  @flabel_3 = "Three:"
39
28
  @flabel_4 = "Four:"
@@ -22,19 +22,7 @@ describe "/catalog/_show_default.html.erb" do
22
22
  @fname_3 = "empty_field"
23
23
  @fname_4 = "four_field"
24
24
 
25
- @document = double("solr_doc")
26
- allow(@document).to receive(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
27
- allow(@document).to receive(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
28
- allow(@document).to receive(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
29
- allow(@document).to receive(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
30
-
31
- allow(@document).to receive(:has?).with(@fname_1).and_return(true)
32
- allow(@document).to receive(:has?).with(@fname_2).and_return(true)
33
- allow(@document).to receive(:has?).with(@fname_3).and_return(false)
34
- allow(@document).to receive(:has?).with(@fname_4).and_return(true)
35
-
36
- # cover any remaining fields in initalizer
37
- allow(@document).to receive(:[])
25
+ @document = SolrDocument.new(id: 1, @fname_1 => "val_1", @fname_2 => "val2", @fname_4 => "val_4")
38
26
 
39
27
  @flabel_1 = "One:"
40
28
  @flabel_3 = "Two:"
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: 5.11.3
4
+ version: 5.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2015-03-26 00:00:00.000000000 Z
20
+ date: 2015-03-24 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.13'
62
+ version: '0.15'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0.13'
69
+ version: '0.15'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rsolr
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -314,6 +314,7 @@ files:
314
314
  - app/views/blacklight/nav/_bookmark.html.erb
315
315
  - app/views/blacklight/nav/_saved_searches.html.erb
316
316
  - app/views/blacklight/nav/_search_history.html.erb
317
+ - app/views/bookmarks/_clear_bookmarks_widget.html.erb
317
318
  - app/views/bookmarks/_tools.html.erb
318
319
  - app/views/bookmarks/index.html.erb
319
320
  - app/views/catalog/_bookmark_control.html.erb
@@ -452,6 +453,7 @@ files:
452
453
  - lib/blacklight/solr/facet_paginator.rb
453
454
  - lib/blacklight/solr/request.rb
454
455
  - lib/blacklight/solr/search_builder.rb
456
+ - lib/blacklight/solr/search_builder_behavior.rb
455
457
  - lib/blacklight/solr_helper.rb
456
458
  - lib/blacklight/solr_repository.rb
457
459
  - lib/blacklight/solr_response.rb
@@ -471,6 +473,7 @@ files:
471
473
  - lib/generators/blacklight/document_generator.rb
472
474
  - lib/generators/blacklight/install_generator.rb
473
475
  - lib/generators/blacklight/models_generator.rb
476
+ - lib/generators/blacklight/search_builder_generator.rb
474
477
  - lib/generators/blacklight/templates/alternate_controller.rb
475
478
  - lib/generators/blacklight/templates/blacklight.css.scss
476
479
  - lib/generators/blacklight/templates/blacklight.en.yml
@@ -478,6 +481,7 @@ files:
478
481
  - lib/generators/blacklight/templates/config/blacklight.yml
479
482
  - lib/generators/blacklight/templates/config/initializers/blacklight_initializer.rb
480
483
  - lib/generators/blacklight/templates/config/jetty.yml
484
+ - lib/generators/blacklight/templates/search_builder.rb
481
485
  - lib/generators/blacklight/templates/solr_document.rb
482
486
  - lib/generators/blacklight/test_support_generator.rb
483
487
  - lib/generators/blacklight/user_generator.rb
@@ -518,6 +522,7 @@ files:
518
522
  - spec/lib/blacklight/document/dublin_core_spec.rb
519
523
  - spec/lib/blacklight/document/email_spec.rb
520
524
  - spec/lib/blacklight/document/sms_spec.rb
525
+ - spec/lib/blacklight/document_spec.rb
521
526
  - spec/lib/blacklight/facet_paginator_spec.rb
522
527
  - spec/lib/blacklight/facet_spec.rb
523
528
  - spec/lib/blacklight/routes_spec.rb
@@ -637,6 +642,7 @@ test_files:
637
642
  - spec/lib/blacklight/document/dublin_core_spec.rb
638
643
  - spec/lib/blacklight/document/email_spec.rb
639
644
  - spec/lib/blacklight/document/sms_spec.rb
645
+ - spec/lib/blacklight/document_spec.rb
640
646
  - spec/lib/blacklight/facet_paginator_spec.rb
641
647
  - spec/lib/blacklight/facet_spec.rb
642
648
  - spec/lib/blacklight/routes_spec.rb