blacklight 5.0.3 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/Gemfile +9 -9
  4. data/Rakefile +0 -1
  5. data/VERSION +1 -1
  6. data/app/assets/stylesheets/blacklight/_facets.css.scss +2 -1
  7. data/app/controllers/bookmarks_controller.rb +0 -1
  8. data/app/helpers/blacklight/blacklight_helper_behavior.rb +3 -3
  9. data/app/helpers/blacklight/catalog_helper_behavior.rb +5 -1
  10. data/app/helpers/blacklight/configuration_helper_behavior.rb +60 -0
  11. data/app/helpers/blacklight/facets_helper_behavior.rb +3 -5
  12. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +1 -1
  13. data/app/helpers/blacklight/url_helper_behavior.rb +24 -19
  14. data/app/views/catalog/_facet_layout.html.erb +1 -1
  15. data/app/views/catalog/_facet_limit.html.erb +2 -4
  16. data/app/views/catalog/_facet_pagination.html.erb +0 -1
  17. data/app/views/catalog/facet.html.erb +2 -13
  18. data/blacklight.gemspec +3 -3
  19. data/gemfiles/rails3.gemfile +19 -5
  20. data/gemfiles/rails4.gemfile +17 -5
  21. data/lib/blacklight/catalog.rb +55 -10
  22. data/lib/blacklight/configuration.rb +6 -1
  23. data/lib/blacklight/configuration/fields.rb +38 -4
  24. data/lib/blacklight/controller.rb +10 -1
  25. data/lib/blacklight/facet.rb +8 -0
  26. data/lib/blacklight/solr_helper.rb +53 -25
  27. data/lib/blacklight/solr_response/facets.rb +22 -4
  28. data/spec/controllers/catalog_controller_spec.rb +59 -2
  29. data/spec/features/alternate_controller_spec.rb +3 -3
  30. data/spec/features/record_view_spec.rb +1 -1
  31. data/spec/helpers/blacklight_helper_spec.rb +5 -5
  32. data/spec/helpers/catalog_helper_spec.rb +20 -7
  33. data/spec/helpers/configuration_helper_spec.rb +42 -0
  34. data/spec/helpers/facets_helper_spec.rb +5 -12
  35. data/spec/helpers/render_constraints_helper_spec.rb +4 -1
  36. data/spec/helpers/url_helper_spec.rb +37 -49
  37. data/spec/lib/blacklight/configuration_spec.rb +53 -1
  38. data/spec/lib/blacklight/solr_helper_spec.rb +37 -4
  39. data/spec/test_app_templates/Gemfile.extra +21 -0
  40. data/spec/test_app_templates/lib/generators/test_app_generator.rb +5 -0
  41. data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +14 -0
  42. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -2
  43. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -1
  44. data/spec/views/catalog/_facets.html.erb_spec.rb +42 -40
  45. data/spec/views/catalog/facet.html.erb_spec.rb +30 -0
  46. metadata +23 -33
  47. data/spec/views/catalog/opensearch.xml.builder_spec.rb +0 -10
@@ -55,6 +55,18 @@ describe "Blacklight::Configuration" do
55
55
  end
56
56
  end
57
57
 
58
+ describe "config.index.respond_to" do
59
+ it "should have a list of additional formats for index requests to respond to" do
60
+ @config.index.respond_to.xml = true
61
+
62
+ @config.index.respond_to.csv = { :layout => false }
63
+
64
+ @config.index.respond_to.yaml = lambda { render text: "" }
65
+
66
+ expect(@config.index.respond_to.keys).to eq [:xml, :csv, :yaml]
67
+ end
68
+ end
69
+
58
70
  describe "spell_max" do
59
71
  it "should default to 5" do
60
72
  expect(Blacklight::Configuration.new.spell_max).to eq 5
@@ -152,6 +164,13 @@ describe "Blacklight::Configuration" do
152
164
  expect(@config.facet_fields).to have(2).fields
153
165
  end
154
166
 
167
+ it "should accept array form with a block" do
168
+ expect do |b|
169
+ @config.add_facet_field([{ :field => 'format', :label => 'Format'}, { :field => 'publication_date', :label => 'Publication Date' }], &b)
170
+ end.to yield_control.twice
171
+ end
172
+
173
+
155
174
  it "should create default label from titleized solr field" do
156
175
  @config.add_facet_field("publication_date")
157
176
 
