blacklight 4.9.0 → 5.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +22 -12
- data/Gemfile +3 -40
- data/LICENSE +1 -2
- data/README.md +1 -2
- data/Rakefile +0 -4
- data/VERSION +1 -1
- data/app/assets/images/blacklight/logo.png +0 -0
- data/app/assets/javascripts/blacklight/ajax_modal.js +190 -0
- data/app/assets/javascripts/blacklight/blacklight.js +7 -17
- data/app/assets/javascripts/blacklight/checkbox_submit.js +1 -1
- data/app/assets/stylesheets/blacklight/{_blacklight_base.scss → _blacklight_base.css.scss} +0 -21
- data/app/assets/stylesheets/blacklight/_bookmark.css.scss +4 -0
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +192 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +141 -0
- data/app/assets/stylesheets/blacklight/{_group.scss → _group.css.scss} +1 -1
- data/app/assets/stylesheets/blacklight/_header.css.scss +44 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +5 -0
- data/app/assets/stylesheets/blacklight/{_modal.scss → _modal.css.scss} +7 -7
- data/app/assets/stylesheets/blacklight/_search_history.css.scss +20 -0
- data/app/assets/stylesheets/blacklight/{blacklight.scss → blacklight.css.scss} +0 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +14 -0
- data/app/controllers/bookmarks_controller.rb +0 -4
- data/app/controllers/feedback_controller.rb +0 -4
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +45 -155
- data/app/helpers/blacklight/catalog_helper_behavior.rb +8 -41
- data/app/helpers/blacklight/facets_helper_behavior.rb +20 -43
- data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +2 -9
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +9 -14
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +6 -6
- data/app/views/_flash_msg.html.erb +9 -2
- data/app/views/_user_util_links.html.erb +29 -15
- data/app/views/bookmarks/_tools.html.erb +4 -7
- data/app/views/bookmarks/index.html.erb +3 -2
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_constraints.html.erb +1 -1
- data/app/views/catalog/_constraints_element.html.erb +12 -8
- data/app/views/catalog/_did_you_mean.html.erb +2 -2
- data/app/views/catalog/_document_header.html.erb +3 -3
- data/app/views/catalog/_email_form.html.erb +10 -10
- data/app/views/catalog/_facet_layout.html.erb +11 -3
- data/app/views/catalog/_facet_limit.html.erb +7 -7
- data/app/views/catalog/_facet_pagination.html.erb +8 -7
- data/app/views/catalog/_facet_pivot.html.erb +3 -1
- data/app/views/catalog/_facets.html.erb +12 -9
- data/app/views/catalog/_paginate_compact.html.erb +1 -7
- data/app/views/catalog/_per_page_widget.html.erb +5 -8
- data/app/views/catalog/_previous_next_doc.html.erb +11 -9
- data/app/views/catalog/_refworks_form.html.erb +3 -4
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +16 -14
- data/app/views/catalog/_show_sidebar.html.erb +7 -9
- data/app/views/catalog/_show_tools.html.erb +13 -7
- data/app/views/catalog/_sms_form.html.erb +8 -8
- data/app/views/catalog/_sort_and_per_page.html.erb +4 -6
- data/app/views/catalog/_sort_widget.html.erb +5 -6
- data/app/views/catalog/email.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +2 -8
- data/app/views/catalog/index.html.erb +11 -6
- data/app/views/catalog/show.html.erb +5 -5
- data/app/views/catalog/sms.html.erb +1 -1
- data/app/views/catalog/sms_sent.html.erb +1 -1
- data/app/views/feedback/complete.html.erb +2 -2
- data/app/views/feedback/show.html.erb +1 -1
- data/app/views/kaminari/blacklight/_paginator.html.erb +1 -1
- data/app/views/kaminari/blacklight_compact/_paginator.html.erb +25 -5
- data/app/views/layouts/blacklight.html.erb +23 -23
- data/app/views/saved_searches/index.html.erb +2 -2
- data/app/views/search_history/index.html.erb +5 -7
- data/app/views/shared/_header_navbar.html.erb +23 -23
- data/blacklight.gemspec +10 -13
- data/config/locales/blacklight.en.yml +1 -12
- data/config/locales/blacklight.fr.yml +1 -12
- data/gemfiles/rails3.gemfile +21 -0
- data/gemfiles/rails4.gemfile +20 -0
- data/lib/blacklight.rb +0 -8
- data/lib/blacklight/base.rb +0 -2
- data/lib/blacklight/catalog.rb +6 -32
- data/lib/blacklight/catalog/search_context.rb +8 -48
- data/lib/blacklight/configurable.rb +2 -1
- data/lib/blacklight/configuration.rb +1 -2
- data/lib/blacklight/configuration/facet_field.rb +0 -2
- data/lib/blacklight/engine.rb +3 -3
- data/lib/blacklight/legacy_controller_methods.rb +1 -64
- data/lib/blacklight/rails/routes.rb +17 -0
- data/lib/blacklight/routes.rb +46 -40
- data/lib/blacklight/solr.rb +1 -0
- data/lib/blacklight/solr/document.rb +21 -42
- data/lib/blacklight/solr/facet_paginator.rb +30 -54
- data/lib/blacklight/solr/request.rb +45 -0
- data/lib/blacklight/solr_helper.rb +16 -53
- data/lib/blacklight/solr_response.rb +0 -6
- data/lib/blacklight/user.rb +2 -7
- data/lib/blacklight/utils.rb +1 -9
- data/lib/generators/blacklight/assets_generator.rb +0 -14
- data/lib/generators/blacklight/blacklight_generator.rb +17 -14
- data/lib/generators/blacklight/templates/blacklight.css.scss +3 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +4 -1
- data/lib/railties/blacklight.rake +3 -1
- data/solr/sample_solr_documents.yml +641 -0
- data/spec/controllers/application_controller_spec.rb +5 -21
- data/spec/controllers/bookmarks_controller_spec.rb +11 -11
- data/spec/controllers/catalog_controller_spec.rb +122 -119
- data/spec/controllers/search_history_controller_spec.rb +8 -8
- data/spec/features/alternate_controller_spec.rb +5 -5
- data/spec/features/facets_spec.rb +9 -0
- data/spec/features/record_view_spec.rb +1 -1
- data/spec/features/search_filters_spec.rb +97 -41
- data/spec/features/search_results_spec.rb +14 -17
- data/spec/features/search_sort_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +170 -285
- data/spec/helpers/catalog_helper_spec.rb +57 -96
- data/spec/helpers/facets_helper_spec.rb +130 -152
- data/spec/helpers/hash_as_hidden_fields_spec.rb +9 -15
- data/spec/helpers/render_constraints_helper_spec.rb +5 -5
- data/spec/helpers/search_history_constraints_helper_spec.rb +21 -21
- data/spec/lib/blacklight/routes_spec.rb +25 -0
- data/spec/lib/blacklight/solr/request_spec.rb +37 -0
- data/spec/lib/blacklight/solr_response/group_response_spec.rb +2 -2
- data/spec/lib/blacklight_configurable_spec.rb +16 -16
- data/spec/lib/blacklight_configuration_spec.rb +132 -132
- data/spec/lib/blacklight_email_spec.rb +4 -4
- data/spec/lib/blacklight_sms_spec.rb +4 -4
- data/spec/lib/blacklight_solr_document_dublin_core_spec.rb +6 -6
- data/spec/lib/blacklight_solr_document_more_like_this_spec.rb +4 -4
- data/spec/lib/blacklight_solr_document_spec.rb +36 -36
- data/spec/lib/blacklight_solr_response_spec.rb +43 -48
- data/spec/lib/blacklight_spec.rb +6 -14
- data/spec/lib/blacklight_user_spec.rb +5 -9
- data/spec/lib/facet_paginator_spec.rb +59 -51
- data/spec/lib/search_fields_spec.rb +13 -13
- data/spec/lib/solr_helper_spec.rb +258 -304
- data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
- data/spec/lib/utils_spec.rb +16 -46
- data/spec/models/bookmark_spec.rb +6 -7
- data/spec/models/record_mailer_spec.rb +16 -16
- data/spec/models/search_spec.rb +8 -8
- data/spec/models/solr_document_spec.rb +6 -77
- data/spec/routing/catalog_routing_spec.rb +16 -10
- data/spec/spec_helper.rb +7 -7
- data/spec/support/assert_difference.rb +2 -2
- data/spec/support/features.rb +0 -11
- data/spec/support/features/session_helpers.rb +3 -3
- data/spec/support/include_text.rb +2 -2
- data/spec/test_app_templates/Gemfile.extra +10 -2
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -18
- data/spec/views/catalog/_constraints_element.html.erb_spec.rb +13 -13
- data/spec/views/catalog/_document.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facets.html.erb_spec.rb +13 -14
- data/spec/views/catalog/_index_default.erb_spec.rb +21 -21
- data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
- data/spec/views/catalog/_show_default.erb_spec.rb +21 -21
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +7 -7
- data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -3
- data/spec/views/catalog/index.atom.builder_spec.rb +29 -29
- data/spec/views/catalog/index.html.erb_spec.rb +6 -7
- data/tasks/blacklight.rake +8 -2
- metadata +84 -180
- data/app/assets/javascripts/blacklight/css_dropdowns.js +0 -10
- data/app/assets/javascripts/blacklight/facet_expand_contract.js +0 -41
- data/app/assets/javascripts/blacklight/lightbox_dialog.js +0 -70
- data/app/assets/javascripts/blacklight/select_submit.js +0 -27
- data/app/assets/javascripts/blacklight/zebra_stripe.js +0 -13
- data/app/assets/javascripts/improved-modal/bootstrap-modal.js +0 -355
- data/app/assets/javascripts/improved-modal/bootstrap-modalmanager.js +0 -370
- data/app/assets/stylesheets/blacklight/_bookmark.scss +0 -33
- data/app/assets/stylesheets/blacklight/_catalog.scss +0 -255
- data/app/assets/stylesheets/blacklight/_dropdown.scss +0 -57
- data/app/assets/stylesheets/blacklight/_facets.scss +0 -197
- data/app/assets/stylesheets/blacklight/_footer.scss +0 -0
- data/app/assets/stylesheets/blacklight/_header.scss +0 -53
- data/app/assets/stylesheets/blacklight/_layout.scss +0 -10
- data/app/assets/stylesheets/blacklight/_mixins.scss +0 -0
- data/app/assets/stylesheets/blacklight/_print.scss +0 -0
- data/app/assets/stylesheets/blacklight/_responsive.scss +0 -3
- data/app/assets/stylesheets/blacklight/_search_history.scss +0 -42
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -49
- data/app/assets/stylesheets/blacklight/responsive_partials/_catalog.scss +0 -5
- data/app/assets/stylesheets/blacklight/responsive_partials/_facets.scss +0 -37
- data/app/assets/stylesheets/blacklight/responsive_partials/_header.scss +0 -30
- data/app/assets/stylesheets/improved-modal/bootstrap-modal.css +0 -217
- data/app/helpers/blacklight/html_head_helper_behavior.rb +0 -118
- data/app/helpers/html_head_helper.rb +0 -3
- data/app/views/catalog/_bookmark_form.html.erb +0 -7
- data/app/views/catalog/_marc_view.html.erb +0 -32
- data/app/views/catalog/librarian_view.html.erb +0 -10
- data/config/routes.rb +0 -17
- data/doc/Atom-Responses.md +0 -90
- data/doc/Blacklight-3.0-Release-Notes-And-Upgrade-Guide.md +0 -107
- data/doc/Blacklight-3.2-Release-Notes-and-Upgrade-Guide.md +0 -191
- data/doc/Blacklight-3.3-release-notes-and-upgrade-guide.md +0 -37
- data/doc/Blacklight-3.4-release-notes-and-upgrade-guide.md +0 -27
- data/doc/Blacklight-3.5-release-notes-and-upgrade-guide.md +0 -44
- data/doc/Blacklight-3.6-release-notes-and-upgrade-guide.md +0 -25
- data/doc/Blacklight-3.7-release-notes-and-upgrade-guide.md +0 -80
- data/doc/Blacklight-3.8-release-notes-and-upgrade-guide.md +0 -11
- data/doc/Blacklight-4.0-release-notes-and-upgrade-guide.md +0 -135
- data/doc/Blacklight-4.1-release-notes-and-upgrade-guide.md +0 -17
- data/doc/Blacklight-4.2-release-notes-and-upgrade-guide.md +0 -25
- data/doc/Blacklight-4.3-release-notes-and-upgrade-guide.md +0 -21
- data/doc/Blacklight-4.4-release-notes-and-upgrade-guide.md +0 -41
- data/doc/Blacklight-Add-ons.md +0 -28
- data/doc/Blacklight-configuration.md +0 -411
- data/doc/Blacklight-on-Heroku.md +0 -135
- data/doc/Code4Lib-2014.md +0 -48
- data/doc/Community-principles.md +0 -44
- data/doc/Configuring-and-Customizing-Blacklight.md +0 -271
- data/doc/Configuring-rails-routes.md +0 -13
- data/doc/Contributing-to-Blacklight.md +0 -25
- data/doc/Examples.md +0 -94
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
- data/doc/FAQs.md +0 -1
- data/doc/Home.md +0 -80
- data/doc/How-to-release-a-version.md +0 -29
- data/doc/Indexing-your-data-into-solr.md +0 -32
- data/doc/Integration-with-Rails-Footnotes.md +0 -20
- data/doc/Internationalization.md +0 -32
- data/doc/JSON-API.md +0 -17
- data/doc/Pagination.md +0 -51
- data/doc/Providing-your-own-view-templates.md +0 -109
- data/doc/Quickstart.md +0 -115
- data/doc/README_SOLR.md +0 -245
- data/doc/Release-Notes-And-Upgrade-Guides.md +0 -20
- data/doc/Roadmap.md +0 -43
- data/doc/Sunspot-for-indexing.md +0 -46
- data/doc/Theming.md +0 -64
- data/doc/User-Authentication.md +0 -60
- data/doc/testing.md +0 -57
- data/lib/SolrMarc.jar +0 -0
- data/lib/blacklight/mash.rb +0 -19
- data/lib/blacklight/solr/document/marc.rb +0 -71
- data/lib/blacklight/solr/document/marc_export.rb +0 -590
- data/lib/generators/blacklight/marc_generator.rb +0 -66
- data/lib/generators/blacklight/templates/blacklight.scss +0 -4
- data/lib/generators/blacklight/templates/config/SolrMarc/config-test.properties +0 -37
- data/lib/generators/blacklight/templates/config/SolrMarc/config.properties +0 -37
- data/lib/generators/blacklight/templates/config/SolrMarc/index.properties +0 -97
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/dewey.bsh +0 -47
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/format.bsh +0 -126
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/README_MAPS +0 -1
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/callnumber_map.properties +0 -407
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/composition_era_map.properties +0 -56
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/country_map.properties +0 -379
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/format_map.properties +0 -50
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/instrument_map.properties +0 -101
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/language_map.properties +0 -490
- data/lib/railties/solr_marc.rake +0 -162
- data/spec/data/test_data.utf8.mrc +0 -1
- data/spec/features/librarian_view_spec.rb +0 -13
- data/spec/helpers/html_head_helper_spec.rb +0 -164
- data/spec/lib/blacklight_solr_document_marc_spec.rb +0 -89
- data/spec/lib/marc_export_spec.rb +0 -746
- data/spec/lib/tasks/solr_marc_task_spec.rb +0 -60
- data/spec/requests/alternate_controller_spec.rb +0 -16
- data/spec/routing/routes_spec.rb +0 -20
- data/spec/views/catalog/_constraints.html.erb_spec.rb +0 -33
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +0 -49
- data/test_support/data/test_data.utf8.mrc +0 -1
@@ -11,44 +11,18 @@ describe CatalogHelper do
|
|
11
11
|
start = (current_page - 1) * per_page
|
12
12
|
|
13
13
|
mock_docs = (1..total).to_a.map { {}.with_indifferent_access }
|
14
|
-
|
14
|
+
|
15
15
|
mock_response = Kaminari.paginate_array(mock_docs).page(current_page).per(per_page)
|
16
16
|
|
17
|
-
|
17
|
+
mock_response.stub(:docs).and_return(mock_docs.slice(start, per_page))
|
18
18
|
mock_response
|
19
19
|
end
|
20
20
|
|
21
21
|
def render_grouped_response?
|
22
22
|
false
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
describe "response_has_no_search_results?" do
|
27
|
-
it "should be deprecated" do
|
28
|
-
expect(Blacklight::CatalogHelperBehavior.deprecation_behavior.first).to receive(:call)
|
29
|
-
assign(:response, double(:empty? => false))
|
30
|
-
expect(helper.response_has_no_search_results?).to eq false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "paginate_params" do
|
35
|
-
let(:response) { double }
|
36
|
-
it "should be deprecated" do
|
37
|
-
expect(Blacklight::CatalogHelperBehavior.deprecation_behavior.first).to receive(:call)
|
38
|
-
assign(:response, response)
|
39
|
-
expect(helper.paginate_params(response)).to eq response
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "format_num" do
|
44
|
-
it "should be deprecated" do
|
45
|
-
expect(Blacklight::CatalogHelperBehavior.deprecation_behavior.first).to receive(:call)
|
46
|
-
expect(format_num(10000)).to eq '10,000'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
24
|
+
|
25
|
+
|
52
26
|
describe "page_entries_info" do
|
53
27
|
before(:all) do
|
54
28
|
end
|
@@ -57,16 +31,16 @@ describe CatalogHelper do
|
|
57
31
|
@response = mock_response :total => 0
|
58
32
|
|
59
33
|
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
60
|
-
|
61
|
-
|
34
|
+
html.should == "No entry_names found"
|
35
|
+
html.html_safe?.should == true
|
62
36
|
end
|
63
37
|
|
64
38
|
it "with no results (and no entry_name provided)" do
|
65
39
|
@response = mock_response :total => 0
|
66
40
|
|
67
41
|
html = page_entries_info(@response)
|
68
|
-
|
69
|
-
|
42
|
+
html.should == "No entries found"
|
43
|
+
html.html_safe?.should == true
|
70
44
|
end
|
71
45
|
|
72
46
|
describe "with a single result" do
|
@@ -74,21 +48,21 @@ describe CatalogHelper do
|
|
74
48
|
response = mock_response :total => 1
|
75
49
|
|
76
50
|
html = page_entries_info(response, { :entry_name => 'entry_name' })
|
77
|
-
|
78
|
-
|
51
|
+
html.should == "<strong>1</strong> entry_name found"
|
52
|
+
html.html_safe?.should == true
|
79
53
|
end
|
80
54
|
|
81
55
|
it "should infer a name" do
|
82
56
|
response = mock_response :total => 1
|
83
57
|
|
84
58
|
html = page_entries_info(response)
|
85
|
-
|
86
|
-
|
59
|
+
html.should == "<strong>1</strong> entry found"
|
60
|
+
html.html_safe?.should == true
|
87
61
|
end
|
88
62
|
|
89
63
|
it "should use the model_name from the response" do
|
90
64
|
response = mock_response :total => 1
|
91
|
-
|
65
|
+
response.stub(:model_name).and_return('thingy')
|
92
66
|
|
93
67
|
html = page_entries_info(response)
|
94
68
|
expect(html).to eq "<strong>1</strong> thingy found"
|
@@ -100,139 +74,126 @@ describe CatalogHelper do
|
|
100
74
|
response = mock_response :total => 7
|
101
75
|
|
102
76
|
html = page_entries_info(response, { :entry_name => 'entry_name' })
|
103
|
-
|
104
|
-
|
77
|
+
html.should == "<strong>1</strong> - <strong>7</strong> of <strong>7</strong>"
|
78
|
+
html.html_safe?.should == true
|
105
79
|
end
|
106
80
|
|
107
81
|
it "on the first page of multiple pages of results" do
|
108
82
|
@response = mock_response :total => 15, :per_page => 10
|
109
83
|
|
110
84
|
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
111
|
-
|
112
|
-
|
85
|
+
html.should == "<strong>1</strong> - <strong>10</strong> of <strong>15</strong>"
|
86
|
+
html.html_safe?.should == true
|
113
87
|
end
|
114
88
|
|
115
89
|
it "on the second page of multiple pages of results" do
|
116
90
|
@response = mock_response :total => 47, :per_page => 10, :current_page => 2
|
117
91
|
|
118
92
|
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
119
|
-
|
120
|
-
|
93
|
+
html.should == "<strong>11</strong> - <strong>20</strong> of <strong>47</strong>"
|
94
|
+
html.html_safe?.should == true
|
121
95
|
end
|
122
96
|
|
123
97
|
it "on the last page of results" do
|
124
98
|
@response = mock_response :total => 47, :per_page => 10, :current_page => 5
|
125
99
|
|
126
100
|
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
127
|
-
|
128
|
-
|
101
|
+
html.should == "<strong>41</strong> - <strong>47</strong> of <strong>47</strong>"
|
102
|
+
html.html_safe?.should == true
|
129
103
|
end
|
130
104
|
it "should work with rows the same as per_page" do
|
131
105
|
@response = mock_response :total => 47, :rows => 20, :current_page => 2
|
132
106
|
|
133
107
|
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
it "uses delimiters with large numbers" do
|
139
|
-
@response = mock_response :total => 5000, :rows => 10, :current_page => 101
|
140
|
-
html = page_entries_info(@response, { :entry_name => 'entry_name' })
|
141
|
-
|
142
|
-
expect(html).to eq("<strong>1,001</strong> - <strong>1,010</strong> of <strong>5,000</strong>")
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should work with an activerecord collection" do
|
146
|
-
50.times { b = Bookmark.new; b.user_id = 1; b.save! }
|
147
|
-
html = helper.page_entries_info(Bookmark.page(1).per(25))
|
148
|
-
expect(html).to eq "<strong>1</strong> - <strong>25</strong> of <strong>50</strong>"
|
108
|
+
html.should == "<strong>21</strong> - <strong>40</strong> of <strong>47</strong>"
|
109
|
+
html.html_safe?.should == true
|
149
110
|
end
|
150
111
|
|
151
112
|
end
|
152
113
|
|
153
114
|
describe "should_autofocus_on_search_box?" do
|
154
115
|
it "should be focused if we're on a catalog-like index page without query or facet parameters" do
|
155
|
-
|
156
|
-
expect(helper.should_autofocus_on_search_box?).to
|
116
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { })
|
117
|
+
expect(helper.should_autofocus_on_search_box?).to be_true
|
157
118
|
end
|
158
119
|
|
159
120
|
it "should not be focused if we're not on a catalog controller" do
|
160
|
-
|
161
|
-
expect(helper.should_autofocus_on_search_box?).to
|
121
|
+
helper.stub(:controller => ApplicationController.new)
|
122
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
162
123
|
end
|
163
124
|
|
164
125
|
it "should not be focused if we're not on a catalog controller index" do
|
165
|
-
|
166
|
-
expect(helper.should_autofocus_on_search_box?).to
|
126
|
+
helper.stub(:controller => CatalogController.new, :action_name => "show")
|
127
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
167
128
|
end
|
168
129
|
|
169
130
|
it "should not be focused if a search string is provided" do
|
170
|
-
|
171
|
-
expect(helper.should_autofocus_on_search_box?).to
|
131
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :q => "hello"})
|
132
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
172
133
|
end
|
173
134
|
|
174
135
|
it "should not be focused if a facet is selected" do
|
175
|
-
|
176
|
-
expect(helper.should_autofocus_on_search_box?).to
|
136
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :f => { "field" => ["value"]}})
|
137
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
177
138
|
end
|
178
139
|
end
|
179
140
|
|
180
141
|
describe "has_thumbnail?" do
|
181
142
|
it "should have a thumbnail if a thumbnail_method is configured" do
|
182
|
-
|
143
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_method => :xyz) ))
|
183
144
|
document = double()
|
184
|
-
expect(helper.has_thumbnail? document).to
|
145
|
+
expect(helper.has_thumbnail? document).to be_true
|
185
146
|
end
|
186
147
|
|
187
148
|
it "should have a thumbnail if a thumbnail_field is configured and it exists in the document" do
|
188
|
-
|
149
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_field => :xyz) ))
|
189
150
|
document = double(:has? => true)
|
190
|
-
expect(helper.has_thumbnail? document).to
|
151
|
+
expect(helper.has_thumbnail? document).to be_true
|
191
152
|
end
|
192
|
-
|
153
|
+
|
193
154
|
it "should not have a thumbnail if the thumbnail_field is missing from the document" do
|
194
|
-
|
155
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_field => :xyz) ))
|
195
156
|
document = double(:has? => false)
|
196
|
-
expect(helper.has_thumbnail? document).to
|
157
|
+
expect(helper.has_thumbnail? document).to be_false
|
197
158
|
end
|
198
159
|
|
199
160
|
it "should not have a thumbnail if none of the fields are configured" do
|
200
|
-
|
201
|
-
expect(helper.has_thumbnail? double()).to
|
161
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new()))
|
162
|
+
expect(helper.has_thumbnail? double()).to be_false
|
202
163
|
end
|
203
164
|
end
|
204
165
|
|
205
166
|
describe "render_thumbnail_tag" do
|
206
167
|
it "should call the provided thumbnail method" do
|
207
|
-
|
168
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_method => :xyz)))
|
208
169
|
document = double()
|
209
|
-
|
170
|
+
helper.stub(:xyz => "some-thumbnail")
|
210
171
|
|
211
|
-
|
172
|
+
helper.should_receive(:link_to_document).with(document, :label => "some-thumbnail")
|
212
173
|
helper.render_thumbnail_tag document
|
213
174
|
end
|
214
175
|
|
215
176
|
it "should create an image tag from the given field" do
|
216
|
-
|
177
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new(:thumbnail_field => :xyz)))
|
217
178
|
document = double()
|
218
179
|
|
219
|
-
|
220
|
-
|
180
|
+
document.stub(:has?).with(:xyz).and_return(true)
|
181
|
+
document.stub(:first).with(:xyz).and_return("http://example.com/some.jpg")
|
221
182
|
|
222
|
-
|
183
|
+
helper.should_receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
|
223
184
|
helper.render_thumbnail_tag document
|
224
185
|
end
|
225
186
|
|
226
187
|
it "should return nil if no thumbnail is available" do
|
227
|
-
|
188
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new()))
|
228
189
|
|
229
190
|
document = double()
|
230
191
|
expect(helper.render_thumbnail_tag document).to be_nil
|
231
192
|
end
|
232
193
|
|
233
194
|
it "should return nil if no thumbnail is returned from the thumbnail method" do
|
234
|
-
|
235
|
-
|
195
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new(:thumbnail_method => :xyz)))
|
196
|
+
helper.stub(:xyz => nil)
|
236
197
|
document = double()
|
237
198
|
|
238
199
|
expect(helper.render_thumbnail_tag document).to be_nil
|
@@ -241,17 +202,17 @@ describe CatalogHelper do
|
|
241
202
|
|
242
203
|
describe "thumbnail_url" do
|
243
204
|
it "should pull the configured thumbnail field out of the document" do
|
244
|
-
|
205
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_field => "xyz")))
|
245
206
|
document = double()
|
246
|
-
|
247
|
-
|
207
|
+
document.stub(:has?).with("xyz").and_return(true)
|
208
|
+
document.stub(:first).with("xyz").and_return("asdf")
|
248
209
|
expect(helper.thumbnail_url document).to eq("asdf")
|
249
210
|
end
|
250
211
|
|
251
212
|
it "should return nil if the thumbnail field doesn't exist" do
|
252
|
-
|
213
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_field => "xyz")))
|
253
214
|
document = double()
|
254
|
-
|
215
|
+
document.stub(:has?).with("xyz").and_return(false)
|
255
216
|
expect(helper.thumbnail_url document).to be_nil
|
256
217
|
end
|
257
218
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'nokogiri'
|
4
3
|
require 'equivalent-xml'
|
5
4
|
|
6
5
|
describe FacetsHelper do
|
7
6
|
let(:blacklight_config) { Blacklight::Configuration.new }
|
8
7
|
|
9
8
|
before(:each) do
|
10
|
-
|
9
|
+
helper.stub(:blacklight_config).and_return blacklight_config
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
describe "has_facet_values?" do
|
14
13
|
it "should be true if there are any facets to display" do
|
15
14
|
|
@@ -18,7 +17,7 @@ describe FacetsHelper do
|
|
18
17
|
empty = double(:items => [])
|
19
18
|
|
20
19
|
fields = [a,b,empty]
|
21
|
-
|
20
|
+
helper.has_facet_values?(fields).should be_true
|
22
21
|
end
|
23
22
|
|
24
23
|
it "should be false if all facets are empty" do
|
@@ -26,7 +25,7 @@ describe FacetsHelper do
|
|
26
25
|
empty = double(:items => [])
|
27
26
|
|
28
27
|
fields = [empty]
|
29
|
-
|
28
|
+
helper.has_facet_values?(fields).should_not be_true
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -34,49 +33,23 @@ describe FacetsHelper do
|
|
34
33
|
before do
|
35
34
|
@config = Blacklight::Configuration.new do |config|
|
36
35
|
config.add_facet_field 'basic_field'
|
37
|
-
config.add_facet_field 'no_show', :show
|
38
|
-
config.add_facet_field 'helper_show', :show => :my_helper
|
39
|
-
config.add_facet_field 'helper_with_an_arg_show', :show => :my_helper_with_an_arg
|
40
|
-
config.add_facet_field 'lambda_show', :show => lambda { |context, config, field| true }
|
41
|
-
config.add_facet_field 'lambda_no_show', :show => lambda { |context, config, field| false }
|
36
|
+
config.add_facet_field 'no_show', :show=>false
|
42
37
|
end
|
43
38
|
|
44
|
-
|
39
|
+
helper.stub(:blacklight_config => @config)
|
45
40
|
end
|
46
|
-
|
47
41
|
it "should render facets with items" do
|
48
42
|
a = double(:items => [1,2], :name=>'basic_field')
|
49
|
-
|
43
|
+
helper.should_render_facet?(a).should == true
|
50
44
|
end
|
51
45
|
it "should not render facets without items" do
|
52
46
|
empty = double(:items => [], :name=>'basic_field')
|
53
|
-
|
47
|
+
helper.should_render_facet?(empty).should == false
|
54
48
|
end
|
55
49
|
|
56
50
|
it "should not render facets where show is set to false" do
|
57
51
|
a = double(:items => [1,2], :name=>'no_show')
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should call a helper to determine if it should render a field" do
|
62
|
-
allow(helper).to receive_messages(:my_helper => true)
|
63
|
-
a = double(:items => [1,2], :name=>'helper_show')
|
64
|
-
expect(helper.should_render_facet?(a)).to eq true
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should call a helper to determine if it should render a field" do
|
68
|
-
a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
|
69
|
-
expect(helper).to receive(:my_helper_with_an_arg).with(a).and_return(true)
|
70
|
-
expect(helper.should_render_facet?(a)).to eq true
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
it "should evaluate a Proc to determine if it should render a field" do
|
75
|
-
a = double(:items => [1,2], :name=>'lambda_show')
|
76
|
-
expect(helper.should_render_facet?(a)).to eq true
|
77
|
-
|
78
|
-
a = double(:items => [1,2], :name=>'lambda_no_show')
|
79
|
-
expect(helper.should_render_facet?(a)).to eq false
|
52
|
+
helper.should_render_facet?(a).should == false
|
80
53
|
end
|
81
54
|
end
|
82
55
|
|
@@ -84,24 +57,24 @@ describe FacetsHelper do
|
|
84
57
|
it "should retrieve the facet from the response given a string" do
|
85
58
|
facet_config = double(:query => nil)
|
86
59
|
facet_field = double()
|
87
|
-
|
60
|
+
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
88
61
|
|
89
62
|
@response = double()
|
90
|
-
|
63
|
+
@response.should_receive(:facet_by_field_name).with('a').and_return(facet_field)
|
91
64
|
|
92
|
-
|
65
|
+
helper.facet_by_field_name('a').should == facet_field
|
93
66
|
end
|
94
67
|
|
95
68
|
it "should also work for facet query fields" do
|
96
69
|
facet_config = double(:query => {})
|
97
|
-
|
98
|
-
|
70
|
+
helper.should_receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
|
71
|
+
helper.should_receive(:create_rsolr_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
|
99
72
|
|
100
73
|
helper.facet_by_field_name 'a_query_facet_field'
|
101
74
|
end
|
102
75
|
|
103
76
|
describe "query facets" do
|
104
|
-
let(:facet_config) {
|
77
|
+
let(:facet_config) {
|
105
78
|
double(
|
106
79
|
:query => {
|
107
80
|
'a_simple_query' => { :fq => 'field:search', :label => 'A Human Readable label'},
|
@@ -112,7 +85,7 @@ describe FacetsHelper do
|
|
112
85
|
}
|
113
86
|
|
114
87
|
before(:each) do
|
115
|
-
|
88
|
+
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
116
89
|
|
117
90
|
@response = double(:facet_queries => {
|
118
91
|
'field:search' => 10,
|
@@ -124,17 +97,17 @@ describe FacetsHelper do
|
|
124
97
|
|
125
98
|
it"should convert the query facets into a double RSolr FacetField" do
|
126
99
|
field = helper.facet_by_field_name('my_query_facet_field')
|
127
|
-
|
100
|
+
field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
128
101
|
|
129
|
-
|
130
|
-
|
131
|
-
|
102
|
+
field.name.should == 'my_query_facet_field'
|
103
|
+
field.items.length.should == 2
|
104
|
+
field.items.map { |x| x.value }.should_not include 'field:not_appearing_in_the_config'
|
132
105
|
|
133
106
|
facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first
|
134
107
|
|
135
|
-
|
136
|
-
|
137
|
-
|
108
|
+
facet_item.value.should == 'a_simple_query'
|
109
|
+
facet_item.hits.should == 10
|
110
|
+
facet_item.label.should == 'A Human Readable label'
|
138
111
|
end
|
139
112
|
end
|
140
113
|
|
@@ -143,24 +116,24 @@ describe FacetsHelper do
|
|
143
116
|
double(:pivot => ['field_a', 'field_b'])
|
144
117
|
}
|
145
118
|
|
146
|
-
before(:each) do
|
147
|
-
|
148
|
-
|
119
|
+
before(:each) do
|
120
|
+
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
121
|
+
|
149
122
|
@response = double(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
|
150
123
|
end
|
151
124
|
|
152
125
|
it "should convert the pivot facet into a double RSolr FacetField" do
|
153
126
|
field = helper.facet_by_field_name('my_pivot_facet_field')
|
154
|
-
|
127
|
+
field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
155
128
|
|
156
|
-
|
129
|
+
field.name.should == 'my_pivot_facet_field'
|
157
130
|
|
158
|
-
|
131
|
+
field.items.length.should == 1
|
159
132
|
|
160
|
-
|
133
|
+
field.items.first.should respond_to(:items)
|
161
134
|
|
162
|
-
|
163
|
-
|
135
|
+
field.items.first.items.length.should == 1
|
136
|
+
field.items.first.items.first.fq.should == { 'field_a' => 'a' }
|
164
137
|
end
|
165
138
|
end
|
166
139
|
end
|
@@ -174,9 +147,9 @@ describe FacetsHelper do
|
|
174
147
|
|
175
148
|
fields = [a,b,empty]
|
176
149
|
|
177
|
-
|
178
|
-
|
179
|
-
|
150
|
+
helper.should_receive(:render_facet_limit).with(a, {})
|
151
|
+
helper.should_receive(:render_facet_limit).with(b, {})
|
152
|
+
helper.should_receive(:render_facet_limit).with(empty, {})
|
180
153
|
|
181
154
|
helper.render_facet_partials fields
|
182
155
|
end
|
@@ -184,10 +157,10 @@ describe FacetsHelper do
|
|
184
157
|
it "should default to the configured facets" do
|
185
158
|
a = double(:items => [1,2])
|
186
159
|
b = double(:items => ['b','c'])
|
187
|
-
|
160
|
+
helper.should_receive(:facet_field_names) { [a,b] }
|
188
161
|
|
189
|
-
|
190
|
-
|
162
|
+
helper.should_receive(:render_facet_limit).with(a, {})
|
163
|
+
helper.should_receive(:render_facet_limit).with(b, {})
|
191
164
|
|
192
165
|
helper.render_facet_partials
|
193
166
|
end
|
@@ -204,16 +177,15 @@ describe FacetsHelper do
|
|
204
177
|
config.add_facet_field 'my_facet_field_with_custom_partial', :partial => 'custom_facet_partial'
|
205
178
|
end
|
206
179
|
|
207
|
-
|
180
|
+
helper.stub(:blacklight_config => @config)
|
208
181
|
@response = double()
|
209
182
|
end
|
210
183
|
|
211
184
|
it "should set basic local variables" do
|
212
185
|
@mock_facet = double(:name => 'basic_field', :items => [1,2,3])
|
213
|
-
|
214
|
-
:locals => {
|
186
|
+
helper.should_receive(:render).with(hash_including(:partial => 'facet_limit',
|
187
|
+
:locals => {
|
215
188
|
:solr_field => 'basic_field',
|
216
|
-
:solr_fname => 'basic_field',
|
217
189
|
:facet_field => helper.blacklight_config.facet_fields['basic_field'],
|
218
190
|
:display_facet => @mock_facet }
|
219
191
|
))
|
@@ -222,46 +194,39 @@ describe FacetsHelper do
|
|
222
194
|
|
223
195
|
it "should render a facet _not_ declared in the configuration" do
|
224
196
|
@mock_facet = double(:name => 'asdf', :items => [1,2,3])
|
225
|
-
|
197
|
+
helper.should_receive(:render).with(hash_including(:partial => 'facet_limit'))
|
226
198
|
helper.render_facet_limit(@mock_facet)
|
227
199
|
end
|
228
200
|
|
229
201
|
it "should get the partial name from the configuration" do
|
230
202
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
231
|
-
|
203
|
+
helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
232
204
|
helper.render_facet_limit(@mock_facet)
|
233
|
-
end
|
205
|
+
end
|
234
206
|
|
235
207
|
it "should use a partial layout for rendering the facet frame" do
|
236
208
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
237
|
-
|
209
|
+
helper.should_receive(:render).with(hash_including(:layout => 'facet_layout'))
|
238
210
|
helper.render_facet_limit(@mock_facet)
|
239
211
|
end
|
240
212
|
|
241
213
|
it "should allow the caller to opt-out of facet layouts" do
|
242
214
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
243
|
-
|
215
|
+
helper.should_receive(:render).with(hash_including(:layout => nil))
|
244
216
|
helper.render_facet_limit(@mock_facet, :layout => nil)
|
245
217
|
end
|
246
218
|
|
247
219
|
it "should render the facet_pivot partial for pivot facets" do
|
248
220
|
@mock_facet = double(:name => 'pivot_facet_field', :items => [1,2,3])
|
249
|
-
|
221
|
+
helper.should_receive(:render).with(hash_including(:partial => 'facet_pivot'))
|
250
222
|
helper.render_facet_limit(@mock_facet)
|
251
|
-
end
|
223
|
+
end
|
252
224
|
|
253
225
|
it "should let you override the rendered partial for pivot facets" do
|
254
226
|
@mock_facet = double(:name => 'my_pivot_facet_field_with_custom_partial', :items => [1,2,3])
|
255
|
-
|
227
|
+
helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
256
228
|
helper.render_facet_limit(@mock_facet)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should be deprecated when a string is passed" do
|
260
|
-
expect(@response).to receive(:facet_by_field_name)
|
261
|
-
expect(Blacklight::FacetsHelperBehavior.deprecation_behavior.first).to receive(:call)
|
262
|
-
helper.render_facet_limit('basic_field')
|
263
|
-
end
|
264
|
-
|
229
|
+
end
|
265
230
|
end
|
266
231
|
|
267
232
|
describe "add_facet_params" do
|
@@ -271,84 +236,84 @@ describe FacetsHelper do
|
|
271
236
|
end
|
272
237
|
|
273
238
|
it "should add facet value for no pre-existing facets" do
|
274
|
-
|
239
|
+
helper.stub(:params).and_return(@params_no_existing_facet)
|
275
240
|
|
276
241
|
result_params = helper.add_facet_params("facet_field", "facet_value")
|
277
|
-
|
278
|
-
|
279
|
-
|
242
|
+
result_params[:f].should be_a_kind_of(Hash)
|
243
|
+
result_params[:f]["facet_field"].should be_a_kind_of(Array)
|
244
|
+
result_params[:f]["facet_field"].should == ["facet_value"]
|
280
245
|
end
|
281
246
|
|
282
247
|
it "should add a facet param to existing facet constraints" do
|
283
|
-
|
284
|
-
|
248
|
+
helper.stub(:params).and_return(@params_existing_facets)
|
249
|
+
|
285
250
|
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
286
251
|
|
287
|
-
|
252
|
+
result_params[:f].should be_a_kind_of(Hash)
|
288
253
|
|
289
254
|
@params_existing_facets[:f].each_pair do |facet_field, value_list|
|
290
|
-
|
291
|
-
|
255
|
+
result_params[:f][facet_field].should be_a_kind_of(Array)
|
256
|
+
|
292
257
|
if facet_field == 'facet_field_2'
|
293
|
-
|
258
|
+
result_params[:f][facet_field].should == (@params_existing_facets[:f][facet_field] | ["new_facet_value"])
|
294
259
|
else
|
295
|
-
|
296
|
-
end
|
260
|
+
result_params[:f][facet_field].should == @params_existing_facets[:f][facet_field]
|
261
|
+
end
|
297
262
|
end
|
298
263
|
end
|
299
264
|
it "should leave non-facet params alone" do
|
300
265
|
[@params_existing_facets, @params_no_existing_facet].each do |params|
|
301
|
-
|
266
|
+
helper.stub(:params).and_return(params)
|
302
267
|
|
303
268
|
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
304
269
|
|
305
270
|
params.each_pair do |key, value|
|
306
271
|
next if key == :f
|
307
|
-
|
308
|
-
end
|
272
|
+
result_params[key].should == params[key]
|
273
|
+
end
|
309
274
|
end
|
310
|
-
end
|
275
|
+
end
|
311
276
|
|
312
277
|
it "should replace facets for facets configured as single" do
|
313
|
-
|
278
|
+
helper.should_receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(:single => true))
|
314
279
|
params = { :f => { 'single_value_facet_field' => 'other_value'}}
|
315
|
-
|
280
|
+
helper.stub(:params).and_return params
|
316
281
|
|
317
282
|
result_params = helper.add_facet_params('single_value_facet_field', 'my_value')
|
318
283
|
|
319
284
|
|
320
|
-
|
321
|
-
|
285
|
+
result_params[:f]['single_value_facet_field'].length.should == 1
|
286
|
+
result_params[:f]['single_value_facet_field'].first.should == 'my_value'
|
322
287
|
end
|
323
288
|
|
324
289
|
it "should accept a FacetItem instead of a plain facet value" do
|
325
|
-
|
290
|
+
|
326
291
|
result_params = helper.add_facet_params('facet_field_1', double(:value => 123))
|
327
292
|
|
328
|
-
|
293
|
+
result_params[:f]['facet_field_1'].should include(123)
|
329
294
|
end
|
330
295
|
|
331
296
|
it "should defer to the field set on a FacetItem" do
|
332
|
-
|
297
|
+
|
333
298
|
result_params = helper.add_facet_params('facet_field_1', double(:field => 'facet_field_2', :value => 123))
|
334
299
|
|
335
|
-
|
336
|
-
|
300
|
+
result_params[:f]['facet_field_1'].should be_blank
|
301
|
+
result_params[:f]['facet_field_2'].should include(123)
|
337
302
|
end
|
338
303
|
|
339
304
|
it "should add any extra fq parameters from the FacetItem" do
|
340
|
-
|
305
|
+
|
341
306
|
result_params = helper.add_facet_params('facet_field_1', double(:value => 123, :fq => {'facet_field_2' => 'abc'}))
|
342
307
|
|
343
|
-
|
344
|
-
|
308
|
+
result_params[:f]['facet_field_1'].should include(123)
|
309
|
+
result_params[:f]['facet_field_2'].should include('abc')
|
345
310
|
end
|
346
311
|
end
|
347
312
|
|
348
313
|
describe "add_facet_params_and_redirect" do
|
349
314
|
before do
|
350
|
-
catalog_facet_params = {:q => "query",
|
351
|
-
:search_field => "search_field",
|
315
|
+
catalog_facet_params = {:q => "query",
|
316
|
+
:search_field => "search_field",
|
352
317
|
:per_page => "50",
|
353
318
|
:page => "5",
|
354
319
|
:f => {"facet_field_1" => ["value1"], "facet_field_2" => ["value2", "value2a"]},
|
@@ -356,25 +321,25 @@ describe FacetsHelper do
|
|
356
321
|
Blacklight::Solr::FacetPaginator.request_keys[:sort] => "index",
|
357
322
|
:id => 'facet_field_name'
|
358
323
|
}
|
359
|
-
|
324
|
+
helper.stub(:params).and_return(catalog_facet_params)
|
360
325
|
end
|
361
326
|
it "should redirect to 'index' action" do
|
362
327
|
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
363
328
|
|
364
|
-
|
329
|
+
params[:action].should == "index"
|
365
330
|
end
|
366
331
|
it "should not include request parameters used by the facet paginator" do
|
367
332
|
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
368
333
|
|
369
334
|
bad_keys = Blacklight::Solr::FacetPaginator.request_keys.values + [:id]
|
370
335
|
bad_keys.each do |paginator_key|
|
371
|
-
|
336
|
+
params.keys.should_not include(paginator_key)
|
372
337
|
end
|
373
338
|
end
|
374
339
|
it 'should remove :page request key' do
|
375
340
|
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
376
341
|
|
377
|
-
|
342
|
+
params.keys.should_not include(:page)
|
378
343
|
end
|
379
344
|
it "should otherwise do the same thing as add_facet_params" do
|
380
345
|
added_facet_params = helper.add_facet_params("facet_field_2", "facet_value")
|
@@ -382,8 +347,8 @@ describe FacetsHelper do
|
|
382
347
|
|
383
348
|
added_facet_params_from_facet_action.each_pair do |key, value|
|
384
349
|
next if key == :action
|
385
|
-
|
386
|
-
end
|
350
|
+
value.should == added_facet_params[key]
|
351
|
+
end
|
387
352
|
end
|
388
353
|
end
|
389
354
|
|
@@ -393,9 +358,9 @@ describe FacetsHelper do
|
|
393
358
|
|
394
359
|
describe "facet_field_in_params?" do
|
395
360
|
it "should check if the facet field is selected in the user params" do
|
396
|
-
|
397
|
-
expect(helper.facet_field_in_params?("some-field")).to
|
398
|
-
expect(helper.facet_field_in_params?("other-field")).to_not
|
361
|
+
helper.stub(:params => { :f => { "some-field" => ["x"]}})
|
362
|
+
expect(helper.facet_field_in_params?("some-field")).to be_true
|
363
|
+
expect(helper.facet_field_in_params?("other-field")).to_not be_true
|
399
364
|
end
|
400
365
|
end
|
401
366
|
|
@@ -404,54 +369,67 @@ describe FacetsHelper do
|
|
404
369
|
end
|
405
370
|
|
406
371
|
describe "render_facet_value" do
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
372
|
+
let (:item) { double(:value => 'A', :hits => 10) }
|
373
|
+
before do
|
374
|
+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
|
375
|
+
helper.should_receive(:facet_display_value).and_return('Z')
|
376
|
+
helper.should_receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
|
377
|
+
end
|
378
|
+
describe "simple case" do
|
379
|
+
let(:expected_html) { "<span class=\"facet-label\"><a class=\"facet_select\" href=\"/\">Z</a></span><span class=\"facet-count\">10</span>" }
|
380
|
+
it "should use facet_display_value" do
|
381
|
+
result = helper.render_facet_value('simple_field', item)
|
382
|
+
expect(result).to be_equivalent_to(expected_html).respecting_element_order
|
383
|
+
end
|
416
384
|
end
|
417
385
|
|
386
|
+
describe "when :suppress_link is set" do
|
387
|
+
let(:expected_html) { "<span class=\"facet-label\">Z</span><span class=\"facet-count\">10</span>" }
|
388
|
+
it "should suppress the link" do
|
389
|
+
result = helper.render_facet_value('simple_field', item, :suppress_link => true)
|
390
|
+
expect(result).to be_equivalent_to(expected_html).respecting_element_order
|
391
|
+
end
|
392
|
+
end
|
418
393
|
|
419
|
-
|
420
|
-
|
394
|
+
describe "when a route_set is passed" do
|
395
|
+
let(:my_engine) { double("Engine") }
|
396
|
+
let(:expected_html) { "<span class=\"facet-label\"><a class=\"facet_select\" href=\"/\">Z</a></span><span class=\"facet-count\">10</span>" }
|
421
397
|
|
422
|
-
|
423
|
-
|
424
|
-
|
398
|
+
it "should use the engine scope" do
|
399
|
+
expect(my_engine).to receive(:url_for).and_return({controller: 'catalog'})
|
400
|
+
result = helper.render_facet_value('simple_field', item, route_set: my_engine)
|
401
|
+
expect(result).to be_equivalent_to(expected_html).respecting_element_order
|
402
|
+
end
|
425
403
|
end
|
426
404
|
end
|
427
|
-
|
405
|
+
|
428
406
|
describe "#facet_display_value" do
|
429
407
|
it "should just be the facet value for an ordinary facet" do
|
430
|
-
|
431
|
-
|
408
|
+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
|
409
|
+
helper.facet_display_value('simple_field', 'asdf').should == 'asdf'
|
432
410
|
end
|
433
411
|
|
434
412
|
it "should allow you to pass in a :helper_method argument to the configuration" do
|
435
|
-
|
436
|
-
|
437
|
-
|
413
|
+
helper.stub(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
|
414
|
+
|
415
|
+
helper.should_receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
|
438
416
|
|
439
|
-
|
417
|
+
helper.facet_display_value('helper_field', 'qwerty').should == 'abc'
|
440
418
|
end
|
441
419
|
|
442
420
|
it "should extract the configuration label for a query facet" do
|
443
|
-
|
444
|
-
|
421
|
+
helper.stub(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
|
422
|
+
helper.facet_display_value('query_facet', 'query_key').should == 'XYZ'
|
445
423
|
end
|
446
424
|
|
447
425
|
it "should localize the label for date-type facets" do
|
448
|
-
|
449
|
-
|
426
|
+
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
|
427
|
+
helper.facet_display_value('date_facet', '2012-01-01').should == 'Sun, 01 Jan 2012 00:00:00 +0000'
|
450
428
|
end
|
451
429
|
|
452
430
|
it "should localize the label for date-type facets with the supplied localization options" do
|
453
|
-
|
454
|
-
|
431
|
+
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
|
432
|
+
helper.facet_display_value('date_facet', '2012-01-01').should == '01 Jan 00:00'
|
455
433
|
end
|
456
434
|
end
|
457
435
|
end
|