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.
Files changed (262) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/app/assets/images/blacklight/arrow-alt-circle-left.svg +1 -0
  4. data/app/assets/images/blacklight/arrow-alt-circle-right.svg +1 -0
  5. data/app/assets/javascripts/spotlight/admin/{add_new_page_button.js → add_new_button.js} +7 -0
  6. data/app/assets/javascripts/spotlight/admin/block_mixins/autocompleteable.js +4 -4
  7. data/app/assets/javascripts/spotlight/admin/blocks/browse_block.js +55 -1
  8. data/app/assets/javascripts/spotlight/admin/blocks/browse_group_categories_block.js +88 -0
  9. data/app/assets/javascripts/spotlight/admin/blocks/pages_block.js +1 -1
  10. data/app/assets/javascripts/spotlight/admin/blocks/solr_documents_base_block.js +1 -1
  11. data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +7 -2
  12. data/app/assets/javascripts/spotlight/admin/crop.es6 +11 -0
  13. data/app/assets/javascripts/spotlight/admin/croppable.js +1 -1
  14. data/app/assets/javascripts/spotlight/admin/index.js +0 -2
  15. data/app/assets/javascripts/spotlight/admin/reindex_monitor.js +1 -0
  16. data/app/assets/javascripts/spotlight/admin/search_typeahead.js +2 -2
  17. data/app/assets/javascripts/spotlight/admin/sir-trevor/block_controls.js +21 -12
  18. data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +11 -3
  19. data/app/assets/javascripts/spotlight/user/browse_group_categories.js +59 -0
  20. data/app/assets/javascripts/spotlight/user/index.js +1 -0
  21. data/app/assets/stylesheets/spotlight/_accessibility.scss +1 -1
  22. data/app/assets/stylesheets/spotlight/_breadcrumbs.scss +8 -0
  23. data/app/assets/stylesheets/spotlight/_browse.scss +16 -0
  24. data/app/assets/stylesheets/spotlight/_catalog.scss +6 -6
  25. data/app/assets/stylesheets/spotlight/_curation.scss +6 -0
  26. data/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +214 -83
  27. data/app/assets/stylesheets/spotlight/_header.scss +1 -1
  28. data/app/assets/stylesheets/spotlight/_item_text_block.scss +6 -0
  29. data/app/assets/stylesheets/spotlight/_pages.scss +9 -4
  30. data/app/assets/stylesheets/spotlight/_report_a_problem.scss +5 -2
  31. data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
  32. data/app/assets/stylesheets/spotlight/_translations.scss +7 -0
  33. data/app/assets/stylesheets/spotlight/browse_group_categories_block.scss +92 -0
  34. data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +1 -2
  35. data/app/controllers/concerns/spotlight/search_helper.rb +2 -8
  36. data/app/controllers/spotlight/appearances_controller.rb +0 -12
  37. data/app/controllers/spotlight/browse_controller.rb +7 -3
  38. data/app/controllers/spotlight/catalog_controller.rb +5 -2
  39. data/app/controllers/spotlight/concerns/application_controller.rb +13 -2
  40. data/app/controllers/spotlight/dashboards_controller.rb +1 -1
  41. data/app/controllers/spotlight/exhibits_controller.rb +2 -3
  42. data/app/controllers/spotlight/featured_images_controller.rb +1 -1
  43. data/app/controllers/spotlight/groups_controller.rb +80 -0
  44. data/app/controllers/spotlight/pages_controller.rb +6 -9
  45. data/app/controllers/spotlight/resources/csv_upload_controller.rb +1 -1
  46. data/app/controllers/spotlight/searches_controller.rb +7 -19
  47. data/app/controllers/spotlight/translations_controller.rb +46 -0
  48. data/app/helpers/spotlight/application_helper.rb +20 -1
  49. data/app/helpers/spotlight/crop_helper.rb +4 -1
  50. data/app/helpers/spotlight/crud_link_helpers.rb +1 -1
  51. data/app/helpers/spotlight/main_app_helpers.rb +1 -1
  52. data/app/helpers/spotlight/pages_helper.rb +1 -1
  53. data/app/jobs/concerns/spotlight/job_tracking.rb +47 -0
  54. data/app/jobs/concerns/spotlight/limit_concurrency.rb +33 -0
  55. data/app/jobs/spotlight/add_uploads_from_csv.rb +34 -6
  56. data/app/jobs/spotlight/application_job.rb +8 -0
  57. data/app/jobs/spotlight/cleanup_job_trackers_job.rb +13 -0
  58. data/app/jobs/spotlight/default_thumbnail_job.rb +1 -3
  59. data/app/jobs/spotlight/reindex_exhibit_job.rb +36 -0
  60. data/app/jobs/spotlight/reindex_job.rb +49 -41
  61. data/app/jobs/spotlight/rename_sidecar_field_job.rb +2 -2
  62. data/app/jobs/spotlight/update_job_trackers_job.rb +20 -0
  63. data/app/mailers/spotlight/indexing_complete_mailer.rb +3 -2
  64. data/app/models/concerns/spotlight/exhibit_defaults.rb +1 -1
  65. data/app/models/concerns/spotlight/translatables.rb +17 -1
  66. data/app/models/concerns/spotlight/user.rb +2 -1
  67. data/app/models/sir_trevor_rails/blocks/browse_group_categories_block.rb +25 -0
  68. data/app/models/spotlight/ability.rb +2 -0
  69. data/app/models/spotlight/about_page.rb +3 -1
  70. data/app/models/spotlight/blacklight_configuration.rb +2 -1
  71. data/app/models/spotlight/contact.rb +1 -1
  72. data/app/models/spotlight/custom_field.rb +3 -3
  73. data/app/models/spotlight/event.rb +13 -0
  74. data/app/models/spotlight/exhibit.rb +18 -14
  75. data/app/models/spotlight/feature_page.rb +3 -1
  76. data/app/models/spotlight/featured_image.rb +29 -12
  77. data/app/models/spotlight/group.rb +22 -0
  78. data/app/models/spotlight/group_member.rb +11 -0
  79. data/app/models/spotlight/home_page.rb +3 -1
  80. data/app/models/spotlight/job_tracker.rb +105 -0
  81. data/app/models/spotlight/main_navigation.rb +2 -2
  82. data/app/models/spotlight/masthead.rb +1 -1
  83. data/app/models/spotlight/page.rb +5 -1
  84. data/app/models/spotlight/page_configurations.rb +6 -0
  85. data/app/models/spotlight/page_content.rb +2 -0
  86. data/app/models/spotlight/reindex_progress.rb +44 -27
  87. data/app/models/spotlight/resource.rb +24 -58
  88. data/app/models/spotlight/resources/csv_upload.rb +2 -1
  89. data/app/models/spotlight/resources/iiif_harvester.rb +10 -1
  90. data/app/models/spotlight/resources/iiif_manifest.rb +11 -7
  91. data/app/models/spotlight/resources/iiif_service.rb +1 -1
  92. data/app/models/spotlight/resources/json_upload.rb +12 -0
  93. data/app/models/spotlight/resources/upload.rb +25 -2
  94. data/app/models/spotlight/search.rb +10 -1
  95. data/app/models/spotlight/solr_document_sidecar.rb +9 -6
  96. data/app/models/spotlight/temporary_image.rb +8 -0
  97. data/app/services/spotlight/etl.rb +7 -0
  98. data/app/services/spotlight/etl/context.rb +52 -0
  99. data/app/services/spotlight/etl/executor.rb +194 -0
  100. data/app/services/spotlight/etl/loaders.rb +12 -0
  101. data/app/services/spotlight/etl/pipeline.rb +81 -0
  102. data/app/services/spotlight/etl/solr_loader.rb +96 -0
  103. data/app/services/spotlight/etl/sources.rb +25 -0
  104. data/app/services/spotlight/etl/step.rb +82 -0
  105. data/app/services/spotlight/etl/transforms.rb +64 -0
  106. data/app/services/spotlight/exhibit_import_export_service.rb +482 -0
  107. data/app/services/spotlight/validity_checker.rb +5 -5
  108. data/app/values/custom_field_name.rb +1 -0
  109. data/app/views/catalog/_save_search.html.erb +1 -1
  110. data/app/views/spotlight/about_pages/_empty.html.erb +5 -5
  111. data/app/views/spotlight/browse/_search.html.erb +5 -3
  112. data/app/views/spotlight/browse/_search_title.html.erb +2 -1
  113. data/app/views/spotlight/browse/index.html.erb +13 -0
  114. data/app/views/spotlight/catalog/_document.html.erb +2 -4
  115. data/app/views/spotlight/catalog/index.iiif_json.jbuilder +22 -0
  116. data/app/views/spotlight/contacts/_form.html.erb +1 -1
  117. data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +6 -6
  118. data/app/views/spotlight/feature_pages/_empty.html.erb +5 -5
  119. data/app/views/spotlight/featured_images/_form.html.erb +1 -1
  120. data/app/views/spotlight/featured_images/_upload_form.html.erb +1 -1
  121. data/app/views/spotlight/home_pages/_empty.html.erb +3 -3
  122. data/app/views/spotlight/indexing_complete_mailer/documents_indexed.html.erb +9 -0
  123. data/app/views/spotlight/pages/_form.html.erb +2 -2
  124. data/app/views/spotlight/searches/_form.html.erb +13 -0
  125. data/app/views/spotlight/searches/_group.html.erb +27 -0
  126. data/app/views/spotlight/searches/_search.html.erb +1 -0
  127. data/app/views/spotlight/searches/index.html.erb +58 -17
  128. data/app/views/spotlight/shared/_honeypot_field.html.erb +4 -0
  129. data/app/views/spotlight/shared/_locale_picker.html.erb +1 -1
  130. data/app/views/spotlight/shared/_report_a_problem.html.erb +7 -10
  131. data/app/views/spotlight/sir_trevor/blocks/_browse_block.html.erb +1 -0
  132. data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +45 -0
  133. data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +7 -1
  134. data/app/views/spotlight/translations/_browse_categories.html.erb +29 -3
  135. data/app/views/spotlight/translations/_general.html.erb +7 -7
  136. data/app/views/spotlight/translations/_groups.html.erb +34 -0
  137. data/app/views/spotlight/translations/_import.html.erb +24 -0
  138. data/app/views/spotlight/translations/_metadata.html.erb +1 -1
  139. data/app/views/spotlight/translations/_page.html.erb +5 -5
  140. data/app/views/spotlight/translations/_pages.html.erb +4 -4
  141. data/app/views/spotlight/translations/_pages_table.html.erb +5 -5
  142. data/app/views/spotlight/translations/_search_fields.html.erb +3 -3
  143. data/app/views/spotlight/translations/edit.html.erb +14 -6
  144. data/app/views/spotlight/translations/show.yaml.yamlbuilder +81 -0
  145. data/config/i18n-tasks.yml +7 -0
  146. data/config/locales/spotlight.ar.yml +57 -24
  147. data/config/locales/spotlight.en.yml +184 -128
  148. data/config/routes.rb +16 -1
  149. data/db/migrate/20200403161512_add_subtitle_to_searches.rb +7 -0
  150. data/db/migrate/20210113092223_create_spotlight_groups.rb +23 -0
  151. data/db/migrate/20210122082032_create_job_trackers.rb +22 -0
  152. data/db/migrate/20210126123041_create_events.rb +15 -0
  153. data/lib/generators/spotlight/install_generator.rb +23 -2
  154. data/lib/generators/spotlight/scaffold_resource_generator.rb +5 -13
  155. data/lib/generators/spotlight/templates/config/initializers/sir_trevor_rails.rb +10 -0
  156. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +3 -1
  157. data/lib/spotlight/engine.rb +35 -4
  158. data/lib/spotlight/upload_field_config.rb +1 -0
  159. data/lib/spotlight/version.rb +1 -1
  160. data/spec/controllers/spotlight/about_pages_controller_spec.rb +3 -3
  161. data/spec/controllers/spotlight/browse_controller_spec.rb +24 -1
  162. data/spec/controllers/spotlight/catalog_controller_spec.rb +4 -2
  163. data/spec/controllers/spotlight/contacts_controller_spec.rb +2 -2
  164. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +11 -0
  165. data/spec/controllers/spotlight/groups_controller_spec.rb +103 -0
  166. data/spec/controllers/spotlight/home_pages_controller_spec.rb +2 -2
  167. data/spec/controllers/spotlight/resources/csv_upload_controller_spec.rb +4 -4
  168. data/spec/controllers/spotlight/searches_controller_spec.rb +10 -3
  169. data/spec/controllers/spotlight/translations_controller_spec.rb +53 -2
  170. data/spec/controllers/spotlight/view_configurations_controller_spec.rb +1 -1
  171. data/spec/examples.txt +1448 -125
  172. data/spec/factories/featured_images.rb +4 -0
  173. data/spec/factories/group.rb +17 -0
  174. data/spec/factories/job_trackers.rb +9 -0
  175. data/spec/factories/searches.rb +11 -1
  176. data/spec/features/add_contacts_spec.rb +1 -1
  177. data/spec/features/add_items_spec.rb +9 -4
  178. data/spec/features/browse_category_admin_spec.rb +39 -7
  179. data/spec/features/browse_category_navigation_spec.rb +44 -0
  180. data/spec/features/browse_category_spec.rb +2 -2
  181. data/spec/features/catalog_spec.rb +2 -2
  182. data/spec/features/create_exhibit_spec.rb +5 -4
  183. data/spec/features/dashboard_spec.rb +7 -7
  184. data/spec/features/edit_search_fields_spec.rb +2 -2
  185. data/spec/features/exhibits/administration_spec.rb +3 -3
  186. data/spec/features/exhibits/edit_metadata_fields_spec.rb +1 -1
  187. data/spec/features/exhibits/language_create_edit_spec.rb +3 -3
  188. data/spec/features/exhibits/translation_editing_spec.rb +57 -8
  189. data/spec/features/home_page_spec.rb +13 -4
  190. data/spec/features/item_admin_spec.rb +4 -4
  191. data/spec/features/javascript/about_page_admin_spec.rb +1 -1
  192. data/spec/features/javascript/block_controls_spec.rb +3 -1
  193. data/spec/features/javascript/blocks/browse_group_categories_block_spec.rb +64 -0
  194. data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +4 -1
  195. data/spec/features/javascript/browse_group_admin_spec.rb +45 -0
  196. data/spec/features/javascript/edit_in_place_spec.rb +3 -3
  197. data/spec/features/javascript/feature_page_admin_spec.rb +1 -1
  198. data/spec/features/javascript/reindex_monitor_spec.rb +1 -1
  199. data/spec/features/javascript/search_config_admin_spec.rb +1 -1
  200. data/spec/features/report_a_problem_spec.rb +6 -5
  201. data/spec/features/site_users_management_spec.rb +4 -4
  202. data/spec/helpers/spotlight/crud_link_helpers_spec.rb +3 -3
  203. data/spec/helpers/spotlight/pages_helper_spec.rb +10 -2
  204. data/spec/i18n_spec.rb +0 -2
  205. data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +13 -1
  206. data/spec/jobs/spotlight/reindex_exhibit_job_spec.rb +43 -0
  207. data/spec/jobs/spotlight/reindex_job_spec.rb +30 -59
  208. data/spec/mailers/spotlight/indexing_complete_mailer_spec.rb +11 -1
  209. data/spec/models/sir_trevor_rails/blocks/browse_group_categories_block_spec.rb +41 -0
  210. data/spec/models/solr_document_spec.rb +2 -3
  211. data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -0
  212. data/spec/models/spotlight/exhibit_spec.rb +21 -59
  213. data/spec/models/spotlight/featured_image_spec.rb +27 -0
  214. data/spec/models/spotlight/group_spec.rb +19 -0
  215. data/spec/models/spotlight/main_navigation_spec.rb +1 -1
  216. data/spec/models/spotlight/page_spec.rb +6 -1
  217. data/spec/models/spotlight/reindex_progress_spec.rb +89 -87
  218. data/spec/models/spotlight/resource_spec.rb +69 -90
  219. data/spec/models/spotlight/resources/iiif_harvester_spec.rb +9 -10
  220. data/spec/models/spotlight/resources/upload_spec.rb +43 -79
  221. data/spec/models/spotlight/role_spec.rb +3 -3
  222. data/spec/models/spotlight/search_spec.rb +30 -3
  223. data/spec/models/spotlight/solr_document_sidecar_spec.rb +1 -0
  224. data/spec/services/spotlight/etl/context_spec.rb +66 -0
  225. data/spec/services/spotlight/etl/executor_spec.rb +149 -0
  226. data/spec/services/spotlight/etl/pipeline_spec.rb +22 -0
  227. data/spec/services/spotlight/etl/solr_loader_spec.rb +76 -0
  228. data/spec/services/spotlight/etl/step_spec.rb +70 -0
  229. data/spec/{serializers/spotlight/exhibit_export_serializer_spec.rb → services/spotlight/exhibit_import_export_service_spec.rb} +168 -23
  230. data/spec/services/spotlight/iiif_resource_resolver_spec.rb +1 -1
  231. data/spec/spec_helper.rb +3 -6
  232. data/spec/support/features/test_features_helpers.rb +15 -0
  233. data/spec/test_app_templates/Gemfile.extra +1 -3
  234. data/spec/test_app_templates/catalog_controller.rb +6 -3
  235. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  236. data/spec/views/shared/_exhibit_navbar.html.erb_spec.rb +1 -1
  237. data/spec/views/spotlight/browse/index.html.erb_spec.rb +2 -0
  238. data/spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb +1 -1
  239. data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +28 -25
  240. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -3
  241. data/spec/views/spotlight/pages/show.html.erb_spec.rb +1 -0
  242. data/spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb +1 -1
  243. data/spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb +7 -8
  244. data/spec/views/spotlight/translations/_import.html.erb_spec.rb +24 -0
  245. data/vendor/assets/javascripts/leaflet-iiif.js +46 -21
  246. data/vendor/assets/javascripts/tiny-slider.js +3218 -0
  247. data/vendor/assets/stylesheets/tiny-slider.css +1 -0
  248. metadata +444 -289
  249. data/app/models/concerns/spotlight/resources/open_graph.rb +0 -36
  250. data/app/models/spotlight/reindexing_log_entry.rb +0 -42
  251. data/app/serializers/spotlight/exhibit_export_serializer.rb +0 -205
  252. data/app/serializers/spotlight/featured_image_representer.rb +0 -29
  253. data/app/serializers/spotlight/main_navigation_representer.rb +0 -13
  254. data/app/serializers/spotlight/page_representer.rb +0 -33
  255. data/app/services/spotlight/resources/iiif_builder.rb +0 -19
  256. data/app/services/spotlight/solr_document_builder.rb +0 -76
  257. data/app/services/spotlight/upload_solr_document_builder.rb +0 -57
  258. data/spec/factories/reindexing_log_entries.rb +0 -54
  259. data/spec/models/spotlight/reindexing_log_entry_spec.rb +0 -129
  260. data/spec/models/spotlight/resources/open_graph_spec.rb +0 -65
  261. data/spec/services/spotlight/solr_document_builder_spec.rb +0 -66
  262. data/vendor/assets/javascripts/handlebars-v1.3.0.js +0 -2746
