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
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::Etl::Pipeline do
4
+ let(:mock_executor) { instance_double(Spotlight::Etl::Executor, call: 'result', estimated_size: 10) }
5
+ let(:context) { instance_double(Spotlight::Etl::Context) }
6
+
7
+ describe '#call' do
8
+ it 'forwards the call to the executor' do
9
+ allow(Spotlight::Etl::Executor).to receive(:new).with(subject, context, cache: nil).and_return(mock_executor)
10
+
11
+ expect(subject.call(context)).to eq 'result'
12
+ end
13
+ end
14
+
15
+ describe '#estimated_size' do
16
+ it 'forwards the call to the executor' do
17
+ allow(Spotlight::Etl::Executor).to receive(:new).with(subject, context).and_return(mock_executor)
18
+
19
+ expect(subject.estimated_size(context)).to eq 10
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::Etl::SolrLoader do
4
+ subject(:loader) { described_class.new(batch_size: 5, solr_connection: mock_connection) }
5
+
6
+ let(:mock_connection) { instance_double(RSolr::Client, commit: nil, update: nil) }
7
+
8
+ describe '#call' do
9
+ it 'queues data' do
10
+ loader.call({})
11
+ loader.call({})
12
+ loader.call({})
13
+
14
+ expect(loader.size).to eq 3
15
+ end
16
+
17
+ it 'writes data to the index when the queue is long enough' do
18
+ 5.times { loader.call({}) }
19
+
20
+ expect(mock_connection).to have_received(:update) do |data:, **|
21
+ expect(JSON.parse(data).length).to eq 5
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#finalize' do
27
+ let(:pipeline) do
28
+ Spotlight::Etl::Executor.new(nil, Spotlight::Etl::Context.new(commit: false))
29
+ end
30
+
31
+ it 'flushes the remaining queue to the index' do
32
+ 3.times { loader.call({}) }
33
+
34
+ loader.finalize
35
+
36
+ expect(mock_connection).to have_received(:update) do |data:, **|
37
+ expect(JSON.parse(data).length).to eq 3
38
+ end
39
+
40
+ expect(mock_connection).to have_received(:commit)
41
+ end
42
+
43
+ it 'uses the pipeline configuration to determine whether to send a commit' do
44
+ loader.finalize(pipeline)
45
+
46
+ expect(mock_connection).not_to have_received(:commit)
47
+ end
48
+
49
+ context 'error handling' do
50
+ it 'tries documents individually if the whole batch fails' do
51
+ allow(mock_connection).to receive(:update) do |data:, **|
52
+ raise '???' if JSON.parse(data).length > 1
53
+ end
54
+
55
+ 3.times { loader.call({}) }
56
+ loader.finalize
57
+
58
+ expect(mock_connection).to have_received(:update).exactly(4).times
59
+ end
60
+
61
+ it 'logs errors from trying individual documents' do
62
+ allow(pipeline).to receive(:on_error)
63
+
64
+ allow(mock_connection).to receive(:update) do |**|
65
+ raise '???'
66
+ end
67
+
68
+ loader.call({})
69
+
70
+ loader.finalize(pipeline)
71
+
72
+ expect(pipeline).to have_received(:on_error).once
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::Etl::Step do
4
+ subject(:step) { described_class.new(definition, **step_args) }
5
+
6
+ let(:definition) { ->(a = nil) { a || 'value' } }
7
+ let(:step_args) { {} }
8
+
9
+ describe '#call' do
10
+ it 'returns the value from the defined step' do
11
+ expect(step.call).to eq('value')
12
+ end
13
+
14
+ it 'passes through arguments' do
15
+ expect(step.call('a')).to eq('a')
16
+ end
17
+
18
+ context 'with a class instance' do
19
+ let(:definition) { Spotlight::Etl::SolrLoader.new }
20
+
21
+ it 'runs the call method' do
22
+ allow(definition).to receive(:call)
23
+
24
+ step.call('a')
25
+
26
+ expect(definition).to have_received(:call).with('a')
27
+ end
28
+ end
29
+
30
+ context 'with a class' do
31
+ let(:definition) { Spotlight::Etl::SolrLoader }
32
+ let(:mock) { instance_double(definition, call: nil) }
33
+
34
+ it 'runs the call method' do
35
+ allow(definition).to receive(:new).and_return(mock)
36
+
37
+ step.call('a', 'b')
38
+
39
+ expect(mock).to have_received(:call).with('a', 'b')
40
+ end
41
+
42
+ it 'uses the same instance for the lifetime of the step' do
43
+ allow(definition).to receive(:new).once.and_return(mock)
44
+
45
+ step.call('a', 'b')
46
+ step.call('a', 'b')
47
+
48
+ expect(mock).to have_received(:call).twice.with('a', 'b')
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#finalize' do
54
+ it 'does nothing if the definition does not have a #finalize method' do
55
+ expect { step.finalize }.not_to raise_exception
56
+ end
57
+
58
+ context 'with a loader' do
59
+ let(:definition) { Spotlight::Etl::SolrLoader.new }
60
+
61
+ it 'runs the finalize method' do
62
+ allow(definition).to receive(:finalize)
63
+
64
+ step.finalize
65
+
66
+ expect(definition).to have_received(:finalize)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Spotlight::ExhibitExportSerializer do
3
+ describe Spotlight::ExhibitImportExportService do
4
4
  subject { JSON.parse(described_class.new(source_exhibit).to_json) }
