blacklight 3.6.1.1 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/VERSION +1 -1
  2. data/app/controllers/bookmarks_controller.rb +28 -46
  3. data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -11
  4. data/app/helpers/blacklight/facets_helper_behavior.rb +57 -4
  5. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +4 -1
  6. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +5 -3
  7. data/app/views/_user_util_links.html.erb +8 -7
  8. data/app/views/bookmarks/index.html.erb +1 -1
  9. data/app/views/catalog/_bookmark_control.html.erb +2 -2
  10. data/lib/blacklight/configuration.rb +14 -1
  11. data/lib/blacklight/configuration/facet_field.rb +14 -0
  12. data/lib/blacklight/controller.rb +44 -7
  13. data/lib/blacklight/routes.rb +1 -10
  14. data/lib/blacklight/solr_helper.rb +60 -17
  15. data/lib/generators/blacklight/blacklight_generator.rb +1 -0
  16. data/lib/generators/blacklight/templates/catalog_controller.rb +11 -6
  17. data/test_support/bin/test.sh +1 -0
  18. data/test_support/features/bookmarks.feature +9 -19
  19. data/test_support/spec/controllers/application_controller_spec.rb +1 -0
  20. data/test_support/spec/controllers/bookmarks_controller_spec.rb +48 -0
  21. data/test_support/spec/controllers/catalog_controller_spec.rb +2 -1
  22. data/test_support/spec/controllers/search_history_controller_spec.rb +2 -0
  23. data/test_support/spec/helpers/blacklight_helper_spec.rb +1 -2
  24. data/test_support/spec/helpers/facets_helper_spec.rb +91 -4
  25. data/test_support/spec/helpers/search_history_constraints_helper_spec.rb +3 -0
  26. data/test_support/spec/lib/solr_helper_spec.rb +56 -8
  27. metadata +6 -9
  28. data/app/controllers/folder_controller.rb +0 -54
  29. data/app/views/catalog/_folder_control.html.erb +0 -12
  30. data/test_support/features/folder.feature +0 -67
  31. data/test_support/features/step_definitions/folder_steps.rb +0 -27
  32. data/test_support/spec/controllers/folder_controller_spec.rb +0 -47
@@ -12,6 +12,9 @@ describe SearchHistoryConstraintsHelper do
12
12
  end
13
13
  end
14
14
 
15
+ before(:each) do
16
+ helper.stub(:blacklight_config).and_return(@config)
17
+ end
15
18
 
16
19
  describe "render_search_to_s_*" do
17
20
  describe "render_search_to_s_element" do
@@ -79,7 +79,8 @@ describe 'Blacklight::SolrHelper' do
79
79
  @produced_params[:rows].should == 10
80
80
  end
81
81
  it 'should have default facet fields' do
82
- @produced_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
82
+ # remove local params from the facet.field
83
+ @produced_params[:"facet.field"].map { |x| x.gsub(/\{![^}]+\}/, '') }.should == blacklight_config.facet_fields_to_add_to_solr
83
84
  end
84
85
 
85
86
  it "should have default qt" do
@@ -116,7 +117,6 @@ describe 'Blacklight::SolrHelper' do
116
117
 
117
118
  solr_params[:q].should be_blank
118
119
  solr_params["spellcheck.q"].should be_blank
119
- solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
120
120
 
121
121
  @single_facet.each_value do |value|
122
122
  solr_params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
@@ -154,7 +154,12 @@ describe 'Blacklight::SolrHelper' do
154
154
  end
155
155
  end
156
156
 
157
- describe "facet_value_to_fq_string", :focus => true do
157
+ describe "facet_value_to_fq_string" do
158
+
159
+ let :blacklight_config do
160
+ Blacklight::Configuration.new
161
+ end
162
+
158
163
  it "should use the raw handler for strings" do
159
164
  facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name}my value"
160
165
  end
