File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,16 @@ def perform(record)
99 attacher . create_derivatives :thumbnail
1010 record . save
1111 end
12- # If the created record is a thumbnail uploaded by a user,
13- # then the associated resource needs to be reindexed
14- record . thumbnail_upload . resource . update_index if record . thumbnail_upload . present?
12+
13+ if record . thumbnail_upload . present?
14+ # If the created record is a thumbnail uploaded by a user,
15+ # then the associated resource needs to be reindexed
16+ record . thumbnail_upload . resource . update_index
17+ else
18+ # Update WorkVersions' solr docs with thumbnail url when
19+ # thumbnail is auto-generated from a WorkVersion upload
20+ record . work_versions . each ( &:update_index )
21+ end
1522 rescue Shrine ::AttachmentChanged , ActiveRecord ::RecordNotFound
1623 # attachment has changed or record has been deleted, nothing to do
1724 end
Original file line number Diff line number Diff line change 2222 described_class . perform_now ( image_record )
2323 expect ( image_record . file_attacher . url ( :thumbnail ) ) . to include ( 'thumbnails' )
2424 end
25+
26+ it 'reindexes associated work versions when no thumbnail upload is present' do
27+ work_version_one = instance_spy ( WorkVersion )
28+ work_version_two = instance_spy ( WorkVersion )
29+ allow ( pdf_record ) . to receive_messages ( work_versions : [ work_version_one , work_version_two ] , thumbnail_upload : nil )
30+
31+ described_class . perform_now ( pdf_record )
32+
33+ expect ( work_version_one ) . to have_received ( :update_index )
34+ expect ( work_version_two ) . to have_received ( :update_index )
35+ end
36+
37+ it 'reindexes associated thumbnail upload resource when present' do
38+ thumbnail_upload = create ( :thumbnail_upload )
39+ resource = thumbnail_upload . resource
40+ allow ( resource ) . to receive ( :update_index )
41+ allow ( pdf_record ) . to receive_messages ( work_versions : [ ] , thumbnail_upload : thumbnail_upload )
42+
43+ described_class . perform_now ( pdf_record )
44+
45+ expect ( resource ) . to have_received ( :update_index )
46+ end
2547 end
2648end
You can’t perform that action at this time.
0 commit comments