Skip to content

Commit

Permalink
Merge pull request #5362 from avalonmediasystem/still_reifying
Browse files Browse the repository at this point in the history
Prevent reification when loading media object #show
  • Loading branch information
cjcolvar authored Sep 13, 2023
2 parents 37c8209 + 9958b27 commit 87d6daa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/models/indexed_file.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 7 additions & 3 deletions app/presenters/speedy_af/proxy/indexed_file.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/presenter_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
file_size: nil,
date_digitized: nil,
file_checksum: nil,
supplemental_file_captions: []
supplemental_file_captions: [],
identifier: []
}
include MasterFileIntercom
include MasterFileBehavior
Expand Down
44 changes: 44 additions & 0 deletions spec/controllers/media_objects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 87d6daa

Please sign in to comment.