@@ -167,7 +186,18 @@ describe "Blacklight::Configuration" do
167
186
  it "should raise on nil solr field name" do
168
187
  expect { @config.add_facet_field(nil) }.to raise_error ArgumentError
169
188
  end
170
-
189
+
190
+ it "should take wild-carded field names and dereference them to solr fields" do
191
+ @config.stub(luke_fields: {
192
+ "some_field_facet" => {},
193
+ "another_field_facet" => {},
194
+ "a_facet_field" => {},
195
+ })
196
+ expect { |b| @config.add_index_field "*_facet", &b }.to yield_control.twice
197
+
198
+ expect(@config.index_fields.keys).to eq ["some_field_facet", "another_field_facet"]
199
+ end
200
+
171
201
  end
172
202
 
173
203
  describe "add_index_field" do
@@ -201,6 +231,17 @@ describe "Blacklight::Configuration" do
201
231
  expect { @config.add_index_field(nil) }.to raise_error ArgumentError
202
232
  end
203
233
 
234
+ it "should take wild-carded field names and dereference them to solr fields" do
235
+ @config.stub(luke_fields: {
236
+ "some_field_display" => {},
237
+ "another_field_display" => {},
238
+ "a_facet_field" => {},
239
+ })
240
+ @config.add_index_field "*_display"
241
+
242
+ expect(@config.index_fields.keys).to eq ["some_field_display", "another_field_display"]
243
+ end
244
+
204
245
  end
205
246
 
206
247
  describe "add_show_field" do
@@ -235,6 +276,17 @@ describe "Blacklight::Configuration" do
235
276
  expect { @config.add_show_field(nil) }.to raise_error ArgumentError
236
277
  end
237
278
 
279
+ it "should take wild-carded field names and dereference them to solr fields" do
280
+ @config.stub(luke_fields: {
281
+ "some_field_display" => {},
282
+ "another_field_display" => {},
283
+ "a_facet_field" => {},
284
+ })
285
+ @config.add_show_field "*_display"
286
+
287
+ expect(@config.show_fields.keys).to eq ["some_field_display", "another_field_display"]
288
+ end
289
+
238
290
  end
239
291
 
240
292
 
@@ -263,7 +263,31 @@ describe 'Blacklight::SolrHelper' do
263
263
  end
264
264
  end
265
265
 
266
- describe "Allow passing :sort when defining facet" do
266
+ describe "#add_solr_fields_to_query" do
267
+ let(:blacklight_config) do
268
+ config = Blacklight::Configuration.new do |config|
269
+
270
+ config.add_index_field 'an_index_field', solr_params: { 'hl.alternativeField' => 'field_x'}
271
+ config.add_show_field 'a_show_field', solr_params: { 'hl.alternativeField' => 'field_y'}
272
+ config.add_field_configuration_to_solr_request!
273
+ end
274
+ end
275
+
276
+ subject do
277
+ solr_parameters = Blacklight::Solr::Request.new
278
+
279
+ add_solr_fields_to_query(solr_parameters, {})
280
+
281
+ solr_parameters
282
+ end
283
+
284
+ it "should add any extra solr parameters from index and show fields" do
285
+ expect(subject[:'f.an_index_field.hl.alternativeField']).to eq "field_x"
286
+ expect(subject[:'f.a_show_field.hl.alternativeField']).to eq "field_y"
287
+ end
288
+ end
289
+
290
+ describe "#add_facetting_to_solr" do
267
291
 
268
292
  let(:blacklight_config) do
269
293
  config = Blacklight::Configuration.new
@@ -271,12 +295,13 @@ describe 'Blacklight::SolrHelper' do
271
295
  config.add_facet_field 'test_field', :sort => 'count'
272
296
  config.add_facet_field 'some-query', :query => {'x' => {:fq => 'some:query' }}, :ex => 'xyz'
273
297
  config.add_facet_field 'some-pivot', :pivot => ['a','b'], :ex => 'xyz'
298
+ config.add_facet_field 'some-field', solr_params: { 'facet.mincount' => 15 }
274
299
  config.add_facet_fields_to_solr_request!
275
300
 
276
301
  config
277
302
  end
278
303
 
279
- it "should return the correct solr parameters" do
304
+ it "should add sort parameters" do
280
305
 
281
306
  solr_parameters = Blacklight::Solr::Request.new
282
307
 