@@ -183,9 +188,22 @@ describe 'Blacklight::SolrHelper' do
183
188
  facet_value_to_fq_string("facet_name", "1.11").should == "facet_name:1.11"
184
189
  end
185
190
 
191
+ it "should pass date-type fields through" do
192
+ blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(mock(:date => true, :query => nil, :tag => nil))
193
+
194
+ facet_value_to_fq_string("facet_name", "2012-01-01").should == "facet_name:2012-01-01"
195
+ end
196
+
186
197
  it "should handle range requests" do
187
198
  facet_value_to_fq_string("facet_name", 1..5).should == "facet_name:[1 TO 5]"
188
199
  end
200
+
201
+ it "should add tag local parameters" do
202
+ blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(mock(:query => nil, :tag => 'asdf', :date => nil))
203
+
204
+ facet_value_to_fq_string("facet_name", true).should == "{!tag=asdf}facet_name:true"
205
+ facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name tag=asdf}my value"
206
+ end
189
207
  end
190
208
 
191
209
  describe "solr parameters for a field search from config (subject)" do
@@ -213,9 +231,7 @@ describe 'Blacklight::SolrHelper' do
213
231
  it "should include spellcheck.q, without LocalParams" do
214
232
  @solr_params["spellcheck.q"].should == "wome"
215
233
  end
216
- it "should include facet.field from default_solr_params" do
217
- @solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
218
- end
234
+
219
235
  it "should include spellcheck.dictionary from field def solr_parameters" do
220
236
  @solr_params[:"spellcheck.dictionary"].should == "subject"
221
237
  end
@@ -241,6 +257,38 @@ describe 'Blacklight::SolrHelper' do
241
257
  end
242
258
  end
243
259
 
260
+ describe "converts a String fq into an Array" do
261
+ it "should return the correct overriden parameter" do
262
+ solr_parameters = {:fq => 'a string' }
263
+
264
+ add_facet_fq_to_solr(solr_parameters, {})
265
+
266
+ solr_parameters[:fq].should be_a_kind_of Array
267
+ end
268
+ end
269
+
270
+ describe "Allow passing :sort when defining facet" do
271
+
272
+ let(:blacklight_config) do
273
+ config = Blacklight::Configuration.new
274
+
275
+ config.add_facet_field 'test_field', :sort => 'count'
276
+ config.add_facet_fields_to_solr_request!
277
+
278
+ config
279
+ end
280
+
281
+ it "should return the correct solr parameters" do
282
+
283
+ solr_parameters = { }
284
+
285
+ add_facetting_to_solr(solr_parameters, {})
286
+
287
+ solr_parameters[:'facet.field'].should include('test_field')
288
+ solr_parameters[:'f.test_field.facet.sort'].should == 'count'
289
+ end
290
+ end
291
+
244
292
  describe "with a complex parameter environment" do
245
293
  def blacklight_config
246
294
  config = Blacklight::Configuration.new
@@ -610,7 +658,7 @@ describe 'Blacklight::SolrHelper' do
610
658
  @facets.size.should > 1
611
659
  end
612
660
  it 'should have all facets specified in initializer' do
613
- blacklight_config[:default_solr_params][:"facet.field"].each do |field|
661
+ blacklight_config.facet_fields_to_add_to_solr.each do |field|
614
662
  @facets.find {|f| f.name == field}.should_not be_nil
615
663
  end
616
664
  end
@@ -869,7 +917,7 @@ describe 'Blacklight::SolrHelper' do
869
917
  end
870
918
  it "should handle no facet_limits in config" do
871
919
  def blacklight_config
872
- config = super.inheritable_copy
920
+ config = Blacklight::Configuration.new
873
921
  config.facet_fields = {}
874
922
  return config
875
923
  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: 3.6.1.1
4
+ version: 3.7.0
5
5
  prerelease:
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-09-19 00:00:00.000000000 Z
20
+ date: 2012-09-25 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -274,7 +274,6 @@ files:
274
274
  - app/controllers/bookmarks_controller.rb
