blacklight 4.3.0 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -6
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/autofocus.js +16 -0
- data/app/assets/javascripts/blacklight/blacklight.js +1 -0
- data/app/assets/javascripts/blacklight/bookmark_toggle.js +2 -5
- data/app/assets/javascripts/blacklight/checkbox_submit.js +3 -6
- data/app/assets/javascripts/blacklight/core.js +24 -1
- data/app/assets/javascripts/blacklight/css_dropdowns.js +2 -2
- data/app/assets/javascripts/blacklight/facet_expand_contract.js +4 -3
- data/app/assets/javascripts/blacklight/lightbox_dialog.js +7 -1
- data/app/assets/javascripts/blacklight/search_context.js +1 -1
- data/app/assets/javascripts/blacklight/select_submit.js +1 -1
- data/app/assets/javascripts/blacklight/zebra_stripe.js +1 -1
- data/app/assets/stylesheets/blacklight/_blacklight_base.css.scss +1 -0
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +5 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +6 -0
- data/app/assets/stylesheets/blacklight/_group.css.scss +14 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +1 -0
- data/app/controllers/bookmarks_controller.rb +2 -2
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +41 -24
- data/app/helpers/blacklight/catalog_helper_behavior.rb +48 -28
- data/app/helpers/blacklight/facets_helper_behavior.rb +9 -75
- data/app/models/record_mailer.rb +1 -16
- data/app/views/bookmarks/index.html.erb +2 -0
- data/app/views/catalog/_bookmark_control.html.erb +3 -4
- data/app/views/catalog/_document.html.erb +2 -1
- data/app/views/catalog/_document_header.html.erb +6 -3
- data/app/views/catalog/_email_form.html.erb +0 -7
- data/app/views/catalog/_facet_layout.html.erb +1 -1
- data/app/views/catalog/_group_default.html.erb +12 -0
- data/app/views/catalog/_index_default.html.erb +1 -1
- data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -3
- data/app/views/catalog/_paginate_compact.html.erb +2 -2
- data/app/views/catalog/_results_pagination.html.erb +2 -2
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_sms_form.html.erb +1 -21
- data/app/views/catalog/_thumbnail_default.html.erb +5 -0
- data/app/views/catalog/email_sent.html.erb +9 -0
- data/app/views/catalog/index.atom.builder +7 -8
- data/app/views/catalog/index.html.erb +6 -3
- data/app/views/catalog/librarian_view.html.erb +1 -1
- data/app/views/catalog/sms_sent.html.erb +9 -0
- data/app/views/feedback/complete.html.erb +2 -0
- data/app/views/feedback/show.html.erb +7 -5
- data/app/views/kaminari/blacklight_compact/_paginator.html.erb +1 -1
- data/app/views/layouts/blacklight.html.erb +1 -2
- data/app/views/saved_searches/index.html.erb +2 -0
- data/app/views/search_history/index.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/locales/blacklight.en.yml +11 -0
- data/config/locales/blacklight.fr.yml +15 -1
- data/gemfiles/rails3.gemfile +7 -0
- data/gemfiles/rails4.gemfile +7 -0
- data/lib/blacklight.rb +1 -0
- data/lib/blacklight/catalog.rb +101 -56
- data/lib/blacklight/configuration.rb +1 -1
- data/lib/blacklight/controller.rb +7 -4
- data/lib/blacklight/facet.rb +79 -0
- data/lib/blacklight/routes.rb +0 -1
- data/lib/blacklight/solr/document.rb +4 -0
- data/lib/blacklight/solr/document/marc_export.rb +1 -1
- data/lib/blacklight/solr_helper.rb +39 -8
- data/lib/blacklight/solr_response.rb +35 -3
- data/lib/blacklight/solr_response/facets.rb +4 -0
- data/lib/blacklight/solr_response/group.rb +33 -0
- data/lib/blacklight/solr_response/group_response.rb +49 -0
- data/lib/blacklight/solr_response/pagination_methods.rb +27 -0
- data/lib/blacklight/user.rb +30 -32
- data/lib/generators/blacklight/assets_generator.rb +3 -1
- data/lib/generators/blacklight/blacklight_generator.rb +28 -125
- data/lib/generators/blacklight/marc_generator.rb +66 -0
- data/lib/generators/blacklight/models_generator.rb +113 -0
- data/lib/generators/blacklight/templates/alternate_controller.rb +9 -0
- data/lib/generators/blacklight/templates/config/solr.yml +0 -2
- data/lib/generators/blacklight/templates/solr_document.rb +1 -13
- data/lib/railties/all_tests.rake +5 -8
- data/spec/controllers/catalog_controller_spec.rb +185 -113
- data/spec/features/alternate_controller_spec.rb +34 -0
- data/spec/features/bookmarks_spec.rb +58 -0
- data/spec/features/did_you_mean_spec.rb +135 -0
- data/spec/features/librarian_view_spec.rb +13 -0
- data/spec/features/record_view_spec.rb +37 -0
- data/spec/features/saved_searches_spec.rb +47 -0
- data/spec/features/search_filters_spec.rb +137 -0
- data/spec/features/search_history_spec.rb +75 -0
- data/spec/features/search_pagination_spec.rb +91 -0
- data/spec/features/search_results_spec.rb +68 -0
- data/spec/features/search_sort_spec.rb +20 -0
- data/spec/features/search_spec.rb +108 -0
- data/spec/helpers/blacklight_helper_spec.rb +45 -2
- data/spec/helpers/catalog_helper_spec.rb +134 -1
- data/spec/helpers/facets_helper_spec.rb +8 -0
- data/spec/lib/blacklight/solr_response/group_response_spec.rb +78 -0
- data/spec/lib/blacklight/solr_response/group_spec.rb +70 -0
- data/spec/lib/blacklight_solr_response_spec.rb +11 -5
- data/spec/lib/blacklight_user_spec.rb +22 -41
- data/spec/lib/solr_helper_spec.rb +73 -1
- data/spec/models/record_mailer_spec.rb +3 -3
- data/spec/models/{solr_docment_spec.rb → solr_document_spec.rb} +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/support/features.rb +7 -0
- data/spec/support/features/session_helpers.rb +22 -0
- data/spec/test_app_templates/Gemfile.extra +0 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -6
- data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +1 -9
- data/spec/views/catalog/_facets.html.erb_spec.rb +2 -1
- data/tasks/blacklight.rake +0 -10
- metadata +49 -58
- data/features/bookmarks.feature +0 -68
- data/features/did_you_mean.feature +0 -123
- data/features/librarian_view.feature +0 -18
- data/features/record_view.feature +0 -40
- data/features/saved_searches.feature +0 -49
- data/features/search.feature +0 -83
- data/features/search_filters.feature +0 -119
- data/features/search_history.feature +0 -85
- data/features/search_pagination.feature +0 -53
- data/features/search_results.feature +0 -61
- data/features/search_sort.feature +0 -27
- data/features/step_definitions/bookmarks_steps.rb +0 -6
- data/features/step_definitions/error_steps.rb +0 -5
- data/features/step_definitions/general_steps.rb +0 -50
- data/features/step_definitions/record_view_steps.rb +0 -12
- data/features/step_definitions/saved_searches_steps.rb +0 -19
- data/features/step_definitions/search_facets_steps.rb +0 -29
- data/features/step_definitions/search_history_steps.rb +0 -9
- data/features/step_definitions/search_pagination_steps.rb +0 -29
- data/features/step_definitions/search_result_steps.rb +0 -115
- data/features/step_definitions/search_steps.rb +0 -118
- data/features/step_definitions/user_steps.rb +0 -5
- data/features/step_definitions/web_steps.rb +0 -217
- data/features/support/env.rb +0 -65
- data/features/support/paths.rb +0 -48
- data/features/support/selectors.rb +0 -40
- data/lib/railties/blacklight_cucumber.rake +0 -126
- data/lib/solrmarc.log.1 +0 -854
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Search Pagination" do
|
5
|
+
it "should have results with pagination" do
|
6
|
+
visit root_path
|
7
|
+
fill_in "q", with: ''
|
8
|
+
click_button 'search'
|
9
|
+
within ("#sortAndPerPage") do
|
10
|
+
expect(page).to have_content "1 - 10 of "
|
11
|
+
within '#per_page-dropdown' do
|
12
|
+
expect(page).to have_link('10')
|
13
|
+
expect(page).to have_link('20')
|
14
|
+
expect(page).to have_link('50')
|
15
|
+
expect(page).to have_link('100')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
click_link "Next »"
|
20
|
+
within ("#sortAndPerPage") do
|
21
|
+
expect(page).to have_content "11 - 20 of "
|
22
|
+
end
|
23
|
+
click_link "« Previous"
|
24
|
+
within ("#sortAndPerPage") do
|
25
|
+
expect(page).to have_content "1 - 10 of "
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to change the number of items per page" do
|
30
|
+
visit root_path
|
31
|
+
fill_in "q", with: ''
|
32
|
+
click_button 'search'
|
33
|
+
within ("#sortAndPerPage") do
|
34
|
+
expect(page).to have_content "1 - 10 of "
|
35
|
+
end
|
36
|
+
|
37
|
+
within ("#per_page-dropdown") do
|
38
|
+
click_link '20'
|
39
|
+
end
|
40
|
+
within ("#sortAndPerPage") do
|
41
|
+
expect(page).to have_content "1 - 20 of "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when the application is configured for other per page values" do
|
46
|
+
let!(:original_per_page) { CatalogController.blacklight_config[:per_page] }
|
47
|
+
let!(:original_rows) { CatalogController.blacklight_config[:default_solr_params][:rows] }
|
48
|
+
before do
|
49
|
+
CatalogController.blacklight_config[:per_page] = [15, 30]
|
50
|
+
CatalogController.blacklight_config[:default_solr_params][:rows] = 15
|
51
|
+
end
|
52
|
+
after do
|
53
|
+
CatalogController.blacklight_config[:per_page] = original_per_page
|
54
|
+
CatalogController.blacklight_config[:default_solr_params][:rows] = original_rows
|
55
|
+
end
|
56
|
+
it "should use the configured values" do
|
57
|
+
visit root_path
|
58
|
+
fill_in "q", with: ''
|
59
|
+
click_button 'search'
|
60
|
+
within ("#sortAndPerPage") do
|
61
|
+
expect(page).to have_content "1 - 15 of "
|
62
|
+
within '#per_page-dropdown' do
|
63
|
+
expect(page).to have_link('15')
|
64
|
+
expect(page).to have_link('30')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
within ("#per_page-dropdown") do
|
68
|
+
click_link '30'
|
69
|
+
end
|
70
|
+
within ("#sortAndPerPage") do
|
71
|
+
expect(page).to have_content "1 - 30 of "
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should reset the page offset to 1 when changing per page" do
|
77
|
+
visit root_path
|
78
|
+
fill_in "q", with: ''
|
79
|
+
click_button 'search'
|
80
|
+
click_link "Next »"
|
81
|
+
within ("#sortAndPerPage") do
|
82
|
+
expect(page).to have_content "11 - 20 of "
|
83
|
+
end
|
84
|
+
within ("#per_page-dropdown") do
|
85
|
+
click_link '20'
|
86
|
+
end
|
87
|
+
within ("#sortAndPerPage") do
|
88
|
+
expect(page).to have_content "1 - 20 of "
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Search Results" do
|
5
|
+
it "should have for an empty query" do
|
6
|
+
visit root_path
|
7
|
+
click_button 'search'
|
8
|
+
number_of_results_from_page(page).should == 30
|
9
|
+
page.should have_xpath("//a[contains(@href, #{2007020969})]")
|
10
|
+
fill_in "q", with: 'korea'
|
11
|
+
click_button 'search'
|
12
|
+
number_of_results_from_page(page).should == 4
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should find same result set with or without diacritcs" do
|
16
|
+
visit root_path
|
17
|
+
fill_in "q", with: 'inmul'
|
18
|
+
click_button 'search'
|
19
|
+
number_of_results_from_page(page).should == 1
|
20
|
+
page.should have_xpath("//a[contains(@href, #{77826928})]")
|
21
|
+
|
22
|
+
fill_in "q", with: 'inmül'
|
23
|
+
click_button 'search'
|
24
|
+
number_of_results_from_page(page).should == 1
|
25
|
+
end
|
26
|
+
it "should find same result set for a case-insensitive query " do
|
27
|
+
visit root_path
|
28
|
+
fill_in "q", with: 'inmul'
|
29
|
+
click_button 'search'
|
30
|
+
number_of_results_from_page(page).should == 1
|
31
|
+
page.should have_xpath("//a[contains(@href, #{77826928})]")
|
32
|
+
|
33
|
+
fill_in "q", with: 'INMUL'
|
34
|
+
click_button 'search'
|
35
|
+
number_of_results_from_page(page).should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should order by relevancy" do
|
39
|
+
visit root_path
|
40
|
+
fill_in "q", with: 'Korea'
|
41
|
+
click_button 'search'
|
42
|
+
position_in_result_page(page, '77826928').should == 1
|
43
|
+
position_in_result_page(page, '94120425').should == 2
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def position_in_result_page(page, id)
|
52
|
+
i = -1
|
53
|
+
page.all(".index_title a").each_with_index do |link, idx|
|
54
|
+
i = (idx+1) if link['href'] =~ Regexp.new(Regexp.escape(id) + "$")
|
55
|
+
end
|
56
|
+
i.to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
def number_of_results_for_query(query)
|
60
|
+
visit root_path
|
61
|
+
fill_in "q", :with => query
|
62
|
+
click_button "search"
|
63
|
+
get_number_of_results_from_page(page)
|
64
|
+
end
|
65
|
+
|
66
|
+
def number_of_results_from_page(page)
|
67
|
+
page.find("meta[name=totalResults]")['content'].to_i rescue 0
|
68
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Search Sort" do
|
4
|
+
it "should sort on facet results with no search terms" do
|
5
|
+
visit root_path
|
6
|
+
click_link 'English'
|
7
|
+
expect(page).to have_content 'Sort by relevance'
|
8
|
+
click_link 'title'
|
9
|
+
expect(page).to have_content 'Sort by title'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should sort on search" do
|
13
|
+
visit root_path
|
14
|
+
fill_in "q", with: 'bod'
|
15
|
+
click_button 'search'
|
16
|
+
expect(page).to have_content 'Sort by relevance'
|
17
|
+
click_link 'title'
|
18
|
+
expect(page).to have_content 'Sort by title'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Search Page" do
|
5
|
+
it "should show welcome" do
|
6
|
+
visit root_path
|
7
|
+
expect(page).to have_selector("input#q")
|
8
|
+
within ("select#search_field") do
|
9
|
+
expect(page).to have_selector('option', text: 'All Fields')
|
10
|
+
expect(page).to have_selector('option', text: 'Title')
|
11
|
+
expect(page).to have_selector('option', text: 'Author')
|
12
|
+
expect(page).to have_selector('option', text: 'Subject')
|
13
|
+
end
|
14
|
+
expect(page).to have_selector("button[type='submit'] .submit-search-text")
|
15
|
+
expect(page).to_not have_selector("#startOverLink")
|
16
|
+
|
17
|
+
expect(page).to have_content "Welcome!"
|
18
|
+
expect(page).to have_selector("link[rel=stylesheet]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should do searches across all fields" do
|
22
|
+
visit root_path
|
23
|
+
fill_in "q", with: 'history'
|
24
|
+
select 'All Fields', from: 'search_field'
|
25
|
+
click_button 'search'
|
26
|
+
|
27
|
+
expect(page).to have_selector("link[rel=alternate][type='application/rss+xml']")
|
28
|
+
expect(page).to have_selector("link[rel=alternate][type='application/atom+xml']")
|
29
|
+
|
30
|
+
# opensearch
|
31
|
+
expect(page).to have_selector("meta[name=totalResults]")
|
32
|
+
expect(page).to have_selector("meta[name=startIndex]")
|
33
|
+
expect(page).to have_selector("meta[name=itemsPerPage]")
|
34
|
+
|
35
|
+
within "#appliedParams" do
|
36
|
+
expect(page).to have_content "You searched for:"
|
37
|
+
expect(page).to have_content "history"
|
38
|
+
end
|
39
|
+
|
40
|
+
within ("select#search_field") do
|
41
|
+
expect(page).to have_selector("option[selected]", text: "All Fields")
|
42
|
+
end
|
43
|
+
|
44
|
+
within ("#sortAndPerPage") do
|
45
|
+
expect(page).to have_content "Sort by"
|
46
|
+
expect(page).to have_content "1 - 9 of 9"
|
47
|
+
within '#sort-dropdown' do
|
48
|
+
expect(page).to have_link('relevance')
|
49
|
+
expect(page).to have_link('year')
|
50
|
+
expect(page).to have_link('author')
|
51
|
+
expect(page).to have_link('title')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
within "#documents" do
|
55
|
+
expect(page).to have_selector(".document", count: 9)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should do searches constrained to a single field" do
|
60
|
+
visit root_path
|
61
|
+
fill_in "q", with: 'inmul'
|
62
|
+
select 'Title', from: 'search_field'
|
63
|
+
click_button 'search'
|
64
|
+
|
65
|
+
within "#appliedParams" do
|
66
|
+
expect(page).to have_content "You searched for:"
|
67
|
+
expect(page).to have_content "Title"
|
68
|
+
expect(page).to have_content "inmul"
|
69
|
+
end
|
70
|
+
within ("select#search_field") do
|
71
|
+
expect(page).to have_selector("option[selected]", text: "Title")
|
72
|
+
end
|
73
|
+
within(".index_title") do
|
74
|
+
expect(page).to have_content "1."
|
75
|
+
end
|
76
|
+
within ("#sortAndPerPage") do
|
77
|
+
expect(page).to have_content "1 to 1 of 1"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should show vernacular (Linked 880) and call number" do
|
82
|
+
visit root_path
|
83
|
+
fill_in "q", with: 'history'
|
84
|
+
click_button 'search'
|
85
|
+
within "#documents" do
|
86
|
+
expect(page).to have_content "次按驟變"
|
87
|
+
expect(page).to have_content "DK861.K3 V5"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should allow you to clear the search" do
|
92
|
+
visit root_path
|
93
|
+
fill_in "q", with: 'history'
|
94
|
+
click_button 'search'
|
95
|
+
within "#appliedParams" do
|
96
|
+
expect(page).to have_content "You searched for:"
|
97
|
+
expect(page).to have_content "history"
|
98
|
+
end
|
99
|
+
|
100
|
+
expect(page).to have_selector "#q[value='history']"
|
101
|
+
|
102
|
+
click_link "Start Over"
|
103
|
+
|
104
|
+
expect(page).to have_content "Welcome!"
|
105
|
+
expect(page).to_not have_selector "#q[value='history']"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -165,9 +165,9 @@ describe BlacklightHelper do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should not return blacklisted elements" do
|
168
|
-
source_params = { :action => 'action', :controller => 'controller', :commit => 'commit'}
|
168
|
+
source_params = { :action => 'action', :controller => 'controller', :id => "id", :commit => 'commit'}
|
169
169
|
result = params_for_search(:params => source_params )
|
170
|
-
result.keys.should_not include(:action, :controller, :commit)
|
170
|
+
result.keys.should_not include(:action, :controller, :commit, :id)
|
171
171
|
|
172
172
|
end
|
173
173
|
|
@@ -479,6 +479,8 @@ describe BlacklightHelper do
|
|
479
479
|
@config = Blacklight::Configuration.new.configure do |config|
|
480
480
|
config.add_index_field 'qwer'
|
481
481
|
config.add_index_field 'asdf', :helper_method => :render_asdf_index_field
|
482
|
+
config.add_index_field 'link_to_search_true', :link_to_search => true
|
483
|
+
config.add_index_field 'link_to_search_named', :link_to_search => :some_field
|
482
484
|
config.add_index_field 'highlight', :highlight => true
|
483
485
|
end
|
484
486
|
helper.stub(:blacklight_config).and_return(@config)
|
@@ -499,6 +501,20 @@ describe BlacklightHelper do
|
|
499
501
|
value.should == 'custom asdf value'
|
500
502
|
end
|
501
503
|
|
504
|
+
it "should check for a link_to_search" do
|
505
|
+
doc = double()
|
506
|
+
doc.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
|
507
|
+
value = helper.render_index_field_value :document => doc, :field => 'link_to_search_true'
|
508
|
+
value.should == helper.link_to("x", helper.search_action_url(:f => { :link_to_search_true => ['x'] }))
|
509
|
+
end
|
510
|
+
|
511
|
+
it "should check for a link_to_search with a field name" do
|
512
|
+
doc = double()
|
513
|
+
doc.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
|
514
|
+
value = helper.render_index_field_value :document => doc, :field => 'link_to_search_named'
|
515
|
+
value.should == helper.link_to("x", helper.search_action_url(:f => { :some_field => ['x'] }))
|
516
|
+
end
|
517
|
+
|
502
518
|
it "should gracefully handle when no highlight field is available" do
|
503
519
|
doc = double()
|
504
520
|
doc.should_not_receive(:get)
|
@@ -537,6 +553,8 @@ describe BlacklightHelper do
|
|
537
553
|
@config = Blacklight::Configuration.new.configure do |config|
|
538
554
|
config.add_show_field 'qwer'
|
539
555
|
config.add_show_field 'asdf', :helper_method => :render_asdf_document_show_field
|
556
|
+
config.add_show_field 'link_to_search_true', :link_to_search => true
|
557
|
+
config.add_show_field 'link_to_search_named', :link_to_search => :some_field
|
540
558
|
config.add_show_field 'highlight', :highlight => true
|
541
559
|
end
|
542
560
|
helper.stub(:blacklight_config).and_return(@config)
|
@@ -558,6 +576,20 @@ describe BlacklightHelper do
|
|
558
576
|
value.should == 'custom asdf value'
|
559
577
|
end
|
560
578
|
|
579
|
+
it "should check for a link_to_search" do
|
580
|
+
doc = double()
|
581
|
+
doc.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
|
582
|
+
value = helper.render_document_show_field_value :document => doc, :field => 'link_to_search_true'
|
583
|
+
value.should == helper.link_to("x", helper.search_action_url(:f => { :link_to_search_true => ['x'] }))
|
584
|
+
end
|
585
|
+
|
586
|
+
it "should check for a link_to_search with a field name" do
|
587
|
+
doc = double()
|
588
|
+
doc.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
|
589
|
+
value = helper.render_document_show_field_value :document => doc, :field => 'link_to_search_named'
|
590
|
+
value.should == helper.link_to("x", helper.search_action_url(:f => { :some_field => ['x'] }))
|
591
|
+
end
|
592
|
+
|
561
593
|
it "should gracefully handle when no highlight field is available" do
|
562
594
|
doc = double()
|
563
595
|
doc.should_not_receive(:get)
|
@@ -626,4 +658,15 @@ describe BlacklightHelper do
|
|
626
658
|
end
|
627
659
|
end
|
628
660
|
|
661
|
+
|
662
|
+
describe "render_grouped_response?" do
|
663
|
+
it "should check if the response contains grouped data" do
|
664
|
+
assign(:response, double("SolrResponse", :grouped? => true))
|
665
|
+
expect(helper.render_grouped_response?).to be_true
|
666
|
+
end
|
667
|
+
end
|
668
|
+
|
669
|
+
describe "render_grouped_document_index" do
|
670
|
+
|
671
|
+
end
|
629
672
|
end
|
@@ -11,13 +11,20 @@ describe CatalogHelper do
|
|
11
11
|
start = (current_page - 1) * per_page
|
12
12
|
|
13
13
|
mock_response = double("Blacklight::SolrResponse")
|
14
|
-
mock_response.stub(:
|
14
|
+
mock_response.stub(:total_count).and_return(total)
|
15
|
+
mock_response.stub(:current_page).and_return(current_page)
|
16
|
+
mock_response.stub(:total_pages).and_return((total / per_page).to_i + 1)
|
15
17
|
mock_response.stub(:rows).and_return(per_page)
|
16
18
|
mock_response.stub(:start).and_return(start)
|
17
19
|
mock_response.stub(:docs).and_return((1..total).to_a.slice(start, per_page))
|
18
20
|
|
19
21
|
mock_response
|
20
22
|
end
|
23
|
+
|
24
|
+
def render_grouped_response?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
21
28
|
|
22
29
|
describe "render_pagination_info" do
|
23
30
|
before(:all) do
|
@@ -87,4 +94,130 @@ describe CatalogHelper do
|
|
87
94
|
end
|
88
95
|
|
89
96
|
end
|
97
|
+
|
98
|
+
describe "should_autofocus_on_search_box?" do
|
99
|
+
it "should be focused if we're on a catalog-like index page without query or facet parameters" do
|
100
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { })
|
101
|
+
expect(helper.should_autofocus_on_search_box?).to be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not be focused if we're not on a catalog controller" do
|
105
|
+
helper.stub(:controller => ApplicationController.new)
|
106
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not be focused if we're not on a catalog controller index" do
|
110
|
+
helper.stub(:controller => CatalogController.new, :action_name => "show")
|
111
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not be focused if a search string is provided" do
|
115
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :q => "hello"})
|
116
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not be focused if a facet is selected" do
|
120
|
+
helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :f => { "field" => ["value"]}})
|
121
|
+
expect(helper.should_autofocus_on_search_box?).to be_false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "has_thumbnail?" do
|
126
|
+
it "should have a thumbnail if a thumbnail_method is configured" do
|
127
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_method => :xyz) ))
|
128
|
+
document = double()
|
129
|
+
expect(helper.has_thumbnail? document).to be_true
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should have a thumbnail if a thumbnail_field is configured and it exists in the document" do
|
133
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_field => :xyz) ))
|
134
|
+
document = double(:has_field? => true)
|
135
|
+
expect(helper.has_thumbnail? document).to be_true
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not have a thumbnail if the thumbnail_field is missing from the document" do
|
139
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new(:thumbnail_field => :xyz) ))
|
140
|
+
document = double(:has_field? => false)
|
141
|
+
expect(helper.has_thumbnail? document).to be_false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should not have a thumbnail if none of the fields are configured" do
|
145
|
+
helper.stub(:blacklight_config => OpenStruct.new(:index => OpenStruct.new()))
|
146
|
+
expect(helper.has_thumbnail? double()).to be_false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "render_thumbnail_tag" do
|
151
|
+
it "should call the provided thumbnail method" do
|
152
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_method => :xyz)))
|
153
|
+
document = double()
|
154
|
+
helper.stub(:xyz => "some-thumbnail")
|
155
|
+
|
156
|
+
helper.should_receive(:link_to_document).with(document, :label => "some-thumbnail")
|
157
|
+
helper.render_thumbnail_tag document
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should create an image tag from the given field" do
|
161
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new(:thumbnail_field => :xyz)))
|
162
|
+
document = double()
|
163
|
+
|
164
|
+
document.stub(:has_field?).with(:xyz).and_return(true)
|
165
|
+
document.stub(:get).with(:xyz, :sep => nil).and_return(["http://example.com/some.jpg"])
|
166
|
+
|
167
|
+
helper.should_receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
|
168
|
+
helper.render_thumbnail_tag document
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return nil if no thumbnail is available" do
|
172
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new()))
|
173
|
+
|
174
|
+
document = double()
|
175
|
+
expect(helper.render_thumbnail_tag document).to be_nil
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return nil if no thumbnail is returned from the thumbnail method" do
|
179
|
+
helper.stub(:blacklight_config => double(:index => OpenStruct.new(:thumbnail_method => :xyz)))
|
180
|
+
helper.stub(:xyz => nil)
|
181
|
+
document = double()
|
182
|
+
|
183
|
+
expect(helper.render_thumbnail_tag document).to be_nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "thumbnail_url" do
|
188
|
+
it "should pull the configured thumbnail field out of the document" do
|
189
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_field => "xyz")))
|
190
|
+
document = double()
|
191
|
+
document.stub(:has_field?).with("xyz").and_return(true)
|
192
|
+
document.stub(:get).with("xyz", :sep => nil).and_return(["asdf"])
|
193
|
+
expect(helper.thumbnail_url document).to eq("asdf")
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should return nil if the thumbnail field doesn't exist" do
|
197
|
+
helper.stub(:blacklight_config => double(:index => double(:thumbnail_field => "xyz")))
|
198
|
+
document = double()
|
199
|
+
document.stub(:has_field?).with("xyz").and_return(false)
|
200
|
+
expect(helper.thumbnail_url document).to be_nil
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "document_counter_with_offset" do
|
205
|
+
it "should render the document index with the appropriate offset" do
|
206
|
+
assign(:response, double(:params => { :start => 0 }, :grouped? => false))
|
207
|
+
expect(helper.document_counter_with_offset(0)).to be(1)
|
208
|
+
expect(helper.document_counter_with_offset(1)).to be(2)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should render the document index with the appropriate offset" do
|
212
|
+
assign(:response, double(:params => { :start => 10 }, :grouped? => false))
|
213
|
+
expect(helper.document_counter_with_offset(0)).to be(11)
|
214
|
+
expect(helper.document_counter_with_offset(1)).to be(12)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should not provide a counter for grouped responses" do
|
218
|
+
assign(:response, double(:params => { :start => 10 }, :grouped? => true))
|
219
|
+
expect(helper.document_counter_with_offset(0)).to be_nil
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
90
223
|
end
|