blacklight-spotlight 3.0.0.alpha.9 → 3.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/assets/images/blacklight/arrow-alt-circle-left.svg +1 -0
- data/app/assets/images/blacklight/arrow-alt-circle-right.svg +1 -0
- data/app/assets/javascripts/spotlight/admin/{add_new_page_button.js → add_new_button.js} +7 -0
- data/app/assets/javascripts/spotlight/admin/block_mixins/autocompleteable.js +4 -4
- data/app/assets/javascripts/spotlight/admin/blocks/browse_block.js +55 -1
- data/app/assets/javascripts/spotlight/admin/blocks/browse_group_categories_block.js +88 -0
- data/app/assets/javascripts/spotlight/admin/blocks/pages_block.js +1 -1
- data/app/assets/javascripts/spotlight/admin/blocks/solr_documents_base_block.js +1 -1
- data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +7 -2
- data/app/assets/javascripts/spotlight/admin/crop.es6 +11 -0
- data/app/assets/javascripts/spotlight/admin/croppable.js +1 -1
- data/app/assets/javascripts/spotlight/admin/index.js +0 -2
- data/app/assets/javascripts/spotlight/admin/reindex_monitor.js +1 -0
- data/app/assets/javascripts/spotlight/admin/search_typeahead.js +2 -2
- data/app/assets/javascripts/spotlight/admin/sir-trevor/block_controls.js +21 -12
- data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +11 -3
- data/app/assets/javascripts/spotlight/user/browse_group_categories.js +59 -0
- data/app/assets/javascripts/spotlight/user/index.js +1 -0
- data/app/assets/stylesheets/spotlight/_accessibility.scss +1 -1
- data/app/assets/stylesheets/spotlight/_breadcrumbs.scss +8 -0
- data/app/assets/stylesheets/spotlight/_browse.scss +16 -0
- data/app/assets/stylesheets/spotlight/_catalog.scss +6 -6
- data/app/assets/stylesheets/spotlight/_curation.scss +6 -0
- data/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +214 -83
- data/app/assets/stylesheets/spotlight/_header.scss +1 -1
- data/app/assets/stylesheets/spotlight/_item_text_block.scss +6 -0
- data/app/assets/stylesheets/spotlight/_pages.scss +9 -4
- data/app/assets/stylesheets/spotlight/_report_a_problem.scss +5 -2
- data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
- data/app/assets/stylesheets/spotlight/_translations.scss +7 -0
- data/app/assets/stylesheets/spotlight/browse_group_categories_block.scss +92 -0
- data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +1 -2
- data/app/controllers/concerns/spotlight/search_helper.rb +2 -8
- data/app/controllers/spotlight/appearances_controller.rb +0 -12
- data/app/controllers/spotlight/browse_controller.rb +7 -3
- data/app/controllers/spotlight/catalog_controller.rb +5 -2
- data/app/controllers/spotlight/concerns/application_controller.rb +13 -2
- data/app/controllers/spotlight/dashboards_controller.rb +1 -1
- data/app/controllers/spotlight/exhibits_controller.rb +2 -3
- data/app/controllers/spotlight/featured_images_controller.rb +1 -1
- data/app/controllers/spotlight/groups_controller.rb +80 -0
- data/app/controllers/spotlight/pages_controller.rb +6 -9
- data/app/controllers/spotlight/resources/csv_upload_controller.rb +1 -1
- data/app/controllers/spotlight/searches_controller.rb +7 -19
- data/app/controllers/spotlight/translations_controller.rb +46 -0
- data/app/helpers/spotlight/application_helper.rb +20 -1
- data/app/helpers/spotlight/crop_helper.rb +4 -1
- data/app/helpers/spotlight/crud_link_helpers.rb +1 -1
- data/app/helpers/spotlight/main_app_helpers.rb +1 -1
- data/app/helpers/spotlight/pages_helper.rb +1 -1
- data/app/jobs/concerns/spotlight/job_tracking.rb +47 -0
- data/app/jobs/concerns/spotlight/limit_concurrency.rb +33 -0
- data/app/jobs/spotlight/add_uploads_from_csv.rb +34 -6
- data/app/jobs/spotlight/application_job.rb +8 -0
- data/app/jobs/spotlight/cleanup_job_trackers_job.rb +13 -0
- data/app/jobs/spotlight/default_thumbnail_job.rb +1 -3
- data/app/jobs/spotlight/reindex_exhibit_job.rb +36 -0
- data/app/jobs/spotlight/reindex_job.rb +49 -41
- data/app/jobs/spotlight/rename_sidecar_field_job.rb +2 -2
- data/app/jobs/spotlight/update_job_trackers_job.rb +20 -0
- data/app/mailers/spotlight/indexing_complete_mailer.rb +3 -2
- data/app/models/concerns/spotlight/exhibit_defaults.rb +1 -1
- data/app/models/concerns/spotlight/translatables.rb +17 -1
- data/app/models/concerns/spotlight/user.rb +2 -1
- data/app/models/sir_trevor_rails/blocks/browse_group_categories_block.rb +25 -0
- data/app/models/spotlight/ability.rb +2 -0
- data/app/models/spotlight/about_page.rb +3 -1
- data/app/models/spotlight/blacklight_configuration.rb +2 -1
- data/app/models/spotlight/contact.rb +1 -1
- data/app/models/spotlight/custom_field.rb +3 -3
- data/app/models/spotlight/event.rb +13 -0
- data/app/models/spotlight/exhibit.rb +18 -14
- data/app/models/spotlight/feature_page.rb +3 -1
- data/app/models/spotlight/featured_image.rb +29 -12
- data/app/models/spotlight/group.rb +22 -0
- data/app/models/spotlight/group_member.rb +11 -0
- data/app/models/spotlight/home_page.rb +3 -1
- data/app/models/spotlight/job_tracker.rb +105 -0
- data/app/models/spotlight/main_navigation.rb +2 -2
- data/app/models/spotlight/masthead.rb +1 -1
- data/app/models/spotlight/page.rb +5 -1
- data/app/models/spotlight/page_configurations.rb +6 -0
- data/app/models/spotlight/page_content.rb +2 -0
- data/app/models/spotlight/reindex_progress.rb +44 -27
- data/app/models/spotlight/resource.rb +24 -58
- data/app/models/spotlight/resources/csv_upload.rb +2 -1
- data/app/models/spotlight/resources/iiif_harvester.rb +10 -1
- data/app/models/spotlight/resources/iiif_manifest.rb +11 -7
- data/app/models/spotlight/resources/iiif_service.rb +1 -1
- data/app/models/spotlight/resources/json_upload.rb +12 -0
- data/app/models/spotlight/resources/upload.rb +25 -2
- data/app/models/spotlight/search.rb +10 -1
- data/app/models/spotlight/solr_document_sidecar.rb +9 -6
- data/app/models/spotlight/temporary_image.rb +8 -0
- data/app/services/spotlight/etl.rb +7 -0
- data/app/services/spotlight/etl/context.rb +52 -0
- data/app/services/spotlight/etl/executor.rb +194 -0
- data/app/services/spotlight/etl/loaders.rb +12 -0
- data/app/services/spotlight/etl/pipeline.rb +81 -0
- data/app/services/spotlight/etl/solr_loader.rb +96 -0
- data/app/services/spotlight/etl/sources.rb +25 -0
- data/app/services/spotlight/etl/step.rb +82 -0
- data/app/services/spotlight/etl/transforms.rb +64 -0
- data/app/services/spotlight/exhibit_import_export_service.rb +482 -0
- data/app/services/spotlight/validity_checker.rb +5 -5
- data/app/values/custom_field_name.rb +1 -0
- data/app/views/catalog/_save_search.html.erb +1 -1
- data/app/views/spotlight/about_pages/_empty.html.erb +5 -5
- data/app/views/spotlight/browse/_search.html.erb +5 -3
- data/app/views/spotlight/browse/_search_title.html.erb +2 -1
- data/app/views/spotlight/browse/index.html.erb +13 -0
- data/app/views/spotlight/catalog/_document.html.erb +2 -4
- data/app/views/spotlight/catalog/index.iiif_json.jbuilder +22 -0
- data/app/views/spotlight/contacts/_form.html.erb +1 -1
- data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +6 -6
- data/app/views/spotlight/feature_pages/_empty.html.erb +5 -5
- data/app/views/spotlight/featured_images/_form.html.erb +1 -1
- data/app/views/spotlight/featured_images/_upload_form.html.erb +1 -1
- data/app/views/spotlight/home_pages/_empty.html.erb +3 -3
- data/app/views/spotlight/indexing_complete_mailer/documents_indexed.html.erb +9 -0
- data/app/views/spotlight/pages/_form.html.erb +2 -2
- data/app/views/spotlight/searches/_form.html.erb +13 -0
- data/app/views/spotlight/searches/_group.html.erb +27 -0
- data/app/views/spotlight/searches/_search.html.erb +1 -0
- data/app/views/spotlight/searches/index.html.erb +58 -17
- data/app/views/spotlight/shared/_honeypot_field.html.erb +4 -0
- data/app/views/spotlight/shared/_locale_picker.html.erb +1 -1
- data/app/views/spotlight/shared/_report_a_problem.html.erb +7 -10
- data/app/views/spotlight/sir_trevor/blocks/_browse_block.html.erb +1 -0
- data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +45 -0
- data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +7 -1
- data/app/views/spotlight/translations/_browse_categories.html.erb +29 -3
- data/app/views/spotlight/translations/_general.html.erb +7 -7
- data/app/views/spotlight/translations/_groups.html.erb +34 -0
- data/app/views/spotlight/translations/_import.html.erb +24 -0
- data/app/views/spotlight/translations/_metadata.html.erb +1 -1
- data/app/views/spotlight/translations/_page.html.erb +5 -5
- data/app/views/spotlight/translations/_pages.html.erb +4 -4
- data/app/views/spotlight/translations/_pages_table.html.erb +5 -5
- data/app/views/spotlight/translations/_search_fields.html.erb +3 -3
- data/app/views/spotlight/translations/edit.html.erb +14 -6
- data/app/views/spotlight/translations/show.yaml.yamlbuilder +81 -0
- data/config/i18n-tasks.yml +7 -0
- data/config/locales/spotlight.ar.yml +57 -24
- data/config/locales/spotlight.en.yml +184 -128
- data/config/routes.rb +16 -1
- data/db/migrate/20200403161512_add_subtitle_to_searches.rb +7 -0
- data/db/migrate/20210113092223_create_spotlight_groups.rb +23 -0
- data/db/migrate/20210122082032_create_job_trackers.rb +22 -0
- data/db/migrate/20210126123041_create_events.rb +15 -0
- data/lib/generators/spotlight/install_generator.rb +23 -2
- data/lib/generators/spotlight/scaffold_resource_generator.rb +5 -13
- data/lib/generators/spotlight/templates/config/initializers/sir_trevor_rails.rb +10 -0
- data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +3 -1
- data/lib/spotlight/engine.rb +35 -4
- data/lib/spotlight/upload_field_config.rb +1 -0
- data/lib/spotlight/version.rb +1 -1
- data/spec/controllers/spotlight/about_pages_controller_spec.rb +3 -3
- data/spec/controllers/spotlight/browse_controller_spec.rb +24 -1
- data/spec/controllers/spotlight/catalog_controller_spec.rb +4 -2
- data/spec/controllers/spotlight/contacts_controller_spec.rb +2 -2
- data/spec/controllers/spotlight/feature_pages_controller_spec.rb +11 -0
- data/spec/controllers/spotlight/groups_controller_spec.rb +103 -0
- data/spec/controllers/spotlight/home_pages_controller_spec.rb +2 -2
- data/spec/controllers/spotlight/resources/csv_upload_controller_spec.rb +4 -4
- data/spec/controllers/spotlight/searches_controller_spec.rb +10 -3
- data/spec/controllers/spotlight/translations_controller_spec.rb +53 -2
- data/spec/controllers/spotlight/view_configurations_controller_spec.rb +1 -1
- data/spec/examples.txt +1448 -125
- data/spec/factories/featured_images.rb +4 -0
- data/spec/factories/group.rb +17 -0
- data/spec/factories/job_trackers.rb +9 -0
- data/spec/factories/searches.rb +11 -1
- data/spec/features/add_contacts_spec.rb +1 -1
- data/spec/features/add_items_spec.rb +9 -4
- data/spec/features/browse_category_admin_spec.rb +39 -7
- data/spec/features/browse_category_navigation_spec.rb +44 -0
- data/spec/features/browse_category_spec.rb +2 -2
- data/spec/features/catalog_spec.rb +2 -2
- data/spec/features/create_exhibit_spec.rb +5 -4
- data/spec/features/dashboard_spec.rb +7 -7
- data/spec/features/edit_search_fields_spec.rb +2 -2
- data/spec/features/exhibits/administration_spec.rb +3 -3
- data/spec/features/exhibits/edit_metadata_fields_spec.rb +1 -1
- data/spec/features/exhibits/language_create_edit_spec.rb +3 -3
- data/spec/features/exhibits/translation_editing_spec.rb +57 -8
- data/spec/features/home_page_spec.rb +13 -4
- data/spec/features/item_admin_spec.rb +4 -4
- data/spec/features/javascript/about_page_admin_spec.rb +1 -1
- data/spec/features/javascript/block_controls_spec.rb +3 -1
- data/spec/features/javascript/blocks/browse_group_categories_block_spec.rb +64 -0
- data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +4 -1
- data/spec/features/javascript/browse_group_admin_spec.rb +45 -0
- data/spec/features/javascript/edit_in_place_spec.rb +3 -3
- data/spec/features/javascript/feature_page_admin_spec.rb +1 -1
- data/spec/features/javascript/reindex_monitor_spec.rb +1 -1
- data/spec/features/javascript/search_config_admin_spec.rb +1 -1
- data/spec/features/report_a_problem_spec.rb +6 -5
- data/spec/features/site_users_management_spec.rb +4 -4
- data/spec/helpers/spotlight/crud_link_helpers_spec.rb +3 -3
- data/spec/helpers/spotlight/pages_helper_spec.rb +10 -2
- data/spec/i18n_spec.rb +0 -2
- data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +13 -1
- data/spec/jobs/spotlight/reindex_exhibit_job_spec.rb +43 -0
- data/spec/jobs/spotlight/reindex_job_spec.rb +30 -59
- data/spec/mailers/spotlight/indexing_complete_mailer_spec.rb +11 -1
- data/spec/models/sir_trevor_rails/blocks/browse_group_categories_block_spec.rb +41 -0
- data/spec/models/solr_document_spec.rb +2 -3
- data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -0
- data/spec/models/spotlight/exhibit_spec.rb +21 -59
- data/spec/models/spotlight/featured_image_spec.rb +27 -0
- data/spec/models/spotlight/group_spec.rb +19 -0
- data/spec/models/spotlight/main_navigation_spec.rb +1 -1
- data/spec/models/spotlight/page_spec.rb +6 -1
- data/spec/models/spotlight/reindex_progress_spec.rb +89 -87
- data/spec/models/spotlight/resource_spec.rb +69 -90
- data/spec/models/spotlight/resources/iiif_harvester_spec.rb +9 -10
- data/spec/models/spotlight/resources/upload_spec.rb +43 -79
- data/spec/models/spotlight/role_spec.rb +3 -3
- data/spec/models/spotlight/search_spec.rb +30 -3
- data/spec/models/spotlight/solr_document_sidecar_spec.rb +1 -0
- data/spec/services/spotlight/etl/context_spec.rb +66 -0
- data/spec/services/spotlight/etl/executor_spec.rb +149 -0
- data/spec/services/spotlight/etl/pipeline_spec.rb +22 -0
- data/spec/services/spotlight/etl/solr_loader_spec.rb +76 -0
- data/spec/services/spotlight/etl/step_spec.rb +70 -0
- data/spec/{serializers/spotlight/exhibit_export_serializer_spec.rb → services/spotlight/exhibit_import_export_service_spec.rb} +168 -23
- data/spec/services/spotlight/iiif_resource_resolver_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -6
- data/spec/support/features/test_features_helpers.rb +15 -0
- data/spec/test_app_templates/Gemfile.extra +1 -3
- data/spec/test_app_templates/catalog_controller.rb +6 -3
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/shared/_exhibit_navbar.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/browse/index.html.erb_spec.rb +2 -0
- data/spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +28 -25
- data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -3
- data/spec/views/spotlight/pages/show.html.erb_spec.rb +1 -0
- data/spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb +7 -8
- data/spec/views/spotlight/translations/_import.html.erb_spec.rb +24 -0
- data/vendor/assets/javascripts/leaflet-iiif.js +46 -21
- data/vendor/assets/javascripts/tiny-slider.js +3218 -0
- data/vendor/assets/stylesheets/tiny-slider.css +1 -0
- metadata +444 -289
- data/app/models/concerns/spotlight/resources/open_graph.rb +0 -36
- data/app/models/spotlight/reindexing_log_entry.rb +0 -42
- data/app/serializers/spotlight/exhibit_export_serializer.rb +0 -205
- data/app/serializers/spotlight/featured_image_representer.rb +0 -29
- data/app/serializers/spotlight/main_navigation_representer.rb +0 -13
- data/app/serializers/spotlight/page_representer.rb +0 -33
- data/app/services/spotlight/resources/iiif_builder.rb +0 -19
- data/app/services/spotlight/solr_document_builder.rb +0 -76
- data/app/services/spotlight/upload_solr_document_builder.rb +0 -57
- data/spec/factories/reindexing_log_entries.rb +0 -54
- data/spec/models/spotlight/reindexing_log_entry_spec.rb +0 -129
- data/spec/models/spotlight/resources/open_graph_spec.rb +0 -65
- data/spec/services/spotlight/solr_document_builder_spec.rb +0 -66
- data/vendor/assets/javascripts/handlebars-v1.3.0.js +0 -2746
@@ -104,7 +104,7 @@ describe Spotlight::CrudLinkHelpers, type: :helper do
|
|
104
104
|
describe '#action_default_value' do
|
105
105
|
it 'attempts i18n lookups for models' do
|
106
106
|
expect(I18n).to receive(:t).with(:'helpers.action.spotlight/feature_page.edit',
|
107
|
-
model: some_model.class.model_name.human,
|
107
|
+
model: some_model.class.model_name.human.downcase,
|
108
108
|
default: [:'helpers.action.edit', 'Edit Feature page'])
|
109
109
|
expect(helper.send(:action_default_value, some_model))
|
110
110
|
end
|
@@ -112,14 +112,14 @@ describe Spotlight::CrudLinkHelpers, type: :helper do
|
|
112
112
|
it 'attempts i18n lookups for unpersisted models' do
|
113
113
|
some_model = Spotlight::FeaturePage.new
|
114
114
|
expect(I18n).to receive(:t).with(:'helpers.action.spotlight/feature_page.create',
|
115
|
-
model: some_model.class.model_name.human,
|
115
|
+
model: some_model.class.model_name.human.downcase,
|
116
116
|
default: [:'helpers.action.create', 'Create Feature page'])
|
117
117
|
expect(helper.send(:action_default_value, some_model))
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'attempts i18n lookups for models with an explicit action' do
|
121
121
|
expect(I18n).to receive(:t).with(:'helpers.action.spotlight/feature_page.custom_action',
|
122
|
-
model: some_model.class.model_name.human,
|
122
|
+
model: some_model.class.model_name.human.downcase,
|
123
123
|
default: [:'helpers.action.custom_action', 'Custom action Feature page'])
|
124
124
|
expect(helper.send(:action_default_value, some_model, :custom_action))
|
125
125
|
end
|
@@ -106,16 +106,24 @@ describe Spotlight::PagesHelper, type: :helper do
|
|
106
106
|
it 'handles nil input' do
|
107
107
|
expect(helper.sir_trevor_markdown(nil)).to be_blank
|
108
108
|
end
|
109
|
+
|
110
|
+
it 'retains paragraphs' do
|
111
|
+
expect(helper.sir_trevor_markdown('<p>First Line</p><p>Second Line</p>').chomp).to match(%r{<p>First Line</p>\s*<p>Second Line</p>})
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'replaces line breaks with paragraphs' do
|
115
|
+
expect(helper.sir_trevor_markdown('First Line<br>Second Line').chomp).to match(%r{<p>First Line</p>\s*<p>Second Line</p>})
|
116
|
+
end
|
109
117
|
end
|
110
118
|
|
111
119
|
describe '#content_editor_class' do
|
112
|
-
context '
|
120
|
+
context 'a sir-trevor backed page with a custom class' do
|
113
121
|
it 'has a custom class' do
|
114
122
|
expect(helper.content_editor_class(Spotlight::Page.new)).to eq 'js-st-instance'
|
115
123
|
end
|
116
124
|
end
|
117
125
|
|
118
|
-
context '
|
126
|
+
context 'a sir-trevor backed page with a derived class' do
|
119
127
|
it 'derives a css class name from the editor type' do
|
120
128
|
expect(helper.content_editor_class(Spotlight::Page.new(content_type: 'Something::Custom'))).to eq 'js-something-custom-instance'
|
121
129
|
end
|
data/spec/i18n_spec.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'i18n/tasks'
|
4
4
|
|
5
|
-
# rubocop:disable RSpec/DescribeClass
|
6
5
|
RSpec.describe 'I18n' do
|
7
6
|
let(:i18n) { I18n::Tasks::BaseTask.new }
|
8
7
|
let(:missing_keys) { i18n.missing_keys }
|
@@ -26,4 +25,3 @@ RSpec.describe 'I18n' do
|
|
26
25
|
expect(non_normalized).to be_empty, error_message
|
27
26
|
end
|
28
27
|
end
|
29
|
-
# rubocop:enable RSpec/DescribeClass
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Spotlight::
|
3
|
+
describe Spotlight::AddUploadsFromCsv do
|
4
4
|
subject(:job) { described_class.new(data, exhibit, user) }
|
5
5
|
|
6
6
|
let(:exhibit) { FactoryBot.create(:exhibit) }
|
@@ -40,4 +40,16 @@ describe Spotlight::AddUploadsFromCSV do
|
|
40
40
|
|
41
41
|
job.perform_now
|
42
42
|
end
|
43
|
+
|
44
|
+
context 'with errors' do
|
45
|
+
it 'collects errors uploaded resources for each row of data' do
|
46
|
+
allow(Spotlight::IndexingCompleteMailer).to receive(:documents_indexed).and_return(double(deliver_now: true))
|
47
|
+
job.perform_now
|
48
|
+
expect(Spotlight::IndexingCompleteMailer).to have_received(:documents_indexed).with(
|
49
|
+
data, exhibit, user,
|
50
|
+
indexed_count: 1,
|
51
|
+
errors: { 1 => array_including(match(/relative URI: x/)), 2 => array_including(match(/Upload is invalid/)) }
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Spotlight::ReindexExhibitJob do
|
4
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
FactoryBot.create_list(:resource, 10, exhibit: exhibit)
|
8
|
+
allow(Spotlight::ReindexJob).to receive(:perform_now)
|
9
|
+
allow(Spotlight::ReindexJob).to receive(:perform_later)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with a single batch' do
|
13
|
+
it 'runs the index job inline' do
|
14
|
+
described_class.perform_now(exhibit, batch_count: 1)
|
15
|
+
|
16
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_now).once.with(exhibit, anything)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a fixed batch count' do
|
21
|
+
it 'enqueues that number of batches' do
|
22
|
+
described_class.perform_now(exhibit, batch_count: 2)
|
23
|
+
|
24
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).twice.with(exhibit, hash_including(:start, :finish))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with a dynamically generated batch count' do
|
29
|
+
it 'enqueues the right number of batches' do
|
30
|
+
described_class.perform_now(exhibit, batch_count: nil, batch_size: 2)
|
31
|
+
|
32
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).exactly(5).times.with(exhibit, hash_including(:start, :finish))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a dynamically generated batch size' do
|
37
|
+
it 'figues out that number of batches' do
|
38
|
+
described_class.perform_now(exhibit, batch_count: nil, batch_size: nil)
|
39
|
+
|
40
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).exactly(3).times.with(exhibit, hash_including(:start, :finish))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,67 +4,14 @@ describe Spotlight::ReindexJob do
|
|
4
4
|
include ActiveJob::TestHelper
|
5
5
|
|
6
6
|
let(:exhibit) { FactoryBot.create(:exhibit) }
|
7
|
-
let(:resource) { FactoryBot.create(:resource) }
|
7
|
+
let(:resource) { FactoryBot.create(:resource, exhibit: exhibit) }
|
8
8
|
let(:user) { FactoryBot.create(:user) }
|
9
|
-
let(:log_entry) { Spotlight::ReindexingLogEntry.create(exhibit: exhibit, user: user) }
|
10
9
|
|
11
10
|
before do
|
12
11
|
ActiveJob::Base.queue_adapter = :test
|
13
12
|
allow_any_instance_of(Spotlight::Resource).to receive(:reindex)
|
14
13
|
end
|
15
14
|
|
16
|
-
context 'with an exhibit' do
|
17
|
-
subject { described_class.new(exhibit) }
|
18
|
-
|
19
|
-
before do
|
20
|
-
exhibit.resources << resource
|
21
|
-
exhibit.save
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'attempts to reindex every resource in the exhibit' do
|
25
|
-
# ActiveJob will reload the collection, so we go through a little trouble:
|
26
|
-
expect_any_instance_of(Spotlight::Resource).to receive(:reindex) do |thingy|
|
27
|
-
expect(exhibit.resources).to include thingy
|
28
|
-
end
|
29
|
-
|
30
|
-
subject.perform_now
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with a log_entry' do
|
34
|
-
subject { described_class.new(exhibit, log_entry) }
|
35
|
-
|
36
|
-
it 'marks the log entry as started' do
|
37
|
-
expect(log_entry).to receive(:in_progress!)
|
38
|
-
subject.perform_now
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'marks the log entry as successful if there is no error' do
|
42
|
-
expect(log_entry).to receive(:succeeded!)
|
43
|
-
subject.perform_now
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'marks the log entry as failed if there is an error' do
|
47
|
-
unexpected_error = StandardError.new
|
48
|
-
# it'd be more realistic to raise on resource#reindex, but that's already stubbed above, so this'll have to do
|
49
|
-
expect(subject).to receive(:perform).with(exhibit, log_entry).and_raise unexpected_error
|
50
|
-
expect(log_entry).to receive(:failed!)
|
51
|
-
expect { subject.perform_now }.to raise_error unexpected_error
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'updates the items_reindexed_estimate field on the log entry' do
|
55
|
-
expect(log_entry).to receive(:update).with(items_reindexed_estimate: 1)
|
56
|
-
subject.perform_now
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'passes log_entry to the resource.reindex call' do
|
60
|
-
# ActiveJob will reload the collection, so we go through a little trouble:
|
61
|
-
expect_any_instance_of(Spotlight::Resource).to receive(:reindex).with(log_entry).exactly(:once)
|
62
|
-
# expect(resource).to receive(:reindex).with(log_entry)
|
63
|
-
subject.perform_now
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
15
|
context 'with a resource' do
|
69
16
|
subject { described_class.new(resource) }
|
70
17
|
|
@@ -75,31 +22,55 @@ describe Spotlight::ReindexJob do
|
|
75
22
|
end
|
76
23
|
|
77
24
|
describe 'validity' do
|
78
|
-
subject { described_class.new(resource,
|
25
|
+
subject { described_class.new(resource, 'validity_token' => 'xyz') }
|
79
26
|
|
80
27
|
let(:mock_checker) { instance_double(Spotlight::ValidityChecker) }
|
81
28
|
|
82
29
|
before do
|
83
30
|
allow(described_class).to receive(:validity_checker).and_return(mock_checker)
|
84
|
-
allow(mock_checker).to receive(:mint).with(
|
31
|
+
allow(mock_checker).to receive(:mint).with(anything).and_return('xyz')
|
85
32
|
end
|
86
33
|
|
87
34
|
it 'mints a new validity token' do
|
88
|
-
expect { described_class.perform_later(resource) }.to have_enqueued_job(described_class).with(resource,
|
35
|
+
expect { described_class.perform_later(resource) }.to have_enqueued_job(described_class).with(resource, 'validity_token' => 'xyz')
|
89
36
|
end
|
90
37
|
|
91
38
|
it 'does nothing if the token is no longer valid' do
|
92
|
-
allow(mock_checker).to receive(:check).with(
|
39
|
+
allow(mock_checker).to receive(:check).with(subject, validity_token: 'xyz').and_return(false)
|
93
40
|
expect(resource).not_to receive(:reindex)
|
94
41
|
|
95
42
|
subject.perform_now
|
96
43
|
end
|
97
44
|
|
98
45
|
it 'indexes the resource if the token is valid' do
|
99
|
-
allow(mock_checker).to receive(:check).with(
|
46
|
+
allow(mock_checker).to receive(:check).with(subject, validity_token: 'xyz').and_return(true)
|
100
47
|
expect(resource).to receive(:reindex)
|
101
48
|
|
102
49
|
subject.perform_now
|
103
50
|
end
|
104
51
|
end
|
52
|
+
|
53
|
+
context 'with start and finish' do
|
54
|
+
it 'indexes the resources within that page' do
|
55
|
+
count = 0
|
56
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex) do
|
57
|
+
count += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
described_class.perform_now(exhibit, start: 0, finish: resource.id)
|
61
|
+
|
62
|
+
expect(count).to eq 1
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does not index resources off that page' do
|
66
|
+
count = 0
|
67
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex) do
|
68
|
+
count += 1
|
69
|
+
end
|
70
|
+
|
71
|
+
described_class.perform_now(exhibit, start: resource.id + 1, finish: resource.id + 500)
|
72
|
+
|
73
|
+
expect(count).to eq 0
|
74
|
+
end
|
75
|
+
end
|
105
76
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe Spotlight::IndexingCompleteMailer do
|
4
|
-
subject { described_class.documents_indexed [1, 2, 3], exhibit, user }
|
4
|
+
subject { described_class.documents_indexed [1, 2, 3], exhibit, user, indexed_count: 3 }
|
5
5
|
|
6
6
|
let(:user) { double(email: 'test@example.com') }
|
7
7
|
let(:exhibit) { double(title: 'Exhibit title') }
|
@@ -29,4 +29,14 @@ describe Spotlight::IndexingCompleteMailer do
|
|
29
29
|
it 'includes the exhibit title' do
|
30
30
|
expect(subject.body.encoded).to match exhibit.title
|
31
31
|
end
|
32
|
+
|
33
|
+
context 'with errors' do
|
34
|
+
subject { described_class.documents_indexed [], exhibit, user, indexed_count: 0, errors: { 1 => ['missing title'], 20 => ['whatever'] } }
|
35
|
+
|
36
|
+
it 'includes some errors' do
|
37
|
+
expect(subject.body.encoded).to match 'Errors'
|
38
|
+
expect(subject.body.encoded).to match 'Row 1: missing title'
|
39
|
+
expect(subject.body.encoded).to match 'Row 20: whatever'
|
40
|
+
end
|
41
|
+
end
|
32
42
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SirTrevorRails::Blocks::BrowseGroupCategoriesBlock do
|
4
|
+
subject { described_class.new({ type: '', data: block_data }, page) }
|
5
|
+
|
6
|
+
let!(:exhibit) { FactoryBot.create(:exhibit) }
|
7
|
+
let!(:page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
|
8
|
+
let!(:group1) { FactoryBot.create(:group, exhibit: exhibit, title: 'abc123', published: true) }
|
9
|
+
let!(:group2) { FactoryBot.create(:group, exhibit: exhibit, title: 'xyz321', published: true) }
|
10
|
+
|
11
|
+
let(:block_data) { {} }
|
12
|
+
|
13
|
+
describe '#groups' do
|
14
|
+
it 'is the array of items with display set to true' do
|
15
|
+
block_data[:item] = {
|
16
|
+
'0': { id: 'abc123', display: 'true', weight: '2' },
|
17
|
+
'1': { id: 'xyz321', display: 'true', weight: '1' }
|
18
|
+
}
|
19
|
+
expect(subject.groups.length).to eq 2
|
20
|
+
expect(subject.groups.first.title).to eq 'xyz321'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#groups?' do
|
25
|
+
it 'is the array of items with display set to true' do
|
26
|
+
block_data[:item] = {}
|
27
|
+
expect(subject.be_groups).to be_falsy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#display_item_counts?' do
|
32
|
+
it do
|
33
|
+
expect(subject).not_to be_display_item_counts
|
34
|
+
end
|
35
|
+
|
36
|
+
it do
|
37
|
+
block_data['display-item-counts'] = 'true'
|
38
|
+
expect(subject).to be_display_item_counts
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,14 +4,13 @@ describe SolrDocument, type: :model do
|
|
4
4
|
subject { document }
|
5
5
|
|
6
6
|
let(:document) { described_class.new(id: 'abcd123') }
|
7
|
+
let(:exhibit_alt) { FactoryBot.create(:exhibit) }
|
8
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
7
9
|
|
8
10
|
before do
|
9
11
|
allow(subject).to receive_messages(reindex: nil)
|
10
12
|
end
|
11
13
|
|
12
|
-
let(:exhibit_alt) { FactoryBot.create(:exhibit) }
|
13
|
-
let(:exhibit) { FactoryBot.create(:exhibit) }
|
14
|
-
|
15
14
|
its(:to_key) { is_expected.to eq ['abcd123'] }
|
16
15
|
its(:persisted?) { is_expected.to be_truthy }
|
17
16
|
|
@@ -19,6 +19,14 @@ describe Spotlight::Exhibit, type: :model do
|
|
19
19
|
expect(subject.description).to eq 'Test description'
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'has reserved slugs' do
|
23
|
+
subject.slug = 'site'
|
24
|
+
|
25
|
+
expect do
|
26
|
+
subject.save!
|
27
|
+
end.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Slug is reserved')
|
28
|
+
end
|
29
|
+
|
22
30
|
describe 'validations' do
|
23
31
|
it 'validates the presence of the title' do
|
24
32
|
exhibit.title = ''
|
@@ -28,7 +36,7 @@ describe Spotlight::Exhibit, type: :model do
|
|
28
36
|
end
|
29
37
|
|
30
38
|
it 'does not validate the presence of the title under a non-default locale' do
|
31
|
-
|
39
|
+
allow(I18n).to receive(:locale).and_return(:fr)
|
32
40
|
exhibit.title = ''
|
33
41
|
expect do
|
34
42
|
exhibit.save
|
@@ -147,7 +155,7 @@ describe Spotlight::Exhibit, type: :model do
|
|
147
155
|
it 'removes the default browse category' do
|
148
156
|
subject.save
|
149
157
|
expect { subject.import({}) }.to change { subject.searches.count }.by(0)
|
150
|
-
expect { subject.import('searches' => [{ 'title' => 'All
|
158
|
+
expect { subject.import('searches' => [{ 'title' => 'All exhibit items', 'slug' => 'all-exhibit-items' }]) }.to change { subject.searches.count }.by(0)
|
151
159
|
end
|
152
160
|
|
153
161
|
it 'imports nested attributes from the hash' do
|
@@ -245,48 +253,9 @@ describe Spotlight::Exhibit, type: :model do
|
|
245
253
|
describe '#reindex_later' do
|
246
254
|
subject { FactoryBot.create(:exhibit) }
|
247
255
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
let(:user) { nil }
|
252
|
-
|
253
|
-
it 'queues a reindex job for the exhibit, with nil user for the log entry' do
|
254
|
-
expect(subject).to receive(:new_reindexing_log_entry).with(nil).and_return(log_entry)
|
255
|
-
expect(Spotlight::ReindexJob).to receive(:perform_later).with(subject, log_entry)
|
256
|
-
subject.reindex_later
|
257
|
-
expect(log_entry.user).to be nil
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'non-nil user is provided' do
|
262
|
-
let(:user) { FactoryBot.build(:user) }
|
263
|
-
|
264
|
-
it 'queues a reindex job for the exhibit, with actual user for the log entry' do
|
265
|
-
expect(subject).to receive(:new_reindexing_log_entry).with(user).and_return(log_entry)
|
266
|
-
expect(Spotlight::ReindexJob).to receive(:perform_later).with(subject, log_entry)
|
267
|
-
subject.reindex_later user
|
268
|
-
expect(log_entry.user).to eq user
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe '#new_reindexing_log_entry' do
|
274
|
-
let(:user) { FactoryBot.build(:user) }
|
275
|
-
|
276
|
-
it 'returns a properly configured Spotlight::ReindexingLogEntry instance' do
|
277
|
-
reindexing_log_entry = subject.send(:new_reindexing_log_entry, user)
|
278
|
-
expect(reindexing_log_entry.exhibit).to eq subject
|
279
|
-
expect(reindexing_log_entry.user).to eq user
|
280
|
-
expect(reindexing_log_entry.items_reindexed_count).to eq 0
|
281
|
-
expect(reindexing_log_entry.unstarted?).to be true
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'does not require user the user parameter' do
|
285
|
-
reindexing_log_entry = subject.send(:new_reindexing_log_entry)
|
286
|
-
expect(reindexing_log_entry.exhibit).to eq subject
|
287
|
-
expect(reindexing_log_entry.user).to be nil
|
288
|
-
expect(reindexing_log_entry.items_reindexed_count).to eq 0
|
289
|
-
expect(reindexing_log_entry.unstarted?).to be true
|
256
|
+
it 'queues a reindex job for the exhibit' do
|
257
|
+
expect(Spotlight::ReindexExhibitJob).to receive(:perform_later).with(subject, user: nil)
|
258
|
+
subject.reindex_later
|
290
259
|
end
|
291
260
|
end
|
292
261
|
|
@@ -358,24 +327,9 @@ describe Spotlight::Exhibit, type: :model do
|
|
358
327
|
end
|
359
328
|
|
360
329
|
describe '#reindex_progress' do
|
361
|
-
let!(:reindexing_log_entries) do
|
362
|
-
[
|
363
|
-
FactoryBot.create(:unstarted_reindexing_log_entry, exhibit: exhibit),
|
364
|
-
FactoryBot.create(:reindexing_log_entry, exhibit: exhibit),
|
365
|
-
in_progress_entry,
|
366
|
-
FactoryBot.create(:failed_reindexing_log_entry, exhibit: exhibit),
|
367
|
-
FactoryBot.create(:unstarted_reindexing_log_entry, exhibit: exhibit)
|
368
|
-
]
|
369
|
-
end
|
370
|
-
|
371
|
-
let(:in_progress_entry) do
|
372
|
-
FactoryBot.create(:in_progress_reindexing_log_entry, exhibit: exhibit)
|
373
|
-
end
|
374
|
-
|
375
330
|
it 'returns the latest log entry that is not unstarted' do
|
376
331
|
reindex_progress = subject.reindex_progress
|
377
332
|
expect(reindex_progress).to be_a Spotlight::ReindexProgress
|
378
|
-
expect(reindex_progress.current_log_entry).to eq in_progress_entry
|
379
333
|
end
|
380
334
|
end
|
381
335
|
|
@@ -402,6 +356,7 @@ describe Spotlight::Exhibit, type: :model do
|
|
402
356
|
I18n.locale = 'fr'
|
403
357
|
persisted_exhibit.reload
|
404
358
|
expect(persisted_exhibit.title).to eq 'Titre français'
|
359
|
+
expect(persisted_exhibit.translated_title).to eq 'Titre français'
|
405
360
|
end
|
406
361
|
|
407
362
|
it 'has a translatable subtitle' do
|
@@ -417,5 +372,12 @@ describe Spotlight::Exhibit, type: :model do
|
|
417
372
|
persisted_exhibit.reload
|
418
373
|
expect(persisted_exhibit.description).to eq 'Description français'
|
419
374
|
end
|
375
|
+
|
376
|
+
it 'is nil if no translation has been prrovided' do
|
377
|
+
expect(persisted_exhibit.title).to eq 'Sample'
|
378
|
+
I18n.locale = 'es'
|
379
|
+
persisted_exhibit.reload
|
380
|
+
expect(persisted_exhibit.translated_title(default: '')).to eq nil
|
381
|
+
end
|
420
382
|
end
|
421
383
|
end
|