275
275
  - app/controllers/catalog_controller.rb
276
276
  - app/controllers/feedback_controller.rb
277
- - app/controllers/folder_controller.rb
278
277
  - app/controllers/saved_searches_controller.rb
279
278
  - app/controllers/search_history_controller.rb
280
279
  - app/helpers/blacklight/blacklight_helper_behavior.rb
@@ -311,7 +310,6 @@ files:
311
310
  - app/views/catalog/_facet_limit.html.erb
312
311
  - app/views/catalog/_facet_pagination.html.erb
313
312
  - app/views/catalog/_facets.html.erb
314
- - app/views/catalog/_folder_control.html.erb
315
313
  - app/views/catalog/_home.html.erb
316
314
  - app/views/catalog/_home_text.html.erb
317
315
  - app/views/catalog/_index_default.html.erb
@@ -365,6 +363,7 @@ files:
365
363
  - lib/blacklight/catalog.rb
366
364
  - lib/blacklight/configurable.rb
367
365
  - lib/blacklight/configuration.rb
366
+ - lib/blacklight/configuration/facet_field.rb
368
367
  - lib/blacklight/configuration/fields.rb
369
368
  - lib/blacklight/configuration/search_field.rb
370
369
  - lib/blacklight/configuration/solr_field.rb
@@ -428,7 +427,6 @@ files:
428
427
  - test_support/data/test_data.utf8.mrc
429
428
  - test_support/features/bookmarks.feature
430
429
  - test_support/features/did_you_mean.feature
431
- - test_support/features/folder.feature
432
430
  - test_support/features/librarian_view.feature
433
431
  - test_support/features/record_view.feature
434
432
  - test_support/features/saved_searches.feature
@@ -439,7 +437,6 @@ files:
439
437
  - test_support/features/search_sort.feature
440
438
  - test_support/features/step_definitions/bookmarks_steps.rb
441
439
  - test_support/features/step_definitions/error_steps.rb
442
- - test_support/features/step_definitions/folder_steps.rb
443
440
  - test_support/features/step_definitions/general_steps.rb
444
441
  - test_support/features/step_definitions/record_view_steps.rb
445
442
  - test_support/features/step_definitions/saved_searches_steps.rb
@@ -453,8 +450,8 @@ files:
453
450
  - test_support/features/support/paths.rb
454
451
  - test_support/features/support/selectors.rb
455
452
  - test_support/spec/controllers/application_controller_spec.rb
453
+ - test_support/spec/controllers/bookmarks_controller_spec.rb
456
454
  - test_support/spec/controllers/catalog_controller_spec.rb
457
- - test_support/spec/controllers/folder_controller_spec.rb
458
455
  - test_support/spec/controllers/search_history_controller_spec.rb
459
456
  - test_support/spec/data/sample_docs.yml
460
457
  - test_support/spec/data/test_data.utf8.mrc
@@ -511,7 +508,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
511
508
  version: '0'
512
509
  segments:
513
510
  - 0
514
- hash: -3828227521653845396
511
+ hash: -1006739623696902057
515
512
  required_rubygems_version: !ruby/object:Gem::Requirement
516
513
  none: false
517
514
  requirements:
@@ -520,7 +517,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
520
517
  version: '0'
521
518
  segments:
522
519
  - 0
523
- hash: -3828227521653845396
520
+ hash: -1006739623696902057
524
521
  requirements: []
525
522
  rubyforge_project: blacklight
526
523
  rubygems_version: 1.8.23