5
5
 
6
6
  let!(:source_exhibit) { FactoryBot.create(:exhibit) }
@@ -24,6 +24,10 @@ describe Spotlight::ExhibitExportSerializer do
24
24
  expect(subject['searches']).to have(source_exhibit.searches.count).searches
25
25
  end
26
26
 
27
+ it 'has group attributes' do
28
+ expect(subject['groups']).to have(source_exhibit.groups.count).groups
29
+ end
30
+
27
31
  it 'has home page attributes' do
28
32
  expect(subject).to have_key 'home_page'
29
33
  expect(subject['home_page']).not_to have_key 'id'
@@ -83,29 +87,43 @@ describe Spotlight::ExhibitExportSerializer do
83
87
 
84
88
  describe 'should round-trip data' do
85
89
  subject do
86
- e = FactoryBot.create(:exhibit)
87
- e.import(export).tap(&:save)
90
+ destination_exhibit.import(export)
91
+ destination_exhibit
88
92
  end
89
93
 
90
- before do
91
- sidecar = source_exhibit.solr_document_sidecars.create! document: SolrDocument.new(id: 1), public: false
92
- source_exhibit.tag(sidecar, with: 'xyz', on: :tags)
93
- end
94
+ let(:destination_exhibit) { FactoryBot.create(:exhibit) }
94
95
 
95
96
  let :export do
96
97
  described_class.new(source_exhibit).as_json
97
98
  end
98
99
 
100
+ before do
101
+ sidecar = source_exhibit.solr_document_sidecars.create! document: SolrDocument.new(id: 1), public: false
102
+ source_exhibit.tag(sidecar, with: 'xyz', on: :tags)
103
+ end
104
+
99
105
  it 'has exhibit properties' do
100
106
  expect(subject.title).to eq source_exhibit.title
101
107
  end
102
108
 
109
+ context 'with a theme that does not exist in the destination' do
110
+ it 'ignores the invalid theme' do
111
+ source_exhibit.theme = 'xyz'
112
+ expect(subject.theme).to eq nil
113
+ end
114
+ end
115
+
103
116
  it 'does not duplicate saved searches' do
104
117
  expect(subject.searches).to have(1).item
105
118
  end
106
119
 
107
120
  it 'has blacklight configuration properties' do
121
+ subject.blacklight_configuration.index_fields_will_change!
122
+ subject.blacklight_configuration.index_fields['language_ssm'] = { some_value: true }
123
+ subject.blacklight_configuration.save
124
+
108
125
  expect(subject.blacklight_configuration).to be_persisted
126
+ expect(subject.blacklight_configuration.blacklight_config.index_fields['language_ssm'].to_h).to include some_value: true
109
127
  end
110
128
 
111
129
  context 'for an exhibit without search fields' do
@@ -221,7 +239,7 @@ describe Spotlight::ExhibitExportSerializer do
221
239
  before do
222
240
  feature_page.content = { data: [{ type: 'text', data: { text: 'xyz' } }] }.to_json
223
241
  feature_page.thumbnail = thumbnail
224
- feature_page.save
242
+ feature_page.save!
225
243
  end
226
244
 
227
245
  it 'copies the masthead' do
@@ -239,6 +257,21 @@ describe Spotlight::ExhibitExportSerializer do
239
257
  expect(subject.feature_pages.first.content.length).to eq 1
240
258
  expect(subject.feature_pages.first.content.first).to be_a_kind_of SirTrevorRails::Blocks::TextBlock
241
259
  end