@@ -3,6 +3,22 @@
3
3
  describe Spotlight::FeaturedImage do
4
4
  subject(:featured_image) { described_class.new }
5
5
 
6
+ let(:temp_image) { FactoryBot.create(:temporary_image) }
7
+
8
+ context 'with an uploaded image' do
9
+ it 'copies the temporary uploaded image to this model' do
10
+ featured_image.source = 'remote'
11
+ featured_image.upload_id = temp_image.id
12
+
13
+ featured_image.save
14
+
15
+ expect(featured_image.image.filename).to eq temp_image.image.filename
16
+ expect(featured_image.image.read).to eq temp_image.image.read
17
+
18
+ expect { temp_image.reload }.to raise_exception ActiveRecord::RecordNotFound
19
+ end
20
+ end
21
+
6
22
  describe '#iiif_url' do
7
23
  let(:iiif_tilesource) { 'http://example.com/iiif/abc123/info.json' }
8
24
  let(:iiif_region) { '0,0,400,300' }
@@ -17,6 +33,17 @@ describe Spotlight::FeaturedImage do
17
33
  expect(subject.iiif_url).to match(%r{^http://example.com/iiif/abc123/})
18
34
  expect(subject.iiif_url).not_to include('info.json')
19
35
  end
36
+
37
+ context 'with an uploaded image' do
38
+ before do
39
+ featured_image.image = temp_image.image
40
+ featured_image.save!
41
+ end
42
+
43
+ it 'points at the RIIIF endpoint' do
44
+ expect(subject.iiif_url).to match(%r{^/images/\d+/})
45
+ end
46
+ end
20
47
  end
21
48
 
22
49
  describe 'region' do
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::Group, type: :model do
4
+ let(:exhibit) { FactoryBot.create(:exhibit) }
5
+
6
+ describe '#searches' do
7
+ let(:group) { FactoryBot.create(:group_with_searches, exhibit: exhibit, searches_count: 4) }
8
+
9
+ it do
10
+ expect(group.searches.count).to eq 4
11
+ end
12
+
13
+ it do
14
+ group.searches.all do |search|
15
+ expect(search).to be_an Spotlight::Search
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,7 +7,7 @@ describe Spotlight::MainNavigation, type: :model do
7
7
 
8
8
  it 'has a default_label' do
9
9
  subject.nav_type = :curated_features
10
- expect(subject.default_label).to eq 'Curated Features'
10
+ expect(subject.default_label).to eq 'Curated features'
11
11
  end
12
12
 
13
13
  it 'returns the use the default label in the absence of a label' do
@@ -119,7 +119,7 @@ describe Spotlight::Page, type: :model do
119
119
  end
120
120
 
121
121
  describe '#slug' do
122
- let(:page) { FactoryBot.create(:feature_page) }
122
+ let(:page) { FactoryBot.create(:about_page) }
123
123
 
124
124
  it 'gets a default slug' do
125
125
  expect(page.slug).not_to be_blank
@@ -130,6 +130,11 @@ describe Spotlight::Page, type: :model do
130
130
  expect(page.slug).to eq 'abc'
131
131
  end
132
132
 
133
+ it 'blacklists contacts' do
134
+ page.update(title: 'contacts')
135
+ expect(page.slug).not_to eq 'contacts'
136
+ end
137
+
133
138
  context 'with a custom slug' do
134
139
  let(:page) { FactoryBot.create(:feature_page, slug: 'xyz') }
135
140
 
@@ -1,122 +1,124 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Spotlight::ReindexProgress, type: :model do
4
- let(:reindexing_log_entry) do
5
- FactoryBot.create(:failed_reindexing_log_entry, items_reindexed_estimate: 12)
4
+ subject(:progress) { described_class.new(exhibit) }
5
+
6
+ let(:exhibit) { FactoryBot.create(:exhibit) }
7
+ let!(:job_tracker) do
8
+ FactoryBot.create(
9
+ :job_tracker,
10
+ resource: exhibit,
11
+ on: exhibit,
12
+ job_class: 'Spotlight::ReindexExhibitJob',
13
+ updated_at: Time.zone.now,
14
+ **job_tracker_args
15
+ )
6
16
  end
17
+ let(:job_tracker_args) { {} }
7
18
 
8
- let(:subject) { described_class.new(reindexing_log_entry) }
19
+ context 'with a completed job' do
20
+ let(:job_tracker_args) { { status: 'completed', data: { progress: 50, total: 50 } } }
9
21
 
10
- describe '#started_at' do
11
- it 'returns start_time for current_log_entry' do
12
- expect(subject.started_at).to eq reindexing_log_entry.start_time
22
+ it 'reports on reindexing progress' do
23
+ expect(progress.as_json).to include(
24
+ completed: 50,
25
+ total: 50,
26
+ finished: true,
27
+ errored: false,
28
+ recently_in_progress: true
29
+ )
13
30
  end
14
31
  end
15
32
 
16
- describe '#updated_at' do
17
- it 'returns the time of last update for current_log_entry' do
18
- expect(subject.updated_at).to eq reindexing_log_entry.updated_at
19
- end
20
- end
33
+ context 'with a failed job' do
34
+ let(:job_tracker_args) { { status: 'failed', data: { progress: 32, total: 50 } } }
21
35
 
22
- describe '#finished?' do
23
- it 'returns true if current_log_entry is succeeded or failed' do
24
- expect(subject.finished?).to be true
36
+ it 'reports on reindexing progress' do
37
+ expect(progress.as_json).to include(
38
+ completed: 32,
39
+ total: 50,
40
+ finished: true,
41
+ errored: true
42
+ )
25
43
  end
26
44
  end
27
45
 
28
- describe '#finished_at' do
29
- it 'returns end_time for current_log_entry' do
30
- expect(subject.finished_at).to eq(reindexing_log_entry.end_time)
46
+ context 'with an in-progress job' do
47
+ before do
48
+ FactoryBot.create(:job_tracker, on: job_tracker, resource: exhibit, data: { progress: 32, total: 32 }, status: 'completed')
49
+ FactoryBot.create(:job_tracker, on: job_tracker, resource: exhibit, data: { progress: 16, total: 50 }, status: 'in_progress')
31
50
  end
32
- end
33
51
 
34
- describe '#total' do
35
- it 'returns items_reindexed_estimate for current_log_entry' do
36
- expect(subject.total).to be 12
37
- end
38
- end
52
+ let(:job_tracker_args) { { status: 'in_progress' } }
39
53
 
40
- describe '#completed' do
41
- it 'returns items_reindexed_count for current_log_entry' do
42
- expect(subject.completed).to be 10
54
+ it 'harvests total and completed data from the child jobs' do
55
+ expect(progress.as_json).to include(
56
+ completed: 48,
57
+ total: 82
58
+ )
43
59
  end
44
- end
45
60
 
46
- describe '#errored?' do
47
- it 'returns true for log entries marked as failed' do
48
- expect(subject).to be_errored
49
- end
50
- end
61
+ it 'is not completed until all the child jobs are finished' do
62
+ job_tracker.update(status: 'failed')
51
63
 
52
- describe '#as_json' do
53
- it 'returns a hash with values for current_log_entry via the various helper methods' do
54
- expect(subject.as_json).to eq(
55
- recently_in_progress: subject.recently_in_progress?,
56
- started_at: I18n.l(reindexing_log_entry.start_time, format: :long),
57
- finished_at: I18n.l(reindexing_log_entry.end_time, format: :long),
58
- updated_at: I18n.l(reindexing_log_entry.updated_at, format: :long),
59
- total: subject.total,
60
- completed: subject.completed,
61
- errored: subject.errored?,
62
- finished: subject.finished?
64
+ expect(progress.as_json).to include(
65
+ finished: false,
66
+ errored: true
63
67
  )
64
68
  end
65
69
  end
66
70
 
67
- describe '#recently_in_progress?' do
68
- context 'there is no end_time for current_log_entry' do
69
- let(:reindexing_log_entry) { FactoryBot.create(:in_progress_reindexing_log_entry) }
70
-
71
- it 'returns true' do
72
- expect(subject).to be_recently_in_progress
73
- end
71
+ context 'with no job' do
72
+ before do
73
+ job_tracker.delete
74
74
  end
75
75
 
76
- context 'current_log_entry has an end_time less than Spotlight::Engine.config.reindex_progress_window.minutes.ago' do
77
- let(:reindexing_log_entry) { FactoryBot.create(:recent_reindexing_log_entry, end_time: Time.zone.now) }
78
-
79
- it 'returns true' do
80
- expect(subject).to be_recently_in_progress
81
- end
76
+ it 'reports on reindexing progress' do
77
+ expect(progress.as_json).to include(
78
+ completed: 0,
79
+ total: 0,
80
+ finished: false,
81
+ errored: false,
82
+ recently_in_progress: false
83
+ )
82
84
  end
85
+ end
83
86
 
84
- context 'current_log_entry is unstarted ' do
85
- let(:reindexing_log_entry) { FactoryBot.create(:unstarted_reindexing_log_entry) }
87
+ context 'with multiple job trackers' do
88
+ let(:job_tracker_args) { { status: 'in_progress' } }
89
+
90
+ before do
91
+ FactoryBot.create(
92
+ :job_tracker,
93
+ resource: exhibit,
94
+ on: exhibit,
95
+ job_class: 'Spotlight::ReindexExhibitJob',
96
+ updated_at: Time.zone.now,
97
+ status: 'completed'
98
+ )
99
+ end
86
100
 
87
- it 'returns false' do
88
- expect(subject).not_to be_recently_in_progress
89
- end
101
+ it 'uses the currently in-progress tracker' do
102
+ expect(progress.as_json).to include(finished: false)
90
103
  end
91
104
  end
92
105
 
93
- context 'current_log_entry is blan' do
94
- let(:reindexing_log_entry) { Spotlight::ReindexingLogEntry.new }
95
-
96
- # rubocop:disable RSpec/MultipleExpectations
97
- it 'methods return gracefully' do
98
- expect(subject.recently_in_progress?).to be false
99
- expect(subject.started_at).to be nil
100
- expect(subject.updated_at).to be nil
101
- expect(subject.finished?).to be false
102
- expect(subject.finished_at).to be nil
103
- expect(subject.total).to be nil
104
- expect(subject.completed).to be nil
105
- expect(subject.errored?).to be false
106
- expect(subject.send(:localized_start_time)).to be nil
107
- expect(subject.send(:localized_finish_time)).to be nil
108
- expect(subject.send(:localized_updated_time)).to be nil
109
- expect(subject.as_json).to eq(
110
- recently_in_progress: false,
111
- started_at: nil,
112
- finished_at: nil,
113
- updated_at: nil,
114
- total: nil,
115
- completed: nil,
116
- errored: false,
117
- finished: false
106
+ context 'with multiple in-progress trackers' do
107
+ let(:job_tracker_args) { { status: 'in_progress' } }
108
+
109
+ before do
110
+ FactoryBot.create(
111
+ :job_tracker,
112
+ resource: exhibit,
113
+ on: exhibit,
114
+ job_class: 'Spotlight::ReindexExhibitJob',
115
+ updated_at: Time.zone.now - 5.years,
116
+ status: 'in_progress'
118
117
  )
119
118
  end
120
- # rubocop:enable RSpec/MultipleExpectations
119
+
120
+ it 'uses the most recently updated tracker' do
121
+ expect(Time.zone.parse(progress.as_json[:updated_at]).year).to eq job_tracker.updated_at.year
122
+ end
121
123
  end
122
124
  end
@@ -1,126 +1,105 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Spotlight::Resource, type: :model do
4
- before do
5
- allow_any_instance_of(described_class).to receive(:update_index)
6
- end
4
+ subject(:resource) { described_class.create(id: 123, exhibit: exhibit) }
7
5
 
8
6
  let(:exhibit) { FactoryBot.create(:exhibit) }
9
7
 
10
- describe '#reindex' do
11
- context 'with a provider that generates ids' do
12
- subject do
13
- Class.new(described_class).new(exhibit: exhibit)
14
- end
8
+ describe '#save_and_index' do
9
+ before do
10
+ allow(subject).to receive(:save)
11
+ allow(subject).to receive(:reindex_later)
12
+ end
15
13
 
16
- let(:solr_response) { { id: 123 } }
14
+ it 'saves the object' do
15
+ expect(subject).to receive(:save).and_return(true)
16
+ subject.save_and_index
17
+ end
17
18
 
18
- before do
19
- SolrDocument.new(id: 123).sidecars.create!(exhibit: exhibit, data: { document_data: true })
20
- allow(subject).to receive_messages(to_global_id: '')
19
+ it 'reindexes after save' do
20
+ expect(subject).to receive(:save).and_return(true)
21
+ expect(subject).to receive(:reindex_later)
22
+ subject.save_and_index
23
+ end
21
24
 
22
- allow(subject.document_builder).to receive(:to_solr).and_return(solr_response)
25
+ context 'if the save fails' do
26
+ it 'does not reindex' do
27
+ expect(subject).to receive(:save).and_return(false)
28
+ expect(subject).not_to receive(:reindex_later)
29
+ subject.save_and_index
23
30
  end
31
+ end
32
+ end
24
33
 
25
- it 'includes exhibit document-specific data' do
26
- allow(subject.send(:blacklight_solr)).to receive(:update) do |options|
27
- data = JSON.parse(options[:data], symbolize_names: true)
28
-
29
- expect(data.length).to eq 1
30
- doc = data.first
31
-
32
- break if doc.first == :commit
33
-
34
- expect(doc).to include document_data: true
35
- end
36
-
37
- subject.reindex
38
- end
34
+ describe '#reindex' do
35
+ before do
36
+ # sneak some data into the pipeline
37
+ subject.indexing_pipeline.transforms = [->(*) { { id: '123' } }] + subject.indexing_pipeline.transforms
38
+ end
39
39
 
40
- context 'when a document does not have an identifier' do
41
- let(:solr_response) { { other_field: 'Content' } }
40
+ let(:indexed_document) do
41
+ result = nil
42
42
 
43
- it 'is not indexed (but a commit can be sent)' do
44
- allow(subject.send(:blacklight_solr)).to receive(:commit)
45
- expect(subject.send(:blacklight_solr)).not_to receive(:update)
43
+ subject.reindex(**index_args) do |data, *|
44
+ result = data
46
45
 
47
- subject.reindex
48
- end
46
+ # skip actually indexing the document into the solr index
47
+ throw :skip
49
48
  end
50
49
 
51
- context 'reindexing_log_entry is provided' do
52
- before do
53
- allow(subject.send(:blacklight_solr)).to receive(:update)
54
- end
55
-
56
- it 'updates the count of reindexed items in the log entry' do
57
- reindexing_log_entry = double(Spotlight::ReindexingLogEntry)
58
- expect(reindexing_log_entry).to receive(:update).with(items_reindexed_count: 1)
59
- subject.reindex reindexing_log_entry
60
- end
61
- end
50
+ result
51
+ end
62
52
 
63
- context 'when the index is not writable' do
64
- before do
65
- allow(Spotlight::Engine.config).to receive_messages(writable_index: false)
66
- end
53
+ let(:index_args) { {} }
67
54
 
68
- it "doesn't write" do
69
- expect(subject.send(:blacklight_solr)).not_to receive(:update)
70
- subject.reindex
71
- end
72
- end
55
+ it 'returns the number of items indexed' do
56
+ expect(subject.reindex { |*| throw :skip }).to eq 1
57
+ end
73
58
 
74
- context 'with a resource that creates multiple solr documents' do
75
- let(:solr_response) { [{ id: 1 }, { id: 2 }] }
59
+ it 'applies exhibit-specific metadata from the sidecar' do
60
+ expect(indexed_document).to include Spotlight::SolrDocumentSidecar.new(document: SolrDocument.new(id: '123'), exhibit: exhibit).to_solr
61
+ end
76
62
 
77
- before do
78
- allow(subject.send(:blacklight_solr)).to receive(:update)
79
- end
63
+ it 'includes metata from each sidecar' do
64
+ a = Spotlight::SolrDocumentSidecar.create(document: SolrDocument.new(id: '123'), exhibit: exhibit)
65
+ b = Spotlight::SolrDocumentSidecar.create(document: SolrDocument.new(id: '123'), exhibit: FactoryBot.build(:exhibit))
80
66
 
81
- it 'returns the number of indexed objects' do
82
- expect(subject.reindex).to eq 2
83
- end
67
+ expect(indexed_document).to include(a.to_solr).and(include(b.to_solr))
68
+ end
84
69
 
85
- it 'triggers a solr commit' do
86
- expect(subject.send(:blacklight_solr)).to receive(:commit).once
70
+ it 'persists a sidecar document' do
71
+ expect { indexed_document }.to change(Spotlight::SolrDocumentSidecar, :count).by(1)
87
72
 
88
- subject.reindex
89
- end
73
+ expect(Spotlight::SolrDocumentSidecar.last).to have_attributes(document_id: '123', exhibit: exhibit)
74
+ end
90
75
 
91
- it 'touches the exhibit to clear any caches' do
92
- allow(subject.exhibit).to receive(:touch)
76
+ it 'applies application metadata' do
77
+ expect(indexed_document).to include(spotlight_resource_id_ssim: resource.to_global_id.to_s, spotlight_resource_type_ssim: 'spotlight/resources')
78
+ end
93
79
 
94
- subject.reindex
80
+ context 'with some provided metadata' do
81
+ let(:index_args) { { additional_metadata: { a: 1 } } }
95
82
 
96
- expect(subject.exhibit).to have_received(:touch)
97
- end
83
+ it 'applies externally provided metadata' do
84
+ expect(indexed_document).to include a: 1
98
85
  end
99
86
  end
100
- end
101
87
 
102
- describe '#save_and_index' do
103
- before do
104
- allow(subject.send(:blacklight_solr)).to receive(:update)
105
- allow(subject).to receive(:reindex_later)
106
- end
88
+ it 'touches the exhibit to bust any caches' do
89
+ allow(exhibit).to receive(:touch)
107
90
 
108
- it 'saves the object' do
109
- expect(subject).to receive(:save).and_return(true)
110
- subject.save_and_index
111
- end
91
+ indexed_document
112
92
 
113
- it 'reindexes after save' do
114
- expect(subject).to receive(:save).and_return(true)
115
- expect(subject).to receive(:reindex_later)
116
- subject.save_and_index
93
+ expect(exhibit).to have_received(:touch)
117
94
  end
118
95
 
119
- context 'if the save fails' do
120
- it 'does not reindex' do
121
- expect(subject).to receive(:save).and_return(false)
122
- expect(subject).not_to receive(:reindex_later)
123
- subject.save_and_index
96
+ context 'with touch: false' do
97
+ it 'does not touch the exhibit' do
98
+ allow(exhibit).to receive(:touch)
99
+
100
+ expect(subject.reindex(touch: false) { |*| throw :skip }).to eq 1
101
+
102
+ expect(exhibit).not_to have_received(:touch)
124
103
  end
125
104
  end
126
105
  end