@@ -1,54 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- class FolderController < ApplicationController
3
- include Blacklight::Configurable
4
- include Blacklight::SolrHelper
5
-
6
- copy_blacklight_config_from(CatalogController)
7
-
8
- helper CatalogHelper
9
-
10
- # fetch the documents that match the ids in the folder
11
- def index
12
- @response, @documents = get_solr_response_for_field_values(SolrDocument.unique_key,session[:folder_document_ids] || [])
13
- end
14
-
15
-
16
- # add a document_id to the folder. :id of action is solr doc id
17
- def update
18
- session[:folder_document_ids] = session[:folder_document_ids] || []
19
- session[:folder_document_ids] << params[:id]
20
- # Rails 3 uses a one line notation for setting the flash notice.
21
- # flash[:notice] = "#{params[:title] || "Item"} successfully added to Folder"
22
- respond_to do |format|
23
- format.html { redirect_to :back, :notice => I18n.t('blacklight.folder.add.success', :title => params[:title] || 'Item') }
24
- format.js { render :json => session[:folder_document_ids] }
25
- end
26
- end
27
-
28
- # remove a document_id from the folder. :id of action is solr_doc_id
29
- def destroy
30
- session[:folder_document_ids].delete(params[:id])
31
-
32
- respond_to do |format|
33
- format.html do
34
- flash[:notice] = I18n.t('blacklight.folder.remove.success', :title => params[:title] || 'Item')
35
- redirect_to :back
36
- end
37
- format.js do
38
- render :json => {"OK" => "OK"}
39
- end
40
- end
41
-
42
- end
43
-
44
- # get rid of the items in the folder
45
- def clear
46
- flash[:notice] = I18n.t('blacklight.folder.clear.success')
47
- session[:folder_document_ids] = []
48
- respond_to do |format|
49
- format.html { redirect_to :back }
50
- format.js { render :json => session[:folder_document_ids] }
51
- end
52
- end
53
-
54
- end
@@ -1,12 +0,0 @@
1
- <%-
2
- # pass in local :document with a SolrDocument
3
- method = (item_in_folder?(document.id) ? "delete" : "put")
4
- label = (item_in_folder?(document.id) ? t('blacklight.search.folder.unselect') : t('blacklight.search.folder.select'))
5
- cssClass = (item_in_folder?(document.id) ? "deleteFolder" : "addFolder")
6
- -%>
7
-
8
- <%= form_tag( folder_path(document), :method => method, :class=> "folder_toggle #{cssClass}", "data-doc-id" => document.id, :title=>h(document[document_show_link_field])) do -%>
9
- <%= hidden_field(:bookmark, :title, :value => document[document_show_link_field]) %>
10
- <%= submit_tag(label, :class=>"folder_submit", :id => "folder_submit_#{document.id}") %>
11
- <% end %>
12
-
@@ -1,67 +0,0 @@
1
- Feature: User Folder
2
- In order to keep track of items
3
- As a user
4
- I want to be able to store items in my folder
5
-
6
- Scenario: Ensure "Add to Folder" form is present in search results
7
- Given I am on the home page
8
- When I fill in "q" with "history"
9
- And I select "All Fields" from "search_field"
10
- And I press "search"
11
- Then I should see an add to folder form
12
-
13
- Scenario: Ensure "Add to Folder" for is present on individual record
14
- Given I am on the document page for id 2007020969
15
- Then I should see an add to folder form
16
-
17
- Scenario: Adding an item to the folder should produce a status message
18
- Given I am on the home page
19
- And I follow "English"
20
- And I add record 2008308175 to my folder
21
- Then I should see "Selected Items (1)"
22
-
23
- Scenario: Do not show "Add to Favorites" when not logged in
24
- Given I have record 2007020969 in my folder
25
- When I follow "Selected Items"
26
- Then I should not see "Add to Folder"
27
-
28
- Scenario: Show "Add to Favorites" when logged in and viewing folder
29
- Given I am logged in as "user1"
30
- And I have record 2007020969 in my folder
31
- When I follow "Selected Items"
32
- Then I should see "Add to Bookmarks"
33
-
34
- Scenario: Do multiple citations when the folder has multiple items
35
- Given I have record 2007020969 in my folder
36
- And I have record 2008308175 in my folder
37
- When I follow "Selected Items"
38
- And I follow "Cite"
39
- Then I should see "Pluvial Nectar of Blessings : a Supplication to the Noble Lama Mahaguru Padmasambhava. Dharamsala: Library of Tibetan Works and Archives, 2002."
40
- And I should see "a Native American elder has her say : an oral history. 1st Atria Books hardcover ed. New York: Atria Books."
41
-
42
- Scenario: Make sure the folder page doesn't bomb if there is no search session
43
- Given I am on the folder page
44
- # That's all that is needed -- it will fail to render if it's not right
45
-
46
- Scenario: Don't show the tools if there are no items in the folder
47
- Given I am on the folder page
48
- Then I should not see the Folder tools
49
-
50
- Scenario: Show the tools if there are items in the folder
51
- Given I have record 2008308175 in my folder
52
- And I follow "Selected Items"
53
- Then I should see the Folder tools
54
-
55
- Scenario: Controls on the record view
56
- When I am on the document page for id 2008308175
57
- Then I should see an add to folder form
58
- Given I have record 2008308175 in my folder
59
- When I am on the document page for id 2008308175
60
- Then I should see a remove from folder form
61
-
62
- Scenario: Controls on the folder view
63
- Given I have record 2008308175 in my folder
64
- When I am on the folder page
65
- Then I should see a remove from folder form
66
- When I remove record 2008308175 from my folder
67
- Then I should not see the Folder tools
@@ -1,27 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- Then /^I should see an add to folder form$/ do
3
- page.should have_selector("form.addFolder")
4
- end
5
-
6
- Then /^I should see a remove from folder form$/ do
7
- page.should have_selector("form.deleteFolder")
8
- end
9
-
10
- When /^I (add|remove) record (.+) (to|from) my folder$/ do |add_or_remove, id, wording|
11
- click_button("folder_submit_#{id}")
12
- end
13
-
14
- Given /^I have record (.+) in my folder$/ do |arg1|
15
- visit catalog_path(arg1)
16
- click_button("Select")
17
- click_link("Selected Items")
18
- end
19
-
20
- Then /^I (should|should not) see the Folder tools$/ do |comparator|
21
- case comparator
22
- when "should"
23
- page.should have_selector("ul.folderTools")
24
- when "should not"
25
- page.should_not have_selector("ul.folderTools")
26
- end
27
- end
@@ -1,47 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
- describe FolderController do
4
- before(:each) do
5
- request.env["HTTP_REFERER"] = "/"
6
- end
7
-
8
- it "should add items to list" do
9
- @mock_response = mock()
10
- @mock_document = mock()
11
- @mock_document2 = mock()
12
- @mock_document.stub(:export_formats => {})
13
- controller.stub(:get_solr_response_for_field_values => [@mock_response, [@mock_document, @mock_document2]])
14
-
15
- get :update, :id =>"77826928"
16
- session[:folder_document_ids].length.should == 1
17
- get :update, :id => "94120425"
18
- session[:folder_document_ids].length.should == 2
19
- session[:folder_document_ids].should include("77826928")
20
- get :index
21
- assigns[:documents].length.should == 2
22
- assigns[:documents].first.should == @mock_document
23
- end
24
- it "should delete an item from list" do
25
- get :update, :id =>"77826928"
26
- get :update, :id => "94120425"
27
- get :destroy, :id =>"77826928"
28
- session[:folder_document_ids].length.should == 1
29
- session[:folder_document_ids].should_not include("77826928")
30
- end
31
- it "should clear list" do
32
- get :update, :id =>"77826928"
33
- get :update, :id => "94120425"
34
- get :clear
35
- session[:folder_document_ids].length.should == 0
36
- end
37
-
38
- it "should generate flash messages for normal requests" do
39
- get :update, :id => "77826928"
40
- flash[:notice].length.should_not == 0
41
- end
42
- it "should clear flash messages after xhr request" do
43
- xhr :get, :update, :id => "77826928"
44
- flash[:notice].should == nil
45
- end
46
- end
47
-