260
+
261
+ context 'with a translation' do
262
+ before do
263
+ localized_page = feature_page.clone_for_locale('ar')
264
+ localized_page.content = { data: [{ type: 'text', data: { text: 'xyz-in-ar' } }] }.to_json
265
+ localized_page.save!
266
+ end
267
+
268
+ it 'transfers the localized page' do
269
+ expect(subject.feature_pages.first.translated_pages.length).to eq 1
270
+ expect(JSON.parse(subject.feature_pages.first.translated_page_for('ar').read_attribute(:content))).to have_key 'data'
271
+ expect(subject.feature_pages.first.translated_page_for('ar').content.length).to eq 1
272
+ expect(subject.feature_pages.first.translated_page_for('ar').content.first).to be_a_kind_of SirTrevorRails::Blocks::TextBlock
273
+ end
274
+ end
242
275
  end
243
276
 
244
277
  it 'assigns STI resources the correct class' do
@@ -259,19 +292,31 @@ describe Spotlight::ExhibitExportSerializer do
259
292
  let(:masthead) { FactoryBot.create(:masthead) }
260
293
  let(:thumbnail) { FactoryBot.create(:featured_image) }
261
294
  let!(:search) { FactoryBot.create(:search, exhibit: source_exhibit, masthead: masthead, thumbnail: thumbnail) }
295
+ let!(:existing_search) { FactoryBot.create(:search, slug: search.slug, exhibit: destination_exhibit) }
262
296
 
263
297
  before do
264
298
  source_exhibit.reload
299
+ destination_exhibit.reload
300
+ end
301
+
302
+ it 'copies the title' do
303
+ subject
304
+ existing_search.reload
305
+ expect(existing_search.title).to eq search.title
265
306
  end
266
307
 
267
308
  it 'copies the masthead' do
268
- expect(subject.searches.last.masthead).not_to be_blank
269
- expect(subject.searches.last.masthead.image.file.path).not_to eq search.masthead.image.file.path
309
+ subject
310
+ existing_search.reload
311
+ expect(existing_search.masthead).not_to be_blank
312
+ expect(existing_search.masthead.image.file.path).not_to eq search.masthead.image.file.path
270
313
  end
271
314
 
272
315
  it 'copies the thumbnail' do
273
- expect(subject.searches.first.thumbnail).not_to be_blank
274
- expect(subject.searches.first.thumbnail.image.file.path).not_to eq search.thumbnail.image.file.path
316
+ subject
317
+ existing_search.reload
318
+ expect(existing_search.thumbnail).not_to be_blank
319
+ expect(existing_search.thumbnail.image.file.path).not_to eq search.thumbnail.image.file.path
275
320
  end
276
321
 
277
322
  context 'without an attached image' do
@@ -281,8 +326,24 @@ describe Spotlight::ExhibitExportSerializer do
281
326
  end
282
327
 
283
328
  it 'copies the masthead without an image' do
284
- expect(subject.searches.last.masthead).not_to be_blank
285
- expect(subject.searches.last.masthead.image).to be_blank
329
+ subject
330
+ existing_search.reload
331
+ expect(existing_search.masthead).not_to be_blank
332
+ expect(existing_search.masthead.image).to be_blank
333
+ end
334
+ end
335
+
336
+ context 'remote thumbnail with existing tilesource' do
337
+ it do
338
+ search.thumbnail.iiif_tilesource
339
+ search.thumbnail.save
340
+ source_exhibit.reload
341
+ end
342
+
343
+ it 'unsets the iiif_tilesource' do
344
+ subject
345
+ existing_search.reload
346
+ expect(existing_search.thumbnail.iiif_tilesource).not_to eq search.thumbnail.iiif_tilesource
286
347
  end
287
348
  end
288
349
 
@@ -290,13 +351,44 @@ describe Spotlight::ExhibitExportSerializer do
290
351
  before do
291
352
  search.masthead.document_global_id = SolrDocument.new(id: 'xyz').to_global_id
292
353
  search.masthead.source = 'exhibit'
354
+ search.masthead.iiif_tilesource = 'foo'
355
+ search.masthead.image = nil # Setting to nil to mimick an exhibit source
293
356
  search.masthead.save
294
357
 
295
358
  source_exhibit.reload
296
359
  end
297
360
 
298
361
  it 'copies the resource' do
