blacklight-spotlight 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/app/assets/images/spotlight/default_browse_thumbnail.jpg +0 -0
  4. data/app/assets/javascripts/spotlight/application.js +6 -1
  5. data/app/assets/javascripts/spotlight/blocks/pages_block.js +1 -1
  6. data/app/assets/javascripts/spotlight/blocks/resources_block.js +7 -4
  7. data/app/assets/javascripts/spotlight/blocks/solr_documents_base_block.js +108 -0
  8. data/app/assets/javascripts/spotlight/blocks/solr_documents_block.js +12 -56
  9. data/app/assets/javascripts/spotlight/blocks/solr_documents_carousel_block.js +3 -3
  10. data/app/assets/javascripts/spotlight/blocks/solr_documents_embed_block.js +3 -3
  11. data/app/assets/javascripts/spotlight/blocks/solr_documents_features_block.js +3 -3
  12. data/app/assets/javascripts/spotlight/blocks/solr_documents_grid_block.js +3 -3
  13. data/app/assets/javascripts/spotlight/crop.es6 +205 -0
  14. data/app/assets/javascripts/spotlight/croppable.js +7 -104
  15. data/app/assets/javascripts/spotlight/iiif.es6 +54 -0
  16. data/app/assets/javascripts/spotlight/multi_image_selector.js +34 -16
  17. data/app/assets/javascripts/spotlight/pages.js.erb +1 -1
  18. data/app/assets/javascripts/spotlight/reindex_monitor.js +5 -1
  19. data/app/assets/javascripts/spotlight/search_typeahead.js +33 -47
  20. data/app/assets/javascripts/spotlight/sir-trevor/locales.js +5 -2
  21. data/app/assets/javascripts/spotlight/zpr_links.js.erb +30 -0
  22. data/app/assets/stylesheets/spotlight/_croppable.scss +8 -13
  23. data/app/assets/stylesheets/spotlight/_multi_image_selector.scss +1 -1
  24. data/app/assets/stylesheets/spotlight/_pages.scss +5 -0
  25. data/app/assets/stylesheets/spotlight/typeahead.css +0 -1
  26. data/app/controllers/concerns/spotlight/base.rb +3 -5
  27. data/app/controllers/spotlight/appearances_controller.rb +6 -4
  28. data/app/controllers/spotlight/catalog_controller.rb +10 -0
  29. data/app/controllers/spotlight/contacts_controller.rb +2 -6
  30. data/app/controllers/spotlight/featured_images_controller.rb +26 -0
  31. data/app/controllers/spotlight/pages_controller.rb +3 -2
  32. data/app/controllers/spotlight/resources/iiif_harvester_controller.rb +10 -0
  33. data/app/controllers/spotlight/resources/upload_controller.rb +4 -3
  34. data/app/controllers/spotlight/searches_controller.rb +20 -6
  35. data/app/controllers/spotlight/sites_controller.rb +2 -5
  36. data/app/helpers/spotlight/application_helper.rb +14 -1
  37. data/app/helpers/spotlight/crop_helper.rb +37 -0
  38. data/app/helpers/spotlight/main_app_helpers.rb +13 -0
  39. data/app/helpers/spotlight/meta_helper.rb +10 -20
  40. data/app/models/concerns/spotlight/solr_document.rb +1 -2
  41. data/app/models/concerns/spotlight/solr_document/uploaded_resource.rb +1 -23
  42. data/app/models/sir_trevor_rails/blocks/browse_block.rb +10 -0
  43. data/app/models/sir_trevor_rails/blocks/featured_pages_block.rb +10 -0
  44. data/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +5 -0
  45. data/app/models/spotlight/analytics/ga.rb +1 -1
  46. data/app/models/spotlight/blacklight_configuration.rb +16 -8
  47. data/app/models/spotlight/contact.rb +2 -13
  48. data/app/models/spotlight/contact_image.rb +11 -0
  49. data/app/models/spotlight/exhibit.rb +11 -8
  50. data/app/models/spotlight/exhibit_thumbnail.rb +12 -0
  51. data/app/models/spotlight/feature_page.rb +3 -5
  52. data/app/models/spotlight/featured_image.rb +28 -9
  53. data/app/models/spotlight/home_page.rb +2 -0
  54. data/app/models/spotlight/masthead.rb +5 -11
  55. data/app/models/spotlight/page.rb +5 -0
  56. data/app/models/spotlight/reindex_progress.rb +10 -18
  57. data/app/models/spotlight/reindexing_log_entry.rb +1 -0
  58. data/app/models/spotlight/resources/iiif_harvester.rb +33 -0
  59. data/app/models/spotlight/resources/iiif_manifest.rb +211 -0
  60. data/app/models/spotlight/resources/iiif_service.rb +93 -0
  61. data/app/models/spotlight/resources/upload.rb +1 -2
  62. data/app/models/spotlight/search.rb +5 -34
  63. data/app/presenters/spotlight/iiif_manifest_presenter.rb +79 -0
  64. data/app/serializers/spotlight/exhibit_export_serializer.rb +9 -41
  65. data/app/services/spotlight/carrierwave_file_resolver.rb +3 -1
  66. data/app/services/spotlight/iiif_resource_resolver.rb +73 -0
  67. data/app/services/spotlight/resources/iiif_builder.rb +17 -0
  68. data/app/services/spotlight/upload_solr_document_builder.rb +23 -23
  69. data/app/uploaders/spotlight/attachment_uploader.rb +0 -48
  70. data/app/uploaders/spotlight/featured_image_uploader.rb +2 -16
  71. data/app/views/_user_util_links.html.erb +8 -5
  72. data/app/views/catalog/_save_search.html.erb +4 -2
  73. data/app/views/layouts/spotlight/spotlight.html.erb +5 -1
  74. data/app/views/shared/_masthead.html.erb +1 -1
  75. data/app/views/spotlight/about_pages/_contact_properties.html.erb +1 -1
  76. data/app/views/spotlight/appearances/edit.html.erb +26 -6
  77. data/app/views/spotlight/browse/_search.html.erb +1 -1
  78. data/app/views/spotlight/contacts/_form.html.erb +12 -7
  79. data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +1 -1
  80. data/app/views/spotlight/exhibits/_exhibit_card_front.html.erb +2 -2
  81. data/app/views/spotlight/featured_images/_form.html.erb +12 -15
  82. data/app/views/spotlight/featured_images/_upload_form.html.erb +6 -12
  83. data/app/views/spotlight/metadata_configurations/_metadata_field.html.erb +3 -3
  84. data/app/views/spotlight/pages/_form.html.erb +3 -3
  85. data/app/views/spotlight/pages/edit.html.erb +4 -2
  86. data/app/views/spotlight/resources/iiif/_form.html.erb +9 -0
  87. data/app/views/spotlight/searches/_form.html.erb +3 -3
  88. data/app/views/spotlight/searches/_search.html.erb +4 -2
  89. data/app/views/spotlight/sir_trevor/blocks/_browse_block.html.erb +2 -2
  90. data/app/views/spotlight/sir_trevor/blocks/_featured_pages_block.html.erb +1 -1
  91. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +7 -2
  92. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +4 -2
  93. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb +4 -2
  94. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb +4 -2
  95. data/app/views/spotlight/sites/edit.html.erb +1 -1
  96. data/config/locales/spotlight.en.yml +31 -6
  97. data/config/routes.rb +9 -0
  98. data/db/migrate/20160714144125_add_iiif_urls_to_featured_image.rb +9 -0
  99. data/db/migrate/20160718194010_add_iiif_url_to_contact.rb +6 -0
  100. data/db/migrate/20160805143841_add_upload_id_to_resources.rb +6 -0
  101. data/db/migrate/20170204091234_add_theme_to_spotlight_exhibits.rb +5 -0
  102. data/lib/generators/spotlight/install_generator.rb +5 -2
  103. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +0 -1
  104. data/lib/generators/spotlight/templates/spotlight.scss +3 -2
  105. data/lib/migration/iiif.rb +82 -0
  106. data/lib/spotlight/engine.rb +22 -10
  107. data/lib/spotlight/version.rb +1 -1
  108. data/lib/tasks/spotlight_tasks.rake +10 -0
  109. data/spec/controllers/spotlight/about_pages_controller_spec.rb +1 -1
  110. data/spec/controllers/spotlight/appearances_controller_spec.rb +31 -18
  111. data/spec/controllers/spotlight/catalog_controller_spec.rb +40 -0
  112. data/spec/controllers/spotlight/contacts_controller_spec.rb +20 -1
  113. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +2 -6
  114. data/spec/controllers/spotlight/featured_images_controller_spec.rb +74 -0
  115. data/spec/controllers/spotlight/home_pages_controller_spec.rb +1 -1
  116. data/spec/controllers/spotlight/searches_controller_spec.rb +3 -1
  117. data/spec/controllers/spotlight/sites_controller_spec.rb +6 -1
  118. data/spec/examples.txt +1118 -1059
  119. data/spec/factories/contact_images.rb +6 -0
  120. data/spec/factories/contacts.rb +4 -1
  121. data/spec/factories/exhibit_thumbnails.rb +6 -0
  122. data/spec/factories/exhibits.rb +4 -0
  123. data/spec/factories/featured_images.rb +1 -0
  124. data/spec/factories/resources.rb +2 -1
  125. data/spec/features/add_contacts_spec.rb +5 -5
  126. data/spec/features/add_iiif_manifest_spec.rb +41 -0
  127. data/spec/features/add_items_spec.rb +2 -2
  128. data/spec/features/autocomplete_typeahead_spec.rb +86 -0
  129. data/spec/features/browse_category_admin_spec.rb +27 -6
  130. data/spec/features/browse_category_spec.rb +2 -2
  131. data/spec/features/create_exhibit_spec.rb +3 -3
  132. data/spec/features/exhibit_masthead_spec.rb +20 -9
  133. data/spec/features/exhibit_themes_spec.rb +25 -0
  134. data/spec/features/home_page_spec.rb +1 -1
  135. data/spec/features/javascript/blocks/solr_documents_block_spec.rb +42 -0
  136. data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +5 -3
  137. data/spec/features/javascript/feature_page_admin_spec.rb +1 -1
  138. data/spec/features/javascript/multi_image_select_spec.rb +5 -6
  139. data/spec/features/javascript/search_config_admin_spec.rb +1 -1
  140. data/spec/features/site_masthead_spec.rb +14 -4
  141. data/spec/fixtures/gk446cj2442-manifest.json +58 -0
  142. data/spec/fixtures/iiif_responses.rb +274 -0
  143. data/spec/fixtures/sample_solr_documents.yml +106 -0
  144. data/spec/helpers/spotlight/crop_helper_spec.rb +9 -0
  145. data/spec/helpers/spotlight/main_app_helpers_spec.rb +45 -0
  146. data/spec/helpers/spotlight/meta_helper_spec.rb +2 -15
  147. data/spec/lib/migration/iiif_spec.rb +70 -0
  148. data/spec/models/spotlight/blacklight_configuration_spec.rb +17 -5
  149. data/spec/models/spotlight/contact_image_spec.rb +9 -0
  150. data/spec/models/spotlight/exhibit_spec.rb +17 -20
  151. data/spec/models/spotlight/exhibit_thumbnail_spec.rb +8 -0
  152. data/spec/models/spotlight/featured_image_spec.rb +59 -10
  153. data/spec/models/spotlight/masthead_spec.rb +33 -17
  154. data/spec/models/spotlight/page_spec.rb +14 -0
  155. data/spec/models/spotlight/reindex_progress_spec.rb +22 -73
  156. data/spec/models/spotlight/resources/iiif_harvester_spec.rb +30 -0
  157. data/spec/models/spotlight/resources/iiif_manifest_spec.rb +107 -0
  158. data/spec/models/spotlight/resources/iiif_service_spec.rb +52 -0
  159. data/spec/models/spotlight/resources/upload_spec.rb +7 -3
  160. data/spec/models/spotlight/search_spec.rb +0 -45
  161. data/spec/models/spotlight/solr_document/uploaded_resource_spec.rb +11 -29
  162. data/spec/presenters/spotlight/iiif_manifest_presenter_spec.rb +123 -0
  163. data/spec/routing/spotlight/exhibit_catalog_spec.rb +4 -0
  164. data/spec/routing/spotlight/featured_images_spec.rb +21 -0
  165. data/spec/serializers/spotlight/exhibit_export_serializer_spec.rb +15 -18
  166. data/spec/services/spotlight/iiif_resource_resolver_spec.rb +90 -0
  167. data/spec/spec_helper.rb +3 -0
  168. data/spec/support/features/test_features_helpers.rb +3 -2
  169. data/spec/support/stub_iiif_response.rb +24 -0
  170. data/spec/support/views/test_view_helpers.rb +1 -0
  171. data/spec/test_app_templates/Gemfile.extra +0 -1
  172. data/spec/uploaders/spotlight/attachment_uploader_spec.rb +24 -0
  173. data/spec/uploaders/spotlight/featured_image_uploader_spec.rb +30 -0
  174. data/spec/views/_user_util_links.html.erb_spec.rb +9 -5
  175. data/spec/views/shared/_masthead.html.erb_spec.rb +5 -2
  176. data/spec/views/spotlight/browse/_search.html.erb_spec.rb +2 -2
  177. data/spec/views/spotlight/contacts/edit.html.erb_spec.rb +4 -7
  178. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +7 -2
  179. data/spec/views/spotlight/pages/edit.html.erb_spec.rb +3 -1
  180. data/spec/views/spotlight/pages/new.html.erb_spec.rb +3 -1
  181. data/spec/views/spotlight/searches/_search.html.erb_spec.rb +3 -2
  182. data/spec/views/spotlight/searches/edit.html.erb_spec.rb +3 -2
  183. data/vendor/assets/javascripts/leaflet-areaselect.js +184 -0
  184. data/vendor/assets/javascripts/leaflet-iiif.js +230 -0
  185. data/vendor/assets/javascripts/leaflet.js +9 -0
  186. data/vendor/assets/javascripts/polyfill.min.js +4 -0
  187. data/vendor/assets/stylesheets/leaflet-areaselect.css +15 -0
  188. data/vendor/assets/stylesheets/leaflet.css +624 -0
  189. metadata +136 -62
  190. data/app/assets/javascripts/spotlight/jcrop.js +0 -1696
  191. data/app/helpers/spotlight/jcrop_helper.rb +0 -37
  192. data/app/models/concerns/spotlight/default_thumbnailable.rb +0 -25
  193. data/app/models/concerns/spotlight/image_derivatives.rb +0 -58
  194. data/app/models/concerns/spotlight/solr_document/spotlight_images.rb +0 -55
  195. data/app/uploaders/spotlight/avatar_uploader.rb +0 -24
  196. data/app/uploaders/spotlight/item_uploader.rb +0 -25
  197. data/app/uploaders/spotlight/masthead_uploader.rb +0 -22
  198. data/spec/helpers/spotlight/jcrop_helper_spec.rb +0 -33
  199. data/spec/models/spotlight/default_thumbnailable_concern_spec.rb +0 -16
  200. data/spec/models/spotlight/image_derivatives_spec.rb +0 -15
  201. data/spec/models/spotlight/solr_document/spotlight_images_spec.rb +0 -42
  202. data/spec/uploaders/spotlight/item_uploader_spec.rb +0 -67
