diff --git a/app/models/indexed_file.rb b/app/models/indexed_file.rb index 11d331a337..ac432b7993 100644 --- a/app/models/indexed_file.rb +++ b/app/models/indexed_file.rb @@ -1,11 +1,11 @@ # Copyright 2011-2023, The Trustees of Indiana University and Northwestern # University. Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. -# +# # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software distributed # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, either express or implied. See the License for the diff --git a/app/presenters/speedy_af/proxy/indexed_file.rb b/app/presenters/speedy_af/proxy/indexed_file.rb index 6e26220b36..04ca163d4b 100644 --- a/app/presenters/speedy_af/proxy/indexed_file.rb +++ b/app/presenters/speedy_af/proxy/indexed_file.rb @@ -1,11 +1,11 @@ # Copyright 2011-2023, The Trustees of Indiana University and Northwestern # University. Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. -# +# # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software distributed # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, either express or implied. See the License for the @@ -23,6 +23,10 @@ def content binary_content? ? Base64.decode64(attrs[:content]) : attrs[:content] end + def persisted? + id.present? + end + def has_content? attrs[:content].present? end diff --git a/config/initializers/presenter_config.rb b/config/initializers/presenter_config.rb index 292782c712..d319e16be6 100644 --- a/config/initializers/presenter_config.rb +++ b/config/initializers/presenter_config.rb @@ -14,7 +14,8 @@ file_size: nil, date_digitized: nil, file_checksum: nil, - supplemental_file_captions: [] + supplemental_file_captions: [], + identifier: [] } include MasterFileIntercom include MasterFileBehavior diff --git a/spec/controllers/media_objects_controller_spec.rb b/spec/controllers/media_objects_controller_spec.rb index 83cf7a7aff..aaab3b9177 100644 --- a/spec/controllers/media_objects_controller_spec.rb +++ b/spec/controllers/media_objects_controller_spec.rb @@ -1249,6 +1249,28 @@ get 'show', params: { id: media_object.id, format:'json' } expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made end + + context 'MO with identifier-less master file' do + let!(:media_object) { FactoryBot.create(:published_media_object, visibility: 'public') } + let!(:master_file) { FactoryBot.create(:master_file, :with_derivative, media_object: media_object, identifier: nil) } + it 'should not read from fedora' do + perform_enqueued_jobs(only: MediaObjectIndexingJob) + WebMock.reset_executed_requests! + get 'show', params: { id: media_object.id, format: 'json' } + expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made + end + end + + context 'MO with master file containing IndexedFiles' do + let!(:media_object) { FactoryBot.create(:published_media_object, visibility: 'public') } + let!(:master_file) { FactoryBot.create(:master_file, :with_derivative, :with_thumbnail, :with_poster, :with_waveform, :with_captions, media_object: media_object, identifier: nil) } + it 'should not read from fedora' do + perform_enqueued_jobs(only: MediaObjectIndexingJob) + WebMock.reset_executed_requests! + get 'show', params: { id: media_object.id, format: 'json' } + expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made + end + end end end @@ -1272,6 +1294,28 @@ get 'show', params: { id: media_object.id } expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made end + + context 'media object with identifier-less master file' do + let!(:media_object) { FactoryBot.create(:published_media_object, visibility: 'public') } + let!(:master_file) { FactoryBot.create(:master_file, :with_derivative, media_object: media_object, identifier: nil) } + it 'should not read from fedora' do + perform_enqueued_jobs(only: MediaObjectIndexingJob) + WebMock.reset_executed_requests! + get 'show', params: { id: media_object.id } + expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made + end + end + + context 'media object with master file containing IndexedFiles' do + let!(:media_object) { FactoryBot.create(:published_media_object, visibility: 'public') } + let!(:master_file) { FactoryBot.create(:master_file, :with_derivative, :with_thumbnail, :with_poster, :with_waveform, :with_captions, media_object: media_object, identifier: nil) } + it 'should not read from fedora' do + perform_enqueued_jobs(only: MediaObjectIndexingJob) + WebMock.reset_executed_requests! + get 'show', params: { id: media_object.id } + expect(a_request(:any, /#{ActiveFedora.fedora.base_uri}/)).not_to have_been_made + end + end end end