299
- expect(subject.searches.last.masthead).not_to be_blank
362
+ subject
363
+ existing_search.reload
364
+ expect(existing_search.masthead).not_to be_blank
365
+ end
366
+
367
+ it 'does not unset the iiif_tilesource' do
368
+ subject
369
+ existing_search.reload
370
+ expect(existing_search.masthead.iiif_tilesource).to eq search.masthead.iiif_tilesource
371
+ end
372
+ end
373
+
374
+ context 'in a group' do
375
+ let!(:group) { FactoryBot.create(:group, title: 'blah', exhibit: source_exhibit) }
376
+
377
+ before do
378
+ search.groups << group
379
+ search.save!
380
+ end
381
+
382
+ it 'copies the group' do
383
+ subject
384
+ expect(destination_exhibit.groups.length).to eq 1
385
+ expect(destination_exhibit.groups.first.as_json).to include(group.as_json.slice('slug', 'title', 'weight', 'published'))
386
+ end
387
+
388
+ it 'copies the group membership' do
389
+ subject
390
+ expect(existing_search.reload.groups.length).to eq 1
391
+ expect(existing_search.groups.pluck(:slug)).to match_array [group.slug]
300
392
  end
301
393
  end
302
394
  end
@@ -328,18 +420,71 @@ describe Spotlight::ExhibitExportSerializer do
328
420
  end
329
421
  end
330
422
 
331
- it 'is idempotent-ish' do
332
- FactoryBot.create :feature_subpage, exhibit: source_exhibit
333
- export = described_class.new(source_exhibit).as_json
334
- e = FactoryBot.create(:exhibit)
335
- e.import(export).tap(&:save)
336
- e.import(export).tap(&:save)
423
+ context 'testing idempotency' do
424
+ let(:masthead) { FactoryBot.create(:masthead) }
425
+ let(:thumbnail) { FactoryBot.create(:exhibit_thumbnail) }
426
+ let!(:search) { FactoryBot.create(:search, exhibit: source_exhibit, masthead: FactoryBot.create(:masthead), thumbnail: FactoryBot.create(:featured_image)) }
427
+ let!(:feature_page_1) { FactoryBot.create(:feature_page, exhibit: source_exhibit) }
428
+ let!(:feature_page_2) { FactoryBot.create(:feature_page, exhibit: source_exhibit) }
429
+
430
+ before do
431
+ source_exhibit.masthead = masthead
432
+ source_exhibit.thumbnail = thumbnail
433
+ end
434
+
435
+ # From Rails 6:
436
+ def _deep_transform_values_in_object(object, &block)
437
+ case object
438
+ when Hash
439
+ object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
440
+ when Array
441
+ object.map { |e| _deep_transform_values_in_object(e, &block) }
442
+ else
443
+ yield(object)
444
+ end
445
+ end
446
+
447
+ it 'is re-runnable' do
448
+ FactoryBot.create :feature_subpage, exhibit: source_exhibit
449
+ export = described_class.new(source_exhibit).as_json
450
+ e = FactoryBot.create(:exhibit)
451
+ e.import(export)
452
+ e.import(export)
453
+ end
454
+
455
+ it 'is idempotent-ish' do
456
+ export = described_class.new(source_exhibit).as_json
457
+ e = FactoryBot.create(:exhibit)
458
+ e.import(export)
459
+ new_export = described_class.new(e).as_json
460
+
461
+ actual = _deep_transform_values_in_object(new_export) do |v|
462
+ if DateTime.parse(v.to_s)
463
+ nil
464
+ else
465
+ v
466
+ end
467
+ rescue ArgumentError
468
+ nil
469
+ end
470
+ expected = _deep_transform_values_in_object(export) do |v|
471
+ if DateTime.parse(v.to_s)
472
+ nil
473
+ else
474
+ v
475
+ end
476
+ rescue ArgumentError
477
+ nil
478
+ end
479
+ expect(actual).to include expected
480
+ end
337
481
  end
338
482
 
339
483
  describe 'should export saved searches with query parameters that can be re-generated' do
340
484
  subject do
341
485
  e = FactoryBot.create(:exhibit)
342
- e.import(export).tap(&:save)
486
+ e.import(export)
487
+ e
343
488
  end
344
489
 
345
490
  before do
@@ -418,7 +563,7 @@ describe Spotlight::ExhibitExportSerializer do
418
563
  end
419
564
 
420
565
  it 'includes only the page-related data' do
421
- expect(subject.keys).to match_array %w[searches about_pages feature_pages home_page contacts]
566
+ expect(subject.keys).to match_array %w[searches groups about_pages feature_pages home_page contacts]
422
567
  end
423
568
  end
424
569
  end