blacklight 7.0.0.rc1 → 7.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +30 -18
- data/.rubocop_todo.yml +308 -67
- data/.solr_wrapper.yml +8 -1
- data/.travis.yml +15 -13
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/Vagrantfile +2 -0
- data/app/assets/javascripts/blacklight/blacklight.js +17 -17
- data/app/assets/stylesheets/blacklight/_blacklight_base.scss +17 -16
- data/app/assets/stylesheets/blacklight/_facets.scss +2 -13
- data/app/assets/stylesheets/blacklight/_icons.scss +8 -2
- data/app/assets/stylesheets/blacklight/_search_form.scss +7 -0
- data/app/assets/stylesheets/blacklight/blacklight.scss +1 -1
- data/app/builders/blacklight/action_builder.rb +1 -0
- data/app/controllers/concerns/blacklight/bookmarks.rb +19 -13
- data/app/controllers/concerns/blacklight/catalog.rb +19 -7
- data/app/controllers/concerns/blacklight/controller.rb +12 -18
- data/app/controllers/concerns/blacklight/facet.rb +3 -0
- data/app/controllers/concerns/blacklight/search_context.rb +7 -3
- data/app/controllers/concerns/blacklight/search_history.rb +1 -6
- data/app/controllers/concerns/blacklight/token_based_user.rb +3 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +5 -1
- data/app/helpers/blacklight/configuration_helper_behavior.rb +5 -3
- data/app/helpers/blacklight/facets_helper_behavior.rb +15 -12
- data/app/helpers/blacklight/icon_helper_behavior.rb +2 -0
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -0
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +29 -14
- data/app/javascript/blacklight/checkbox_submit.js +9 -8
- data/app/javascript/blacklight/core.js +8 -6
- data/app/javascript/blacklight/modal.js +1 -3
- data/app/javascript/blacklight/search_context.js +0 -1
- data/app/models/blacklight/icon.rb +3 -0
- data/app/models/blacklight/suggest_search.rb +3 -14
- data/app/models/bookmark.rb +1 -1
- data/app/models/concerns/blacklight/document.rb +3 -1
- data/app/models/concerns/blacklight/solr/document.rb +1 -0
- data/app/models/concerns/blacklight/suggest/response.rb +5 -3
- data/app/models/concerns/blacklight/user.rb +1 -0
- data/app/models/search.rb +1 -0
- data/app/presenters/blacklight/document_presenter.rb +38 -0
- data/app/presenters/blacklight/field_presenter.rb +2 -0
- data/app/presenters/blacklight/index_presenter.rb +13 -5
- data/app/presenters/blacklight/json_presenter.rb +5 -12
- data/app/presenters/blacklight/link_alternate_presenter.rb +2 -0
- data/app/presenters/blacklight/rendering/abstract_step.rb +2 -0
- data/app/presenters/blacklight/rendering/helper_method.rb +2 -0
- data/app/presenters/blacklight/rendering/join.rb +2 -0
- data/app/presenters/blacklight/rendering/link_to_facet.rb +4 -0
- data/app/presenters/blacklight/rendering/microdata.rb +3 -0
- data/app/presenters/blacklight/rendering/pipeline.rb +2 -0
- data/app/presenters/blacklight/rendering/terminator.rb +2 -0
- data/app/presenters/blacklight/search_bar_presenter.rb +2 -0
- data/app/presenters/blacklight/show_presenter.rb +8 -5
- data/app/presenters/blacklight/thumbnail_presenter.rb +2 -0
- data/app/services/blacklight/document_factory.rb +2 -0
- data/app/services/blacklight/field_retriever.rb +2 -0
- data/app/services/blacklight/search_service.rb +7 -9
- data/app/values/blacklight/types.rb +3 -0
- data/app/views/bookmarks/index.html.erb +12 -13
- data/app/views/catalog/_citation.html.erb +4 -4
- data/app/views/catalog/_constraints.html.erb +2 -0
- data/app/views/catalog/_did_you_mean.html.erb +1 -1
- data/app/views/catalog/_document.atom.builder +17 -16
- data/app/views/catalog/_document.rss.builder +2 -0
- data/app/views/catalog/_facet_index_navigation.html.erb +5 -4
- data/app/views/catalog/_facet_layout.html.erb +3 -5
- data/app/views/catalog/_facets.html.erb +5 -4
- data/app/views/catalog/_field.json.jbuilder +10 -0
- data/app/views/catalog/_group.html.erb +1 -1
- data/app/views/catalog/_home_text.html.erb +5 -5
- data/app/views/catalog/_index.html.erb +5 -7
- data/app/views/catalog/_index_header.html.erb +1 -1
- data/app/views/catalog/_per_page_widget.html.erb +1 -1
- data/app/views/catalog/_results_pagination.html.erb +2 -2
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_search_results.html.erb +2 -2
- data/app/views/catalog/_show.html.erb +3 -5
- data/app/views/catalog/_show_more_like_this.html.erb +1 -1
- data/app/views/catalog/_show_sidebar.html.erb +1 -1
- data/app/views/catalog/_show_tools.html.erb +1 -1
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +1 -1
- data/app/views/catalog/citation.js.erb +1 -1
- data/app/views/catalog/facet.html.erb +5 -4
- data/app/views/catalog/facet.json.jbuilder +2 -0
- data/app/views/catalog/index.atom.builder +4 -2
- data/app/views/catalog/index.json.jbuilder +29 -10
- data/app/views/catalog/index.rss.builder +2 -0
- data/app/views/catalog/opensearch.xml.builder +3 -1
- data/app/views/catalog/show.json.jbuilder +21 -0
- data/app/views/kaminari/blacklight/_first_page.html.erb +1 -1
- data/app/views/kaminari/blacklight/_last_page.html.erb +1 -1
- data/app/views/kaminari/blacklight/_next_page.html.erb +3 -3
- data/app/views/kaminari/blacklight/_page.html.erb +4 -2
- data/app/views/kaminari/blacklight/_prev_page.html.erb +2 -2
- data/app/views/layouts/blacklight.html.erb +4 -4
- data/app/views/layouts/blacklight/base.html.erb +1 -9
- data/app/views/search_history/index.html.erb +3 -3
- data/app/views/shared/_header_navbar.html.erb +1 -1
- data/app/views/shared/_modal.html.erb +2 -2
- data/blacklight.gemspec +7 -6
- data/config/i18n-tasks.yml +17 -0
- data/config/locales/blacklight.de.yml +72 -57
- data/config/locales/blacklight.en.yml +11 -1
- data/config/locales/blacklight.es.yml +15 -1
- data/config/locales/blacklight.fr.yml +17 -8
- data/config/locales/blacklight.hu.yml +3 -1
- data/config/locales/blacklight.it.yml +16 -1
- data/config/locales/blacklight.nl.yml +3 -1
- data/config/locales/blacklight.pt-BR.yml +19 -2
- data/config/locales/blacklight.sq.yml +3 -1
- data/config/locales/blacklight.zh.yml +3 -1
- data/config/routes.rb +0 -1
- data/lib/blacklight.rb +3 -0
- data/lib/blacklight/abstract_repository.rb +12 -0
- data/lib/blacklight/configuration.rb +21 -3
- data/lib/blacklight/configuration/context.rb +11 -0
- data/lib/blacklight/configuration/fields.rb +31 -26
- data/lib/blacklight/configuration/null_field.rb +2 -0
- data/lib/blacklight/engine.rb +4 -1
- data/lib/blacklight/routes/exportable.rb +1 -3
- data/lib/blacklight/routes/searchable.rb +2 -3
- data/lib/blacklight/runtime_registry.rb +2 -0
- data/lib/blacklight/search_builder.rb +2 -0
- data/lib/blacklight/search_state.rb +2 -0
- data/lib/blacklight/solr/repository.rb +34 -0
- data/lib/blacklight/solr/response/spelling.rb +1 -0
- data/lib/generators/blacklight/assets_generator.rb +10 -9
- data/lib/generators/blacklight/controller_generator.rb +1 -1
- data/lib/generators/blacklight/install_generator.rb +7 -14
- data/lib/generators/blacklight/solr_generator.rb +8 -0
- data/lib/generators/blacklight/templates/alternate_controller.rb +4 -4
- data/lib/generators/blacklight/templates/catalog_controller.rb +7 -1
- data/lib/generators/blacklight/templates/solr/conf/schema.xml +20 -22
- data/lib/generators/blacklight/user_generator.rb +2 -0
- data/lib/railties/blacklight.rake +9 -13
- data/package-lock.json +544 -406
- data/package.json +3 -2
- data/spec/controllers/alternate_controller_spec.rb +4 -3
- data/spec/controllers/application_controller_spec.rb +0 -4
- data/spec/controllers/blacklight/base_spec.rb +5 -2
- data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +4 -4
- data/spec/controllers/blacklight/facet_spec.rb +0 -1
- data/spec/controllers/blacklight/search_fields_spec.rb +25 -22
- data/spec/controllers/bookmarks_controller_spec.rb +45 -10
- data/spec/controllers/catalog_controller_spec.rb +206 -138
- data/spec/controllers/search_history_controller_spec.rb +4 -4
- data/spec/features/alternate_controller_spec.rb +3 -3
- data/spec/features/autocomplete_spec.rb +2 -0
- data/spec/features/did_you_mean_spec.rb +4 -3
- data/spec/features/facets_spec.rb +7 -7
- data/spec/features/record_view_spec.rb +11 -12
- data/spec/features/search_context_spec.rb +4 -5
- data/spec/features/search_crawler_spec.rb +3 -5
- data/spec/features/search_filters_spec.rb +44 -44
- data/spec/features/search_history_spec.rb +5 -3
- data/spec/features/search_pagination_spec.rb +3 -1
- data/spec/features/search_results_spec.rb +11 -8
- data/spec/features/search_spec.rb +3 -3
- data/spec/features/sitelinks_search_box.rb +4 -4
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +30 -30
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +65 -59
- data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight/icon_helper_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +8 -3
- data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +16 -4
- data/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +21 -22
- data/spec/helpers/blacklight/suggest_helper_behavior_spec.rb +6 -1
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +49 -43
- data/spec/helpers/blacklight_helper_spec.rb +28 -12
- data/spec/helpers/catalog_helper_spec.rb +50 -47
- data/spec/i18n_spec.rb +18 -0
- data/spec/integration/generators/blacklight/solr_generator_spec.rb +18 -10
- data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -0
- data/spec/lib/blacklight/configuration/field_spec.rb +3 -0
- data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +15 -20
- data/spec/lib/blacklight/parameters_spec.rb +3 -1
- data/spec/lib/blacklight/search_state_spec.rb +51 -34
- data/spec/lib/blacklight_spec.rb +13 -14
- data/spec/lib/tasks/blacklight_task_spec.rb +3 -5
- data/spec/models/blacklight/configurable_spec.rb +11 -13
- data/spec/models/blacklight/configuration/context_spec.rb +9 -10
- data/spec/models/blacklight/configuration_spec.rb +103 -91
- data/spec/models/blacklight/document/active_model_shim_spec.rb +5 -6
- data/spec/models/blacklight/document/cache_key_spec.rb +9 -2
- data/spec/models/blacklight/document/dublin_core_spec.rb +16 -19
- data/spec/models/blacklight/document/email_spec.rb +9 -9
- data/spec/models/blacklight/document/sms_spec.rb +9 -9
- data/spec/models/blacklight/document_spec.rb +9 -8
- data/spec/models/blacklight/facet_paginator_spec.rb +40 -30
- data/spec/models/blacklight/icon_spec.rb +12 -2
- data/spec/models/blacklight/search_builder_spec.rb +12 -3
- data/spec/models/blacklight/solr/document_spec.rb +216 -219
- data/spec/models/blacklight/solr/facet_paginator_spec.rb +6 -4
- data/spec/models/blacklight/solr/repository_spec.rb +37 -34
- data/spec/models/blacklight/solr/request_spec.rb +17 -18
- data/spec/models/blacklight/solr/response/facets_spec.rb +58 -58
- data/spec/models/blacklight/solr/response/group_response_spec.rb +16 -22
- data/spec/models/blacklight/solr/response/group_spec.rb +18 -25
- data/spec/models/blacklight/solr/response_spec.rb +48 -50
- data/spec/models/blacklight/solr/search_builder_spec.rb +120 -121
- data/spec/models/blacklight/suggest/response_spec.rb +6 -4
- data/spec/models/blacklight/suggest_search_spec.rb +9 -16
- data/spec/models/blacklight/user_spec.rb +9 -11
- data/spec/models/bookmark_spec.rb +6 -5
- data/spec/models/record_mailer_spec.rb +22 -20
- data/spec/models/search_spec.rb +18 -17
- data/spec/models/solr_document_spec.rb +6 -2
- data/spec/presenters/blacklight/document_presenter_spec.rb +86 -0
- data/spec/presenters/blacklight/index_presenter_spec.rb +186 -0
- data/spec/presenters/blacklight/json_presenter_spec.rb +59 -0
- data/spec/presenters/blacklight/link_alternate_presenter_spec.rb +3 -0
- data/spec/presenters/blacklight/search_bar_presenter_spec.rb +7 -0
- data/spec/presenters/{show_presenter_spec.rb → blacklight/show_presenter_spec.rb} +138 -91
- data/spec/presenters/pipeline_spec.rb +15 -8
- data/spec/presenters/thumbnail_presenter_spec.rb +5 -2
- data/spec/routing/catalog_routing_spec.rb +12 -14
- data/spec/services/blacklight/search_service_spec.rb +112 -70
- data/spec/spec_helper.rb +6 -2
- data/spec/support/features.rb +1 -1
- data/spec/support/features/session_helpers.rb +4 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -13
- data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -3
- data/spec/views/catalog/_constraints_element.html.erb_spec.rb +9 -5
- data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_facets.html.erb_spec.rb +8 -10
- data/spec/views/catalog/_index.html.erb_spec.rb +13 -14
- data/spec/views/catalog/_index_header.html.erb_spec.rb +5 -8
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_show.html.erb_spec.rb +12 -13
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +4 -7
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +0 -1
- data/spec/views/catalog/_sort_widget.html.erb_spec.rb +3 -1
- data/spec/views/catalog/_thumbnail.html.erb_spec.rb +6 -8
- data/spec/views/catalog/_view_type_group.html.erb_spec.rb +7 -9
- data/spec/views/catalog/email_success.html.erb_spec.rb +0 -1
- data/spec/views/catalog/facet.html.erb_spec.rb +3 -2
- data/spec/views/catalog/facet.json.jbuilder_spec.rb +3 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +9 -4
- data/spec/views/catalog/index.html.erb_spec.rb +2 -1
- data/spec/views/catalog/index.json.jbuilder_spec.rb +84 -36
- data/spec/views/catalog/show.html.erb_spec.rb +6 -6
- data/spec/views/catalog/show.json.jbuilder_spec.rb +40 -0
- data/spec/views/catalog/sms_success.html.erb_spec.rb +0 -1
- data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -4
- data/tasks/blacklight.rake +6 -4
- data/template.demo.rb +2 -0
- metadata +50 -24
- data/app/javascript/blacklight/autofocus.js +0 -20
- data/spec/presenters/index_presenter_spec.rb +0 -150
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe Blacklight::Suggest::Response do
|
4
|
-
let(:empty_response) { described_class.new({}, { q: 'hello' }, 'suggest') }
|
3
|
+
RSpec.describe Blacklight::Suggest::Response, api: true do
|
4
|
+
let(:empty_response) { described_class.new({}, { q: 'hello' }, 'suggest', 'mySuggester') }
|
5
5
|
let(:full_response) do
|
6
6
|
described_class.new(
|
7
7
|
{
|
@@ -36,7 +36,8 @@ RSpec.describe Blacklight::Suggest::Response do
|
|
36
36
|
{
|
37
37
|
q: 'new'
|
38
38
|
},
|
39
|
-
'suggest'
|
39
|
+
'suggest',
|
40
|
+
'mySuggester'
|
40
41
|
)
|
41
42
|
end
|
42
43
|
|
@@ -45,6 +46,7 @@ RSpec.describe Blacklight::Suggest::Response do
|
|
45
46
|
expect(empty_response).to be_an Blacklight::Suggest::Response
|
46
47
|
end
|
47
48
|
end
|
49
|
+
|
48
50
|
describe '#suggestions' do
|
49
51
|
it 'returns an array of suggestions' do
|
50
52
|
expect(full_response.suggestions).to be_an Array
|
@@ -52,4 +54,4 @@ RSpec.describe Blacklight::Suggest::Response do
|
|
52
54
|
expect(full_response.suggestions.first['term']).to eq 'new jersey'
|
53
55
|
end
|
54
56
|
end
|
55
|
-
end
|
57
|
+
end
|
@@ -1,22 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe Blacklight::SuggestSearch do
|
4
|
-
let(:params) { {q: 'test'} }
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
|
3
|
+
RSpec.describe Blacklight::SuggestSearch, api: true do
|
4
|
+
let(:params) { { q: 'test' } }
|
5
|
+
let(:response) { instance_double(Blacklight::Suggest::Response) }
|
6
|
+
let(:repository) { instance_double(Blacklight::Solr::Repository, suggestions: response) }
|
7
|
+
let(:suggest_search) { described_class.new(params, repository) }
|
8
|
+
|
9
9
|
describe '#suggestions' do
|
10
|
-
it '
|
11
|
-
expect(
|
12
|
-
expect(suggest_search).to
|
13
|
-
expect(suggest_search.suggestions).to be_an Blacklight::Suggest::Response
|
14
|
-
end
|
15
|
-
end
|
16
|
-
describe '#suggest_results' do
|
17
|
-
it 'calls send_and_recieve from a repository connection' do
|
18
|
-
expect(suggest_search).to receive(:suggest_handler_path).and_return(suggest_path)
|
19
|
-
expect(suggest_search.suggest_results).to eq 'sent'
|
10
|
+
it 'delegates to the repository' do
|
11
|
+
expect(repository).to receive(:suggestions).with(q: 'test').and_return(response)
|
12
|
+
expect(suggest_search.suggestions).to eq response
|
20
13
|
end
|
21
14
|
end
|
22
15
|
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe "Blacklight::User" do
|
4
|
-
|
5
|
-
subject { User.create! :email => 'xyz@example.com', :password => 'xyz12345' }
|
3
|
+
RSpec.describe "Blacklight::User", api: true do
|
4
|
+
subject { User.create! email: 'xyz@example.com', password: 'xyz12345' }
|
6
5
|
|
7
6
|
def mock_bookmark document_id
|
8
7
|
Bookmark.new document_id: document_id, document_type: SolrDocument.to_s
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
describe "#bookmarks_for_documents" do
|
12
11
|
before do
|
13
12
|
subject.bookmarks << mock_bookmark(1)
|
14
13
|
subject.bookmarks << mock_bookmark(2)
|
15
14
|
subject.bookmarks << mock_bookmark(3)
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
it "returns all the bookmarks that match the given documents" do
|
19
18
|
bookmarks = subject.bookmarks_for_documents([SolrDocument.new(id: 1), SolrDocument.new(id: 2)])
|
20
19
|
expect(bookmarks).to have(2).items
|
@@ -22,18 +21,18 @@ RSpec.describe "Blacklight::User" do
|
|
22
21
|
expect(bookmarks.last.document_id).to eq "2"
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
describe "#document_is_bookmarked?" do
|
27
26
|
before do
|
28
27
|
subject.bookmarks << mock_bookmark(1)
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
it "is true if the document is bookmarked" do
|
32
31
|
expect(subject).to be_document_is_bookmarked(SolrDocument.new(id: 1))
|
33
32
|
end
|
34
33
|
|
35
34
|
it "is false if the document is not bookmarked" do
|
36
|
-
expect(subject).
|
35
|
+
expect(subject).not_to be_document_is_bookmarked(SolrDocument.new(id: 2))
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -41,10 +40,9 @@ RSpec.describe "Blacklight::User" do
|
|
41
40
|
before do
|
42
41
|
subject.bookmarks << mock_bookmark(1)
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
it "returns the bookmark for that document id" do
|
46
45
|
expect(subject.existing_bookmark_for(SolrDocument.new(id: 1))).to eq subject.bookmarks.first
|
47
46
|
end
|
48
47
|
end
|
49
|
-
|
50
|
-
end
|
48
|
+
end
|
@@ -1,32 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Bookmark do
|
4
|
-
let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345'}
|
5
4
|
subject do
|
6
|
-
b =
|
5
|
+
b = described_class.new(user: user)
|
7
6
|
b.document = SolrDocument.new(id: 'u001')
|
8
7
|
b
|
9
8
|
end
|
10
9
|
|
10
|
+
let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345' }
|
11
|
+
|
11
12
|
it "is valid" do
|
12
13
|
expect(subject).to be_valid
|
13
14
|
end
|
14
15
|
|
15
16
|
it "belongs to user" do
|
16
|
-
expect(
|
17
|
+
expect(described_class.reflect_on_association(:user)).not_to be_nil
|
17
18
|
end
|
18
19
|
|
19
20
|
it "is valid after saving" do
|
20
21
|
subject.save
|
21
22
|
expect(subject).to be_valid
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
describe "#document_type" do
|
25
26
|
it "is the class of the solr document" do
|
26
27
|
expect(subject.document_type).to eq SolrDocument
|
27
28
|
end
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
describe "#document" do
|
31
32
|
it "is a SolrDocument with just an id field" do
|
32
33
|
expect(subject.document).to be_a_kind_of SolrDocument
|
@@ -1,18 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe RecordMailer do
|
4
|
-
before
|
5
|
-
allow(
|
6
|
-
SolrDocument.use_extension(
|
7
|
-
SolrDocument.use_extension(
|
8
|
-
document = SolrDocument.new(
|
4
|
+
before do
|
5
|
+
allow(described_class).to receive(:default).and_return(from: 'no-reply@projectblacklight.org')
|
6
|
+
SolrDocument.use_extension(Blacklight::Document::Email)
|
7
|
+
SolrDocument.use_extension(Blacklight::Document::Sms)
|
8
|
+
document = SolrDocument.new(id: "123456", format: ["book"], title_tsim: "The horn", language_ssim: "English", author_tsim: "Janetzky, Kurt")
|
9
9
|
@documents = [document]
|
10
10
|
end
|
11
|
+
|
11
12
|
describe "email" do
|
12
|
-
before
|
13
|
-
details = {:
|
14
|
-
@email =
|
13
|
+
before do
|
14
|
+
details = { to: 'test@test.com', message: "This is my message" }
|
15
|
+
@email = described_class.email_record(@documents, details, host: 'projectblacklight.org', protocol: 'https')
|
15
16
|
end
|
17
|
+
|
16
18
|
it "receives the TO paramater and send the email to that address" do
|
17
19
|
expect(@email.to).to include 'test@test.com'
|
18
20
|
end
|
@@ -31,17 +33,18 @@ RSpec.describe RecordMailer do
|
|
31
33
|
expect(@email.body).to match /projectblacklight.org/
|
32
34
|
end
|
33
35
|
it "uses https URLs when protocol is set" do
|
34
|
-
details = {:
|
35
|
-
@https_email =
|
36
|
-
expect(@https_email.body).to match %r
|
36
|
+
details = { to: 'test@test.com', message: "This is my message" }
|
37
|
+
@https_email = described_class.email_record(@documents, details, host: 'projectblacklight.org', protocol: 'https')
|
38
|
+
expect(@https_email.body).to match %r{https://projectblacklight.org/}
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
describe "SMS" do
|
41
|
-
before
|
42
|
-
details = {:
|
43
|
-
@sms =
|
43
|
+
before do
|
44
|
+
details = { to: '5555555555@txt.att.net' }
|
45
|
+
@sms = described_class.sms_record(@documents, details, host: 'projectblacklight.org:3000')
|
44
46
|
end
|
47
|
+
|
45
48
|
it "creates the correct TO address for the SMS email" do
|
46
49
|
expect(@sms.to).to include '5555555555@txt.att.net'
|
47
50
|
end
|
@@ -54,13 +57,12 @@ RSpec.describe RecordMailer do
|
|
54
57
|
it "prints out the correct body" do
|
55
58
|
expect(@sms.body).to match /The horn/
|
56
59
|
expect(@sms.body).to match /by Janetzky, Kurt/
|
57
|
-
expect(@sms.body).to match /projectblacklight.org:3000/
|
60
|
+
expect(@sms.body).to match /projectblacklight.org:3000/
|
58
61
|
end
|
59
62
|
it "uses https URL when protocol is set" do
|
60
|
-
details = {:
|
61
|
-
@https_sms =
|
62
|
-
expect(@https_sms.body).to match %r
|
63
|
+
details = { to: '5555555555@txt.att.net' }
|
64
|
+
@https_sms = described_class.sms_record(@documents, details, host: 'projectblacklight.org', protocol: 'https')
|
65
|
+
expect(@https_sms.body).to match %r{https://projectblacklight.org/}
|
63
66
|
end
|
64
67
|
end
|
65
|
-
|
66
68
|
end
|
data/spec/models/search_spec.rb
CHANGED
@@ -1,57 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Search do
|
4
|
-
let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345'}
|
4
|
+
let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345' }
|
5
|
+
|
5
6
|
describe "query_params" do
|
6
|
-
before
|
7
|
-
@search =
|
8
|
-
@query_params = { :
|
7
|
+
before do
|
8
|
+
@search = described_class.new(user: user)
|
9
|
+
@query_params = { q: "query", f: "facet" }
|
9
10
|
end
|
10
11
|
|
11
12
|
it "can save and retrieve the hash" do
|
12
13
|
@search.query_params = @query_params
|
13
14
|
@search.save!
|
14
|
-
expect(
|
15
|
+
expect(described_class.find(@search.id).query_params).to eq @query_params
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
describe "saved?" do
|
19
20
|
it "is true when user_id is not NULL and greater than 0" do
|
20
|
-
@search =
|
21
|
+
@search = described_class.new(user: user)
|
21
22
|
@search.save!
|
22
23
|
|
23
24
|
expect(@search).to be_saved
|
24
25
|
end
|
25
26
|
it "is false when user_id is NULL or less than 1" do
|
26
|
-
@search =
|
27
|
+
@search = described_class.create
|
27
28
|
expect(@search).not_to be_saved
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
describe "delete_old_searches" do
|
32
33
|
it "throws an ArgumentError if days_old is not a number" do
|
33
|
-
expect {
|
34
|
+
expect { described_class.delete_old_searches("blah") }.to raise_error(ArgumentError)
|
34
35
|
end
|
35
36
|
|
36
37
|
it "throws an ArgumentError if days_old is equal to 0" do
|
37
|
-
expect {
|
38
|
+
expect { described_class.delete_old_searches(0) }.to raise_error(ArgumentError)
|
38
39
|
end
|
39
40
|
|
40
41
|
it "throws an ArgumentError if days_old is less than 0" do
|
41
|
-
expect {
|
42
|
+
expect { described_class.delete_old_searches(-1) }.to raise_error(ArgumentError)
|
42
43
|
end
|
43
44
|
|
44
45
|
it "destroy searches with no user_id that are older than X days" do
|
45
|
-
|
46
|
+
described_class.destroy_all
|
46
47
|
days_old = 7
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
described_class.create!(created_at: Date.today)
|
49
|
+
described_class.create!(created_at: Date.today - (days_old + 1).days)
|
50
|
+
described_class.create!(user: user, created_at: Date.today)
|
51
|
+
described_class.create!(user: user, created_at: Date.today - (days_old + 1).days)
|
51
52
|
|
52
53
|
expect do
|
53
|
-
|
54
|
-
end.to change(
|
54
|
+
described_class.delete_old_searches(days_old)
|
55
|
+
end.to change(described_class, :count).by(-1)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe SolrDocument do
|
3
|
+
RSpec.describe SolrDocument, api: true do
|
4
4
|
describe "access methods" do
|
5
5
|
let(:solrdoc) do
|
6
6
|
SolrDocument.new(id: '00282214', format: ['Book'], title_tsim: 'some-title')
|
@@ -11,28 +11,32 @@ RSpec.describe SolrDocument do
|
|
11
11
|
|
12
12
|
context "with title_tsim" do
|
13
13
|
let(:field) { :title_tsim }
|
14
|
+
|
14
15
|
it { is_expected.to eq 'some-title' }
|
15
16
|
end
|
17
|
+
|
16
18
|
context "with format" do
|
17
19
|
let(:field) { :format }
|
20
|
+
|
18
21
|
it { is_expected.to eq ['Book'] }
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
describe "#id" do
|
23
26
|
subject { solrdoc.id }
|
27
|
+
|
24
28
|
it { is_expected.to eq '00282214' }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
describe '.attribute' do
|
29
33
|
subject(:title) { document.title }
|
34
|
+
|
30
35
|
let(:doc_class) do
|
31
36
|
Class.new(SolrDocument) do
|
32
37
|
attribute :title, Blacklight::Types::String, 'title_tesim'
|
33
38
|
attribute :author, Blacklight::Types::Array, 'author_tesim'
|
34
39
|
attribute :date, Blacklight::Types::Date, 'date_dtsi'
|
35
|
-
|
36
40
|
end
|
37
41
|
end
|
38
42
|
let(:document) do
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Blacklight::DocumentPresenter do
|
4
|
+
let(:presenter) { described_class.new }
|
5
|
+
let(:doc) { instance_double(SolrDocument) }
|
6
|
+
let(:view_context) { double('View context', should_render_field?: true) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(presenter).to receive(:document).and_return(doc)
|
10
|
+
allow(presenter).to receive(:view_context).and_return(view_context)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#fields_to_render' do
|
14
|
+
subject { presenter.fields_to_render }
|
15
|
+
|
16
|
+
let(:field_config) { double(field: 'asdf') }
|
17
|
+
|
18
|
+
context 'when all of the fields have values' do
|
19
|
+
before do
|
20
|
+
allow(presenter).to receive_messages(fields: { 'title' => field_config },
|
21
|
+
render_field?: true,
|
22
|
+
has_value?: true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { is_expected.to eq('title' => field_config) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#render_field?' do
|
30
|
+
subject { presenter.send(:render_field?, field_config) }
|
31
|
+
|
32
|
+
let(:field_config) { double('field config', if: true, unless: false) }
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(presenter).to receive_messages(document_has_value?: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it { is_expected.to be true }
|
39
|
+
|
40
|
+
context 'when the view context says not to render the field' do
|
41
|
+
let(:view_context) { double('View context', should_render_field?: false) }
|
42
|
+
|
43
|
+
before do
|
44
|
+
allow(field_config).to receive_messages(if: false)
|
45
|
+
end
|
46
|
+
|
47
|
+
it { is_expected.to be false }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#has_value?' do
|
52
|
+
subject { presenter.send(:has_value?, field_config) }
|
53
|
+
|
54
|
+
context 'when the document has the field value' do
|
55
|
+
let(:field_config) { double(field: 'asdf') }
|
56
|
+
|
57
|
+
before do
|
58
|
+
allow(doc).to receive(:has?).with('asdf').and_return(true)
|
59
|
+
end
|
60
|
+
|
61
|
+
it { is_expected.to be true }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when the document has a highlight field value' do
|
65
|
+
let(:field_config) { double(field: 'asdf', highlight: true) }
|
66
|
+
|
67
|
+
before do
|
68
|
+
allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
|
69
|
+
allow(doc).to receive(:has?).with('asdf').and_return(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it { is_expected.to be true }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when the field is a model accessor' do
|
76
|
+
let(:field_config) { double(field: 'asdf', highlight: true, accessor: true) }
|
77
|
+
|
78
|
+
before do
|
79
|
+
allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
|
80
|
+
allow(doc).to receive(:has?).with('asdf').and_return(true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it { is_expected.to be true }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Blacklight::IndexPresenter, api: true do
|
4
|
+
include Capybara::RSpecMatchers
|
5
|
+
subject { presenter }
|
6
|
+
|
7
|
+
let(:request_context) { double(document_index_view_type: 'list') }
|
8
|
+
let(:config) { Blacklight::Configuration.new }
|
9
|
+
|
10
|
+
let(:presenter) { described_class.new(document, request_context, config) }
|
11
|
+
let(:parameter_class) { ActionController::Parameters }
|
12
|
+
let(:params) { parameter_class.new }
|
13
|
+
let(:controller) { double }
|
14
|
+
let(:search_state) { Blacklight::SearchState.new(params, config, controller) }
|
15
|
+
|
16
|
+
let(:document) do
|
17
|
+
SolrDocument.new(id: 1,
|
18
|
+
'link_to_facet_true' => 'x',
|
19
|
+
'link_to_facet_named' => 'x',
|
20
|
+
'qwer' => 'document qwer value')
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(request_context).to receive(:search_state).and_return(search_state)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#field_value' do
|
28
|
+
subject { presenter.field_value field }
|
29
|
+
|
30
|
+
let(:field) { config.index_fields[field_name] }
|
31
|
+
let(:field_name) { 'asdf' }
|
32
|
+
let(:config) do
|
33
|
+
Blacklight::Configuration.new.configure do |config|
|
34
|
+
config.add_index_field 'qwer'
|
35
|
+
config.add_index_field 'asdf', helper_method: :render_asdf_index_field
|
36
|
+
config.add_index_field 'link_to_facet_true', link_to_facet: true
|
37
|
+
config.add_index_field 'link_to_facet_named', link_to_facet: :some_field
|
38
|
+
config.add_index_field 'highlight', highlight: true
|
39
|
+
config.add_index_field 'solr_doc_accessor', accessor: true
|
40
|
+
config.add_index_field 'explicit_accessor', accessor: :solr_doc_accessor
|
41
|
+
config.add_index_field 'alias', field: 'qwer'
|
42
|
+
config.add_index_field 'with_default', default: 'value'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when an explicit value is provided' do
|
47
|
+
subject { presenter.field_value field, value: 'asdf' }
|
48
|
+
|
49
|
+
it { is_expected.to eq 'asdf' }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when field has a helper method' do
|
53
|
+
before do
|
54
|
+
allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
|
55
|
+
end
|
56
|
+
|
57
|
+
it { is_expected.to eq 'custom asdf value' }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when field has link_to_facet with true' do
|
61
|
+
before do
|
62
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_facet_true' => ['x'] }).and_return('/foo')
|
63
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:field_name) { 'link_to_facet_true' }
|
67
|
+
|
68
|
+
it { is_expected.to eq 'bar' }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when field has link_to_facet with a field name' do
|
72
|
+
before do
|
73
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
74
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:field_name) { 'link_to_facet_named' }
|
78
|
+
|
79
|
+
it { is_expected.to eq 'bar' }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when no highlight field is available' do
|
83
|
+
before do
|
84
|
+
allow(document).to receive(:has_highlight_field?).and_return(false)
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:field_name) { 'highlight' }
|
88
|
+
|
89
|
+
it { is_expected.to be_blank }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when highlight field is available' do
|
93
|
+
before do
|
94
|
+
allow(document).to receive(:has_highlight_field?).and_return(true)
|
95
|
+
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
96
|
+
end
|
97
|
+
|
98
|
+
let(:field_name) { 'highlight' }
|
99
|
+
|
100
|
+
it { is_expected.to eq '<em>highlight</em>' }
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when no options are provided' do
|
104
|
+
let(:field_name) { 'qwer' }
|
105
|
+
|
106
|
+
it "checks the document field value" do
|
107
|
+
expect(subject).to eq 'document qwer value'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when accessor is true' do
|
112
|
+
before do
|
113
|
+
allow(document).to receive_messages(solr_doc_accessor: "123")
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:field_name) { 'solr_doc_accessor' }
|
117
|
+
|
118
|
+
it { is_expected.to eq '123' }
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when accessor is set to a value' do
|
122
|
+
let(:field_name) { 'explicit_accessor' }
|
123
|
+
|
124
|
+
it 'calls the accessor with the field_name as the argument' do
|
125
|
+
expect(document).to receive(:solr_doc_accessor).with('explicit_accessor').and_return("123")
|
126
|
+
|
127
|
+
expect(subject).to eq '123'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when the field is an alias' do
|
132
|
+
let(:field_name) { 'alias' }
|
133
|
+
|
134
|
+
it { is_expected.to eq 'document qwer value' }
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when the field has a default' do
|
138
|
+
let(:field_name) { 'with_default' }
|
139
|
+
|
140
|
+
it { is_expected.to eq 'value' }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#field_values' do
|
145
|
+
context 'for a field with the helper_method option' do
|
146
|
+
let(:field_name) { 'field_with_helper' }
|
147
|
+
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
148
|
+
let(:document) do
|
149
|
+
SolrDocument.new(id: 1, 'field_with_helper' => 'value')
|
150
|
+
end
|
151
|
+
|
152
|
+
it "checks call the helper method with arguments" do
|
153
|
+
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
154
|
+
args.first
|
155
|
+
end
|
156
|
+
|
157
|
+
options = subject.send(:field_values, field_config, a: 1)
|
158
|
+
|
159
|
+
expect(options).to include :document, :field, :value, :config, :a
|
160
|
+
expect(options[:document]).to eq document
|
161
|
+
expect(options[:field]).to eq 'field_with_helper'
|
162
|
+
expect(options[:value]).to eq ['value']
|
163
|
+
expect(options[:config]).to eq field_config
|
164
|
+
expect(options[:a]).to eq 1
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#fields' do
|
170
|
+
let(:field) { instance_double(Blacklight::Configuration::Field) }
|
171
|
+
|
172
|
+
before do
|
173
|
+
allow(config).to receive(:index_fields_for).and_return(title: field)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns the list from the configs' do
|
177
|
+
expect(subject.send(:fields)).to eq(title: field)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#thumbnail" do
|
182
|
+
subject { presenter.thumbnail }
|
183
|
+
|
184
|
+
it { is_expected.to be_instance_of Blacklight::ThumbnailPresenter }
|
185
|
+
end
|
186
|
+
end
|