@@ -296,6 +321,14 @@ describe 'Blacklight::SolrHelper' do
296
321
  expect(solr_parameters[:'facet.query']).to include('{!ex=xyz}some:query')
297
322
  expect(solr_parameters[:'facet.pivot']).to include('{!ex=xyz}a,b')
298
323
  end
324
+
325
+ it "should add any additional solr_params" do
326
+ solr_parameters = Blacklight::Solr::Request.new
327
+
328
+ add_facetting_to_solr(solr_parameters, {})
329
+
330
+ expect(solr_parameters[:'f.some-field.facet.mincount']).to eq 15
331
+ end
299
332
  end
300
333
 
301
334
  describe "with a complex parameter environment" do
@@ -1028,11 +1061,11 @@ describe 'Blacklight::SolrHelper' do
1028
1061
  # Okay, this is cheesy, since we included SolrHelper directly
1029
1062
  # into our example groups, we need to set an iVar here, so it will
1030
1063
  # use it.
1031
- @response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
1064
+ @response = double(params:{"facet.limit" => 11})
1032
1065
  expect(facet_limit_for("language_facet")).to eq 10
1033
1066
  end
1034
1067
  it "should get from specific field in @response if available" do
1035
- @response = {"responseHeader" => {"params" => {"facet.limit" => 11,"f.language_facet.facet.limit" => 16}}}
1068
+ @response = double(params: {"facet.limit" => 11,"f.language_facet.facet.limit" => 16})
1036
1069
  expect(facet_limit_for("language_facet")).to eq 15
1037
1070
  end
1038
1071
  end
@@ -0,0 +1,21 @@
1
+ platforms :jruby do
2
+ gem 'jdbc-sqlite3'
3
+ gem 'mediashelf-loggable', '>= 0.4.8'
4
+ gem 'therubyrhino'
5
+ end
6
+
7
+ platforms :ruby do
8
+ gem 'sqlite3'
9
+ end
10
+
11
+ gem 'jquery-rails'
12
+
13
+ group :test do
14
+ gem 'rspec-rails', '~> 2.13'
15
+ gem 'generator_spec'
16
+ gem 'poltergeist'
17
+ gem 'simplecov'
18
+ end
19
+
20
+ gem 'jettywrapper', '>= 1.2.0'
21
+
@@ -11,8 +11,13 @@ class TestAppGenerator < Rails::Generators::Base
11
11
  end
12
12
  end
13
13
 
14
+ def copy_blacklight_test_app_rake_task
15
+ copy_file "lib/tasks/blacklight_test_app.rake"
16
+ end
17
+
14
18
  def remove_index
15
19
  remove_file "public/index.html"
20
+ remove_file 'app/assets/images/rails.png'
16
21
  end
17
22
 
18
23
  def run_blacklight_generator
@@ -0,0 +1,14 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc "run the blacklight gem spec"
4
+ gem_home = File.expand_path('../../../../..', __FILE__)
5
+
6
+ namespace :blacklight_test_app do
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = gem_home + '/spec/**/*_spec.rb'
10
+ t.rspec_opts = "--colour"
11
+ t.ruby_opts = "-I#{gem_home}/spec"
12
+ end
13
+
14
+ end
@@ -14,7 +14,7 @@ describe "catalog/constraints" do
14
14
  end
15
15
 
16
16
  it "should render a start over link" do
17
- view.should_receive(:search_action_url).with({}).and_return('http://xyz')
17
+ view.should_receive(:search_action_path).with({}).and_return('http://xyz')
18
18
  view.stub(query_has_constraints?: true)
19
19
  view.stub(:blacklight_config).and_return(blacklight_config)
20
20
  render partial: "catalog/constraints"
@@ -23,7 +23,7 @@ describe "catalog/constraints" do
23
23
  end
24
24
 
25
25
  it "should render a start over link with the current view type" do
26
- view.should_receive(:search_action_url).with(view: :xyz).and_return('http://xyz?view=xyz')
26
+ view.should_receive(:search_action_path).with(view: :xyz).and_return('http://xyz?view=xyz')
27
27
  view.stub(query_has_constraints?: true)
28
28
  params[:view] = 'xyz'
29
29
  view.stub(:blacklight_config).and_return(blacklight_config)
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe "catalog/facet_layout" do
4
4
 
5
5
  let :blacklight_config do
