blacklight 4.0.0.pre7 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/.gitignore +1 -1
  2. data/VERSION +1 -1
  3. data/app/assets/stylesheets/blacklight/_catalog.css.scss +3 -3
  4. data/app/assets/stylesheets/blacklight/_dropdown.css.scss +0 -1
  5. data/app/assets/stylesheets/blacklight/_facets.css.scss +48 -43
  6. data/app/helpers/blacklight/blacklight_helper_behavior.rb +13 -11
  7. data/app/helpers/blacklight/catalog_helper_behavior.rb +45 -29
  8. data/app/helpers/blacklight/facets_helper_behavior.rb +74 -14
  9. data/app/views/_user_util_links.html.erb +1 -1
  10. data/app/views/catalog/_facet_pivot.html.erb +16 -0
  11. data/app/views/catalog/_per_page_widget.html.erb +5 -3
  12. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  13. data/app/views/catalog/_sort_widget.html.erb +3 -1
  14. data/app/views/catalog/index.html.erb +3 -4
  15. data/config/locales/blacklight.en.yml +3 -3
  16. data/lib/blacklight.rb +1 -0
  17. data/lib/blacklight/catalog.rb +1 -1
  18. data/lib/blacklight/configuration.rb +5 -4
  19. data/lib/blacklight/controller.rb +16 -72
  20. data/lib/blacklight/legacy_controller_methods.rb +69 -0
  21. data/lib/blacklight/solr_helper.rb +14 -8
  22. data/lib/blacklight/solr_response/facets.rb +24 -5
  23. data/lib/generators/blacklight/blacklight_generator.rb +2 -1
  24. data/lib/generators/blacklight/templates/catalog_controller.rb +1 -0
  25. data/test_support/spec/helpers/blacklight_helper_spec.rb +18 -1
  26. data/test_support/spec/helpers/facets_helper_spec.rb +63 -0
  27. data/test_support/spec/lib/blacklight_solr_response_spec.rb +35 -0
  28. data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +2 -2
  29. metadata +5 -3
@@ -141,7 +141,8 @@ EOF
141
141
  " # Adds a few additional behaviors into the application controller \n " +
142
142
  " include Blacklight::Controller\n" +
143
143
  " # Please be sure to impelement current_user and user_session. Blacklight depends on \n" +
144
- " # these methods in order to perform user specific actions. \n\n"
144
+ " # these methods in order to perform user specific actions. \n\n" +
145
+ " layout 'blacklight'\n\n"
145
146
  end
146
147
  end
147
148
 
@@ -59,6 +59,7 @@ class CatalogController < ApplicationController
59
59
  config.add_facet_field 'subject_geo_facet', :label => 'Region'
60
60
  config.add_facet_field 'subject_era_facet', :label => 'Era'
61
61
 
62
+ config.add_facet_field 'example_pivot_field', :label => 'Pivot Field', :pivot => ['format', 'language_facet']
62
63
 