@@ -40,4 +40,49 @@ describe Spotlight::MainAppHelpers, type: :helper do
40
40
  its(:show_contact_form?) { should be_truthy }
41
41
  end
42
42
  end
43
+
44
+ describe '#exhibit_stylesheet_link_tag' do
45
+ let(:exhibit) { FactoryGirl.create(:exhibit) }
46
+ before do
47
+ allow(helper).to receive_messages(current_exhibit: exhibit)
48
+ end
49
+
50
+ context 'without an exhibit context' do
51
+ let(:exhibit) { nil }
52
+ it 'uses the standard stylesheet' do
53
+ expect(helper.exhibit_stylesheet_link_tag('application')).to eq helper.stylesheet_link_tag('application')
54
+ end
55
+ end
56
+
57
+ context 'for an exhibit without a selected theme' do
58
+ before do
59
+ exhibit.update(theme: nil)
60
+ end
61
+
62
+ it 'uses the standard stylesheet' do
63
+ expect(helper.exhibit_stylesheet_link_tag('application')).to eq helper.stylesheet_link_tag('application')
64
+ end
65
+ end
66
+
67
+ context 'for an exhibit with an invalid theme' do
68
+ before do
69
+ exhibit.update(theme: 'garbage')
70
+ end
71
+
72
+ it 'uses the standard stylesheet' do
73
+ expect(helper.exhibit_stylesheet_link_tag('application')).to eq helper.stylesheet_link_tag('application')
74
+ end
75
+ end
76
+
77
+ context 'for a themed exhibit' do
78
+ before do
79
+ allow(Spotlight::Engine.config).to receive(:exhibit_themes).and_return(%w(default modern))
80
+ exhibit.update(theme: 'modern')
81
+ end
82
+
83
+ it 'uses a suffixed stylesheet name' do
84
+ expect(helper.exhibit_stylesheet_link_tag('application')).to eq helper.stylesheet_link_tag('application_modern')
85
+ end
86
+ end
87
+ end
43
88
  end