6
- Blacklight::Configuration.new
6
+ Blacklight::Configuration.new do |config|
7
+ config.facet_fields[facet_field.field] = facet_field
8
+ end
7
9
  end
8
10
 
9
11
  let :facet_field do
@@ -1,60 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "catalog/_facets" do
4
+ let(:blacklight_config) { Blacklight::Configuration.new }
5
+
4
6
  before do
5
- @mock_config = Blacklight::Configuration.new
6
- view.stub(:blacklight_config => @mock_config)
7
- end
8
- it "should not have a header if no facets are displayed" do
9
- view.stub(:render_facet_partials => '')
10
- render
11
- expect(rendered).to_not have_selector('h4')
7
+ view.stub(blacklight_config: blacklight_config)
8
+ view.stub(:search_action_path) do |*args|
9
+ catalog_index_url *args
10
+ end
12
11
  end
13
12
 
14
- it "should have a header" do
15
-
16
- @mock_field_1 = double(:field => 'facet_field_1',
17
- :label => 'label')
18
- @mock_display_facet_1 = double(:name => 'facet_field_1', :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
19
- view.stub(:facet_field_names => [:facet_field_1],
20
- :facet_limit_for => 10 )
21
-
22
- @response = double()
23
- @response.stub(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
24
-
25
- view.stub(:render_facet_partials => '')
26
- render
27
- expect(rendered).to have_selector('h4')
13
+ context "without any facet fields" do
14
+ it "should not have a header if no facets are displayed" do
15
+ view.stub(:render_facet_partials => '')
16
+ render
17
+ expect(rendered).to_not have_selector('h4')
18
+ end
28
19
  end
20
+ context "with facet fields" do
21
+
22
+ let :facet_field do
23
+ Blacklight::Configuration::FacetField.new(field: 'facet_field_1', label: 'label').normalize!
24
+ end
29
25
 
30
- describe "facet display" do
31
26
  before do
32
- @mock_field_1 = double(:field => 'facet_field_1',
33
- :label => 'label')
34
- @mock_display_facet_1 = double(:name => 'facet_field_1', :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
35
- view.stub(:facet_field_names => [:facet_field_1],
36
- :facet_limit_for => 10 )
27
+ blacklight_config.facet_fields['facet_field_1'] = facet_field
37
28
 
38
- @response = double()
39
- @response.stub(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
29
+ @mock_display_facet_1 = double(:name => 'facet_field_1', sort: nil, offset: nil, :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
30
+ view.stub(:facet_field_names => [:facet_field_1],
31
+ :facet_limit_for => 10 )
40
32
 
41
- end
33
+ @response = double()
34
+ @response.stub(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
35
+ end
42
36
 
43
- it "should have a(n accessible) header" do
37
+ it "should have a header" do
38
+ view.stub(:render_facet_partials => '')
44
39
  render
45
- expect(rendered).to have_selector('h5')
40
+ expect(rendered).to have_selector('h4')
46
41
  end
47
42
 
48
- it "should list values" do
49
- render
50
43
 
51
- # The .facet-content class is used by blacklight_range_limit js, and
52
- # should be applied to the .panel-collapse div that contains the collapsible
53
- # facet content. Please make sure it remains if possible.
54
- expect(rendered).to have_selector('.facet-content a.facet_select')
55
- expect(rendered).to have_selector('.facet-content .facet-count')
56
- end
44
+ describe "facet display" do
45
+ it "should have a(n accessible) header" do
46
+ render
47
+ expect(rendered).to have_selector('h5')
48
+ end
49
+
50
+ it "should list values" do
51
+ render
57
52
 
53
+ # The .facet-content class is used by blacklight_range_limit js, and
54
+ # should be applied to the .panel-collapse div that contains the collapsible
55
+ # facet content. Please make sure it remains if possible.
56
+ expect(rendered).to have_selector('.facet-content a.facet_select')
57
+ expect(rendered).to have_selector('.facet-content .facet-count')
58
+ end
59
+ end
58
60
  end
59
61
  end
60
62
 
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'catalog/facet.html.erb' do
4
+ let(:display_facet) { double }
5
+ let(:blacklight_config) { Blacklight::Configuration.new }
6
+ before :each do
7
+ blacklight_config.add_facet_field 'xyz', label: "Facet title"
8
+ view.stub(:blacklight_config).and_return(blacklight_config)
9
+ stub_template 'catalog/_facet_pagination.html.erb' => 'pagination'
10
+ assign :facet, blacklight_config.facet_fields['xyz']
11
+ assign :display_facet, display_facet
12
+ end
13
+
14
+ it "should have the facet title" do
15
+ view.stub(:render_facet_limit)
16
+ render
17
+ expect(rendered).to have_selector 'h3', text: "Facet title"
18
+ end
19
+
20
+ it "should render facet pagination" do
21
+ view.stub(:render_facet_limit)
22
+ render
23
+ expect(rendered).to have_content 'pagination'
24
+ end
25
+
26
+ it "should render the facet limit" do
27
+ view.should_receive(:render_facet_limit).with(display_facet, layout: false)
28
+ render
29
+ end
30
+ 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: 5.0.3
4
+ version: 5.1.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: 2014-03-13 00:00:00.000000000 Z
20
+ date: 2014-02-13 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.0.6
84
+ - !ruby/object:Gem::Dependency
85
+ name: sass-rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: bootstrap-sass
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -151,34 +165,6 @@ dependencies:
151
165
  - - ">="
152
166
  - !ruby/object:Gem::Version
153
167
  version: '0'
154
- - !ruby/object:Gem::Dependency
155
- name: capybara
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: '0'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: '0'
168
- - !ruby/object:Gem::Dependency
169
- name: poltergeist
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- version: '0'
175
- type: :development
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- version: '0'
182
168
  - !ruby/object:Gem::Dependency
183
169
  name: engine_cart
184
170
  requirement: !ruby/object:Gem::Requirement
@@ -469,7 +455,9 @@ files:
469
455
  - spec/support/features.rb
470
456
  - spec/support/features/session_helpers.rb
471
457
  - spec/support/include_text.rb
458
+ - spec/test_app_templates/Gemfile.extra
472
459
  - spec/test_app_templates/lib/generators/test_app_generator.rb
460
+ - spec/test_app_templates/lib/tasks/blacklight_test_app.rake
473
461
  - spec/views/catalog/_constraints.html.erb_spec.rb
474
462
  - spec/views/catalog/_constraints_element.html.erb_spec.rb
475
463
  - spec/views/catalog/_document.html.erb_spec.rb
@@ -485,9 +473,9 @@ files:
485
473
  - spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
486
474
  - spec/views/catalog/_thumbnail_default.erb_spec.rb
487
475
  - spec/views/catalog/_view_type_group.html.erb_spec.rb
476
+ - spec/views/catalog/facet.html.erb_spec.rb
488
477
  - spec/views/catalog/index.atom.builder_spec.rb
489
478
  - spec/views/catalog/index.html.erb_spec.rb
490
- - spec/views/catalog/opensearch.xml.builder_spec.rb
491
479
  - spec/views/catalog/show.html.erb_spec.rb
492
480
  - tasks/blacklight.rake
493
481
  homepage: http://projectblacklight.org/
@@ -510,7 +498,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
510
498
  version: '0'
511
499
  requirements: []
512
500
  rubyforge_project:
513
- rubygems_version: 2.2.2
501
+ rubygems_version: 2.2.0
514
502
  signing_key:
515
503
  specification_version: 4
516
504
  summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
@@ -572,7 +560,9 @@ test_files:
572
560
  - spec/support/features.rb
573
561
  - spec/support/features/session_helpers.rb
574
562
  - spec/support/include_text.rb
563
+ - spec/test_app_templates/Gemfile.extra
575
564
  - spec/test_app_templates/lib/generators/test_app_generator.rb
565
+ - spec/test_app_templates/lib/tasks/blacklight_test_app.rake
576
566
  - spec/views/catalog/_constraints.html.erb_spec.rb
577
567
  - spec/views/catalog/_constraints_element.html.erb_spec.rb
578
568
  - spec/views/catalog/_document.html.erb_spec.rb
@@ -588,7 +578,7 @@ test_files:
588
578
  - spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
589
579
  - spec/views/catalog/_thumbnail_default.erb_spec.rb
590
580
  - spec/views/catalog/_view_type_group.html.erb_spec.rb
581
+ - spec/views/catalog/facet.html.erb_spec.rb
591
582
  - spec/views/catalog/index.atom.builder_spec.rb
592
583
  - spec/views/catalog/index.html.erb_spec.rb
593
- - spec/views/catalog/opensearch.xml.builder_spec.rb
594
584
  - spec/views/catalog/show.html.erb_spec.rb