63
64
  config.add_facet_field 'example_query_facet_field', :label => 'Publish Date', :query => {
64
65
  :years_5 => { :label => 'within 5 Years', :fq => "pub_date:[#{Time.now.year - 5 } TO *]" },
@@ -216,9 +216,22 @@ describe BlacklightHelper do
216
216
  it "should consist of #document_heading wrapped in a <h1>" do
217
217
  @document = SolrDocument.new('title_display' => "A Fake Document")
218
218
 
219
- render_document_heading.should have_selector("h4", :text => document_heading, :count => 1)
219
+ render_document_heading.should have_selector("h4", :text => "A Fake Document", :count => 1)
220
220
  render_document_heading.html_safe?.should == true
221
221
  end
222
+ it "should join the values if it is an array" do
223
+ @document = SolrDocument.new('title_display' => ["A Fake Document", 'Something Else'])
224
+
225
+ render_document_heading.should have_selector("h4", :text => "A Fake Document, Something Else", :count => 1)
226
+ render_document_heading.html_safe?.should == true
227
+ end
228
+ end
229
+
230
+ describe "document_show_html_title" do
231
+ it "should join the values if it is an array" do
232
+ @document = SolrDocument.new('title_display' => ["A Fake Document", 'Something Else'])
233
+ document_show_html_title.should == "A Fake Document, Something Else"
234
+ end
222
235
  end
223
236
 
224
237
  describe "document_index_view_type" do
@@ -227,8 +240,12 @@ describe BlacklightHelper do
227
240
  end
228
241
 
229
242
  it "should pluck values out of params" do
243
+ blacklight_config.stub(:document_index_view_types) { ['list', 'asdf'] }
230
244
  params[:view] = 'asdf'
231
245
  document_index_view_type.should == 'asdf'
246
+
247
+ params[:view] = 'not_in_list'
248
+ document_index_view_type.should == 'list'
232
249
  end
233
250
  end
234
251
 
@@ -107,6 +107,32 @@ describe FacetsHelper do
107
107
  facet_item.label.should == 'A Human Readable label'
108
108
  end
109
109
  end
110
+
111
+ describe "pivot facets" do
112
+ let(:facet_config) {
113
+ mock(:pivot => ['field_a', 'field_b'])
114
+ }
115
+
116
+ before(:each) do
117
+ helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
118
+
119
+ @response = mock(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
120
+ end
121
+
122
+ it "should convert the pivot facet into a mock RSolr FacetField" do
123
+ field = helper.facet_by_field_name('my_pivot_facet_field')
124
+ field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
125
+
126
+ field.name.should == 'my_pivot_facet_field'
127
+
128
+ field.items.length.should == 1
129
+
130
+ field.items.first.should respond_to(:items)
131
+
132
+ field.items.first.items.length.should == 1
133
+ field.items.first.items.first.fq.should == { 'field_a' => 'a' }
134
+ end
135
+ end
110
136
  end
111
137
 
112
138
 
@@ -143,6 +169,8 @@ describe FacetsHelper do
143
169
 
144
170
  @config = Blacklight::Configuration.new do |config|
145
171
  config.add_facet_field 'basic_field'
172
+ config.add_facet_field 'pivot_facet_field', :pivot => ['a', 'b']
173
+ config.add_facet_field 'my_pivot_facet_field_with_custom_partial', :partial => 'custom_facet_partial', :pivot => ['a', 'b']
146
174
  config.add_facet_field 'my_facet_field_with_custom_partial', :partial => 'custom_facet_partial'
147
175
  end
148
176
 
@@ -191,6 +219,18 @@ describe FacetsHelper do
191
219
  helper.should_receive(:render).with(hash_including(:layout => nil))
192
220
  helper.render_facet_limit(@mock_facet, :layout => nil)
193
221
  end
222
+
223
+ it "should render the facet_pivot partial for pivot facets" do
224
+ @mock_facet = mock(:name => 'pivot_facet_field', :items => [1,2,3])
225
+ helper.should_receive(:render).with(hash_including(:partial => 'facet_pivot'))
226
+ helper.render_facet_limit(@mock_facet)
227
+ end
228
+
229
+ it "should let you override the rendered partial for pivot facets" do
230
+ @mock_facet = mock(:name => 'my_pivot_facet_field_with_custom_partial', :items => [1,2,3])
231
+ helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
232
+ helper.render_facet_limit(@mock_facet)
233
+ end
194
234
  end
195
235
 
196
236
  describe "add_facet_params" do
@@ -249,6 +289,29 @@ describe FacetsHelper do
249
289
  result_params[:f]['single_value_facet_field'].length.should == 1
250
290
  result_params[:f]['single_value_facet_field'].first.should == 'my_value'
251
291
  end
292
+
293
+ it "should accept a FacetItem instead of a plain facet value" do
294
+
295
+ result_params = helper.add_facet_params('facet_field_1', mock(:value => 123))
296
+
297
+ result_params[:f]['facet_field_1'].should include(123)
298
+ end
299
+
300
+ it "should defer to the field set on a FacetItem" do
301
+
302
+ result_params = helper.add_facet_params('facet_field_1', mock(:field => 'facet_field_2', :value => 123))
303
+
304
+ result_params[:f]['facet_field_1'].should be_blank
305
+ result_params[:f]['facet_field_2'].should include(123)
306
+ end
307
+
308
+ it "should add any extra fq parameters from the FacetItem" do
309
+
310
+ result_params = helper.add_facet_params('facet_field_1', mock(:value => 123, :fq => {'facet_field_2' => 'abc'}))
311
+
312
+ result_params[:f]['facet_field_1'].should include(123)
313
+ result_params[:f]['facet_field_2'].should include('abc')
314
+ end
252
315
  end
253
316
 
254
317
  describe "add_facet_params_and_redirect" do
@@ -60,6 +60,41 @@ describe Blacklight::SolrResponse do
60
60
 
61
61
  end
62
62
 
63
+ describe "FacetItem" do
64
+ it "should work with a field,value tuple" do
65
+ item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15)
66
+ item.value.should == 'value'
67
+ item.hits.should == 15
68
+ end
69
+
70
+ it "should work with a field,value + hash triple" do
71
+ item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15, :a => 1, :value => 'ignored')
72
+ item.value.should == 'value'
73
+ item.hits.should == 15
74
+ item.a.should == 1
75
+ end
76
+
77
+ it "should work like an openstruct" do
78
+ item = Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'value', :hits => 15)
79
+
80
+ item.hits.should == 15
81
+ item.value.should == 'value'
82
+ item.should be_a_kind_of(OpenStruct)
83
+ end
84
+
85
+ it "should provide a label accessor" do
86
+ item = Blacklight::SolrResponse::Facets::FacetItem.new('value', :hits => 15)
87
+ item.label.should == 'value'
88
+ end
89
+
90
+ it "should use a provided label" do
91
+ item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15, :label => 'custom label')
92
+ item.label.should == 'custom label'
93
+
94
+ end
95
+
96
+ end
97
+
63
98
  it 'should return the correct value when calling facet_by_field_name' do