@@ -12,8 +12,7 @@ describe Spotlight::MetaHelper, type: :helper do
12
12
 
13
13
  it 'generates a twitter card for the exhibit' do
14
14
  allow(helper).to receive(:exhibit_root_url).and_return('some/url')
15
- allow(current_exhibit).to receive(:thumbnail).and_return(double)
16
- allow(current_exhibit).to receive_message_chain(:thumbnail, :image, :thumb, url: '/image')
15
+ allow(current_exhibit).to receive(:thumbnail).and_return(double(iiif_url: 'https://test.host/images/7777/full/400,300/0/default.jpg'))
17
16
 
18
17
  helper.add_exhibit_meta_content
19
18
 
@@ -22,22 +21,10 @@ describe Spotlight::MetaHelper, type: :helper do
22
21
  expect(card).to have_css "meta[name='twitter:url'][value='some/url']", visible: false
23
22
  expect(card).to have_css "meta[name='twitter:title'][value='#{current_exhibit.title}']", visible: false
24
23
  expect(card).to have_css "meta[name='twitter:description'][value='#{current_exhibit.subtitle}']", visible: false
25
- expect(card).to have_css "meta[name='twitter:image'][value='http://test.host/image']", visible: false
24
+ expect(card).to have_css "meta[name='twitter:image'][value='https://test.host/images/7777/full/400,300/0/default.jpg']", visible: false
26
25
 
27
26
  graph = helper.opengraph
28
27
  expect(graph).to have_css "meta[property='og:site_name'][content='some title']", visible: false
29
28
  end
30
29
  end
31
-
32
- describe '#carrierwave_url' do
33
- it 'turns a application-relative URI into a path' do
34
- upload = double(url: '/x/y/z')
35
- expect(helper.send(:carrierwave_url, upload)).to eq 'http://test.host/x/y/z'
36
- end
37
-
38
- it 'passes a full URI through' do
39
- upload = double(url: 'http://some.host/x/y/z')
40
- expect(helper.send(:carrierwave_url, upload)).to eq 'http://some.host/x/y/z'
41
- end
42
- end
43
30
  end
@@ -0,0 +1,70 @@
1
+ require 'migration/iiif'
2
+
3
+ RSpec.describe Migration::IIIF do
4
+ let(:instance) { described_class.new('http://test.host') }
5
+
6
+ before do
7
+ expect(File).to receive(:new).and_return(double)
8
+ end
9
+
10
+ context '#migrate_featured_images' do
11
+ let!(:old_exhibit_thumbnail) { FactoryGirl.create(:featured_image, type: nil, iiif_tilesource: nil) }
12
+ let!(:exhibit) { FactoryGirl.create(:exhibit, thumbnail_id: old_exhibit_thumbnail.id) }
13
+ let(:updated_thumb) { Spotlight::FeaturedImage.find(old_exhibit_thumbnail.id) }
14
+
15
+ context "when it's an exhibit thumbnail" do
16
+ it 'migrates to an ExhibitThumbnail class and stores the image in the correct directory' do
17
+ instance.run
18
+ expect(updated_thumb.class).to eq Spotlight::ExhibitThumbnail
19
+ expect(Spotlight::Exhibit.find(exhibit.id).thumbnail).to eq updated_thumb
20
+ end
21
+
22
+ it 'stores the image in the correct directory for the ExhibitThumbnail class' do
23
+ instance.run
24
+ expect(updated_thumb.image.file.file).to match(%r{/spotlight/exhibit_thumbnail/image/#{old_exhibit_thumbnail.id}})
25
+ end
26
+ end
27
+
28
+ context "when it's any FeaturedImage" do
29
+ it 'updates the iiif_tilesource attribute based on the given host and image resource' do
30
+ instance.run
31
+ expect(updated_thumb.iiif_tilesource).to eq "http://test.host/images/#{updated_thumb.id}/info.json"
32
+ end
33
+
34
+ it 'returns a nil region if one was not set' do
35
+ instance.run
36
+ expect(updated_thumb.iiif_region).to be_nil
37
+ end
38
+
39
+ it 'updates the iiif_region attribute based on the legacy crop coordinates' do
40
+ old_exhibit_thumbnail.image_crop_x = '1'
41
+ old_exhibit_thumbnail.image_crop_y = '1'
42
+ old_exhibit_thumbnail.image_crop_w = '400'
43
+ old_exhibit_thumbnail.image_crop_h = '400'
44
+ old_exhibit_thumbnail.save
45
+
46
+ instance.run
47
+ expect(updated_thumb.iiif_region).to eq '1,1,400,400'
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#migrate_contact_avatars' do
53
+ let(:file) { double }
54
+ let(:contact1) { Spotlight::Contact.create }
55
+ let(:contact2) { Spotlight::Contact.create }
56
+ before do
57
+ allow(File).to receive(:new).and_return(file)
58
+ allow(contact1).to receive('read_attribute_before_type_cast').and_call_original
59
+ allow(contact2).to receive('read_attribute_before_type_cast').and_call_original
60
+ allow(contact1).to receive('read_attribute_before_type_cast').with('avatar').and_return('file1.jpg')
61
+ allow(contact2).to receive('read_attribute_before_type_cast').with('avatar').and_return('file2.jpg')
62
+ end
63
+ it 'migrates' do
64
+ expect do
65
+ instance.send :migrate_contact_avatars
66
+ end.to change { Spotlight::FeaturedImage.count }.by(2)
67
+ expect(Spotlight::Contact.all.pluck(:avatar_id)).to eq Spotlight::FeaturedImage.all.pluck(:id)
68
+ end
69
+ end
70
+ end
@@ -89,9 +89,16 @@ describe Spotlight::BlacklightConfiguration, type: :model do
89
89
  end
90
90
 
91
91
  it 'defaults to not showing a custom field in the facets' do
92
- allow(subject).to receive_messages(custom_facet_fields: { 'a' => Blacklight::Configuration::IndexField.new(field: 'a') })
92
+ field = double('field', field: 'a', solr_field: 'a', configuration: {})
93
+ custom_fields = double('custom_fields', vocab: [field])
94
+ allow(custom_fields).to receive(:map) do |&block|
95
+ block.call(field)
96
+ end
97
+ allow(subject.exhibit).to receive(:custom_fields).and_return(custom_fields)
93
98
  expect(subject.blacklight_config.facet_fields).to include('a')
94
99
  expect(subject.blacklight_config.facet_fields['a'].show).to be_falsey
100
+ expect(subject.blacklight_config.facet_fields['a'].if).to eq :field_enabled?
101
+ expect(subject.blacklight_config.facet_fields['a'].enabled).to eq false
95
102
  end
96
103
  end
97
104
 
@@ -176,10 +183,17 @@ describe Spotlight::BlacklightConfiguration, type: :model do
176
183
  expect(subject.blacklight_config.index_fields['a'].list).to be_truthy
177
184
  end
178
185
 
186
+ it 'applies immutable values from the configuration' do
187
+ blacklight_config.add_index_field 'a', immutable: { something: 'set_in_configuration', another: 'immutable' }
188
+ subject.index_fields['a'] = { something: 'set_in_db' }
189
+ expect(subject.blacklight_config.index_fields['a'].something).to eq 'set_in_configuration'
190
+ expect(subject.blacklight_config.index_fields['a'].another).to eq 'immutable'
191
+ end
192
+
179
193
  context 'custom fields' do
180
194
  it 'includes any custom fields' do
181
195
  subject.index_fields['a'] = { enabled: true, list: true }
182
- allow(subject).to receive_messages(custom_index_fields: { 'a' => double(if: nil, :if= => true, merge!: true, validate!: true, normalize!: true) })
196
+ allow(subject).to receive_messages(custom_index_fields: { 'a' => Blacklight::Configuration::IndexField.new(field: 'a') })
183
197
  expect(subject.blacklight_config.index_fields).to include('a')
184
198
  end
185
199
 
@@ -242,7 +256,7 @@ describe Spotlight::BlacklightConfiguration, type: :model do
242
256
  it 'includes any custom fields' do
243
257
  subject.index_fields['a'] = { enabled: true, show: true }
244
258
 
245
- allow(subject).to receive_messages(custom_index_fields: { 'a' => double(if: nil, :if= => true, merge!: true, validate!: true, normalize!: true) })
259
+ allow(subject).to receive_messages(custom_index_fields: { 'a' => Blacklight::Configuration::IndexField.new(field: 'a') })
246
260
 
247
261
  expect(subject.blacklight_config.show_fields).to include('a')
248
262
  end
@@ -511,9 +525,7 @@ describe Spotlight::BlacklightConfiguration, type: :model do
511
525
  expect(search_field.solr_parameters).to have_key :fl
512
526
  expect(search_field.solr_parameters[:fl]).to include 'id'
513
527
  expect(search_field.solr_parameters[:fl]).to include 'some_field'
514
- expect(search_field.solr_parameters[:fl]).to include 'full_image_url_ssm'
515
528
  expect(search_field.solr_parameters[:fl]).to include 'thumbnail_url_ssm'
516
- expect(search_field.solr_parameters[:fl]).to include 'thumbnail_square_url_ssm'
517
529
  end
518
530
  end
519
531
  end
@@ -0,0 +1,9 @@
1
+ describe Spotlight::ContactImage do
2
+ subject(:contact_image) do
3
+ described_class.new(iiif_tilesource: 'http://example.com/iiif/abc123/info.json')
4
+ end
5
+
6
+ it 'has the appropriate contact image size' do
7
+ expect(contact_image.iiif_url).to match(%r{/full/70,70/})
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  describe Spotlight::Exhibit, type: :model do
2
- subject { FactoryGirl.build(:exhibit, title: 'Sample') }
2
+ subject(:exhibit) { FactoryGirl.build(:exhibit, title: 'Sample') }
3
3
 
4
4
  it 'has a title' do
5
5
  subject.title = 'Test title'
@@ -45,23 +45,6 @@ describe Spotlight::Exhibit, type: :model do
45
45
  end
46
46
  end
47
47
 
48
- context 'thumbnail' do
49
- it 'calls DefaultThumbnailJob to fetch a default feature image' do
50
- expect(Spotlight::DefaultThumbnailJob).to receive(:perform_later).with(subject.searches.first)
51
- expect(Spotlight::DefaultThumbnailJob).to receive(:perform_later).with(subject)
52
- subject.save!
53
- end
54
-
55
- context '#set_default_thumbnail' do
56
- before { subject.save! }
57
- it 'uses the thubmnail from the first search' do
58
- subject.set_default_thumbnail
59
- expect(subject.thumbnail).not_to be_nil
60
- expect(subject.thumbnail).to eq subject.searches.first.thumbnail
61
- end
62
- end
63
- end
64
-
65
48
  describe '#main_navigations' do
66
49
  subject { FactoryGirl.create(:exhibit, title: 'Sample') }
67
50
  it 'has main navigations' do
@@ -302,10 +285,24 @@ describe Spotlight::Exhibit, type: :model do
302
285
  end
303
286
 
304
287
  describe '#reindex_progress' do
305
- it 'returns a Spotlight::ReindexProgress' do
288
+ let!(:reindexing_log_entries) do
289
+ [
290
+ FactoryGirl.create(:unstarted_reindexing_log_entry, exhibit: exhibit),
291
+ FactoryGirl.create(:reindexing_log_entry, exhibit: exhibit),
292
+ in_progress_entry,
293
+ FactoryGirl.create(:failed_reindexing_log_entry, exhibit: exhibit),
294
+ FactoryGirl.create(:unstarted_reindexing_log_entry, exhibit: exhibit)
295
+ ]
296
+ end
297
+
298
+ let(:in_progress_entry) do
299
+ FactoryGirl.create(:in_progress_reindexing_log_entry, exhibit: exhibit)
300
+ end
301
+
302
+ it 'returns the latest log entry that is not unstarted' do
306
303
  reindex_progress = subject.reindex_progress
307
304
  expect(reindex_progress).to be_a Spotlight::ReindexProgress
308
- expect(reindex_progress.exhibit).to eq subject
305
+ expect(reindex_progress.current_log_entry).to eq in_progress_entry
309
306
  end
310
307
  end
311
308
  end
@@ -0,0 +1,8 @@
1
+ describe Spotlight::ExhibitThumbnail do
2
+ subject(:exhibit_thumbnail) { described_class.new }
3
+
4
+ it 'includes the appropriate size in the iiif_url' do
5
+ exhibit_thumbnail.iiif_tilesource = 'http://example.com/iiif/abc123/info.json'
6
+ expect(exhibit_thumbnail.iiif_url).to match(%r{/full/400,400/})
7
+ end
8
+ end
@@ -1,18 +1,67 @@
1
1
  describe Spotlight::FeaturedImage do
2
- context 'with an uploaded resource' do
3
- subject { described_class.new }
4
- let(:document) { double(uploaded_resource?: true) }
2
+ subject(:featured_image) { described_class.new }
5
3
 
6
- it 'replaces the remote_image_url fragment with the local path to the file' do
7
- allow(document).to receive_message_chain(:uploaded_resource, :url, file: File.open(File.join(FIXTURES_PATH, 'avatar.png')))
8
- allow(subject).to receive(:document).and_return(document)
4
+ describe '#iiif_url' do
5
+ let(:iiif_tilesource) { 'http://example.com/iiif/abc123/info.json' }
6
+ let(:iiif_region) { '0,0,400,300' }
9
7
 
10
- subject.remote_image_url = '/some/path'
11
- expect(subject.remote_image_url).to be_nil
8
+ describe 'tilesource' do
9
+ it 'is nil when not present' do
10
+ expect(subject.iiif_url).to be_nil
11
+ end
12
12
 
13
- subject.validate
13
+ it 'is included when present (without "/info.json")' do
14
+ subject.iiif_tilesource = iiif_tilesource
15
+ expect(subject.iiif_url).to match(%r{^http://example.com/iiif/abc123/})
16
+ expect(subject.iiif_url).not_to include('info.json')
17
+ end
18
+ end
19
+
20
+ describe 'region' do
21
+ before { subject.iiif_tilesource = iiif_tilesource }
22
+ it 'is included when present' do
23
+ subject.iiif_region = iiif_region
24
+ expect(subject.iiif_url).to match(%r{/abc123/#{iiif_region}/})
25
+ end
26
+
27
+ it 'is "full" when not present' do
28
+ expect(subject.iiif_url).to match(%r{/abc123/full/})
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '#document' do
34
+ before { subject.source = 'exhibit' }
35
+ it 'fetches the document given the stored GlobalID' do
36
+ subject.document_global_id = 'gid://internal/SolrDocument/yn959jw9550'
37
+
38
+ expect(subject.document).to be_a SolrDocument
39
+ expect(subject.document[:id]).to eq 'yn959jw9550'
40
+ end
41
+
42
+ it 'busts memoization if the GlobalID is updated' do
43
+ subject.document_global_id = 'gid://internal/SolrDocument/yn959jw9550'
44
+ expect(subject.document[:id]).to eq 'yn959jw9550'
45
+
46
+ subject.document_global_id = 'gid://internal/SolrDocument/gk446cj2442'
47
+ expect(subject.document[:id]).to eq 'gk446cj2442'
48
+ end
49
+
50
+ it 'returns nil if the document cannot be found via GlobalID' do
51
+ subject.document_global_id = 'gid://internal/SolrDocument/NotARealDoc'
52
+
53
+ expect(subject.document).to be_nil
54
+ end
55
+ end
56
+
57
+ describe '#file_present?' do
58
+ it 'is false when the image file is not present' do
59
+ expect(subject.file_present?).to be false
60
+ end
14
61
 
15
- expect(subject.image.filename).to eq 'avatar.png'
62
+ it 'is true when the image file is present' do
63
+ expect(subject).to receive(:image).and_return(double('CarrierWaveUpload', file: 'uploaded file content'))
64
+ expect(subject.file_present?).to be true
16
65
  end
17
66
  end
18
67
  end
@@ -1,24 +1,40 @@
1
1
  describe Spotlight::Masthead, type: :model do
2
- describe '#masthead_exists?' do
3
- let(:masthead) { stub_model(described_class) }
4
- let(:image) { OpenStruct.new }
5
- it 'returns false when the masthead is set to not display' do
6
- expect(masthead.display?).to be_falsey
2
+ let(:masthead) { stub_model(described_class) }
3
+
4
+ describe '#iiif_url' do
5
+ it 'inlcudes the appropriate size' do
6
+ masthead.iiif_tilesource = 'http://example.com/iiif/abc123/info.json'
7
+ expect(masthead.iiif_url).to match(%r{/full/1800,180/})
7
8
  end
8
- it 'returns false when the cropped image is not present' do
9
- masthead.display = true
10
- expect(masthead.display?).to be_falsey
9
+ end
10
+
11
+ describe '#display?' do
12
+ let(:image) { OpenStruct.new }
13
+ subject { masthead.display? }
14
+
15
+ context 'when the masthead is set to not display' do
16
+ it { is_expected.to be_falsey }
11
17
  end
12
- it 'returns false when the cropped image is present but the masthead is set to not display' do
13
- allow(masthead).to receive(:image).and_return(image)
14
- allow(image).to receive(:cropped).and_return([0])
15
- expect(masthead.display?).to be_falsey
18
+
19
+ context 'when the cropped image is not present' do
20
+ before { masthead.display = true }
21
+ it { is_expected.to be_falsey }
16
22
  end
17
- it 'returns true when the cropped image is present and the masthead is set to display' do
18
- masthead.display = true
19
- expect(masthead).to receive(:image).and_return(image)
20
- expect(image).to receive(:cropped).and_return([0])
21
- expect(masthead.display?).to be_truthy
23
+
24
+ context 'when the cropped image is present' do
25
+ before do
26
+ masthead.iiif_tilesource = 'http://test.host/images/1'
27
+ masthead.iiif_region = '100,0,200,300'
28
+ end
29
+
30
+ context 'but the masthead is set to not display' do
31
+ it { is_expected.to be_falsey }
32
+ end
33
+
34
+ context 'and the masthead is set to display' do
35
+ before { masthead.display = true }
36
+ it { is_expected.to be_truthy }
37
+ end
22
38
  end
23
39
  end
24
40
  end
@@ -93,4 +93,18 @@ describe Spotlight::Page, type: :model do
93
93
  end
94
94
  end
95
95
  end
96
+
97
+ describe 'thumbnail_image_url' do
98
+ subject(:thumbnail) { FactoryGirl.create(:featured_image) }
99
+ subject(:page) { FactoryGirl.create(:feature_page, exhibit: exhibit) }
100
+
101
+ it 'is nil when there is no thumbnail' do
102
+ expect(page.thumbnail_image_url).to be_nil
103
+ end
104
+
105
+ it "is returns the thumbnail's IIIF url" do
106
+ page.thumbnail = thumbnail
107
+ expect(page.thumbnail_image_url).to eq thumbnail.iiif_url
108
+ end
109
+ end
96
110
  end