64
99
  r = create_response
65
100
  facet = r.facet_by_field_name('cat')
@@ -15,7 +15,7 @@ describe "catalog/_facets" do
15
15
 
16
16
  @mock_field_1 = mock(:field => 'facet_field_1',
17
17
  :label => 'label')
18
- @mock_display_facet_1 = mock(:name => 'facet_field_1', :items => [mock(:value => 'Value', :hits => 1234)])
18
+ @mock_display_facet_1 = mock(:name => 'facet_field_1', :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
19
19
  view.stub(:facet_field_names => [:facet_field_1],
20
20
  :facet_limit_for => 10 )
21
21
 
@@ -31,7 +31,7 @@ describe "catalog/_facets" do
31
31
  before do
32
32
  @mock_field_1 = mock(:field => 'facet_field_1',
33
33
  :label => 'label')
34
- @mock_display_facet_1 = mock(:name => 'facet_field_1', :items => [mock(:value => 'Value', :hits => 1234)])
34
+ @mock_display_facet_1 = mock(:name => 'facet_field_1', :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
35
35
  view.stub(:facet_field_names => [:facet_field_1],
36
36
  :facet_limit_for => 10 )
37
37
 
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: 4.0.0.pre7
4
+ version: 4.0.0.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2012-11-20 00:00:00.000000000 Z
20
+ date: 2012-11-29 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -252,6 +252,7 @@ files:
252
252
  - app/views/catalog/_facet_layout.html.erb
253
253
  - app/views/catalog/_facet_limit.html.erb
254
254
  - app/views/catalog/_facet_pagination.html.erb
255
+ - app/views/catalog/_facet_pivot.html.erb
255
256
  - app/views/catalog/_facets.html.erb
256
257
  - app/views/catalog/_home.html.erb
257
258
  - app/views/catalog/_home_text.html.erb
@@ -322,6 +323,7 @@ files:
322
323
  - lib/blacklight/controller.rb
323
324
  - lib/blacklight/engine.rb
324
325
  - lib/blacklight/exceptions.rb
326
+ - lib/blacklight/legacy_controller_methods.rb
325
327
  - lib/blacklight/mash.rb
326
328
  - lib/blacklight/routes.rb
327
329
  - lib/blacklight/search_fields.rb
@@ -465,7 +467,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
465
467
  version: '0'
466
468
  segments:
467
469
  - 0
468
- hash: 1421767879458885450
470
+ hash: 4562410494290204402
469
471
  required_rubygems_version: !ruby/object:Gem::Requirement
470
472
  none: false
471
473
  requirements: