From 603ec94bb8c5b4892f7723a8c371bfbf2b3ef46b Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Wed, 15 Nov 2023 17:05:56 -0500 Subject: [PATCH 1/2] Test all fields are present in SpeedyAF proxy. Remove supplemental_file_captions from MasterFile proxy defaults because it isn't an attribute but derived from supplemental_files_json --- app/models/concerns/master_file_behavior.rb | 4 +++ app/models/master_file.rb | 4 --- config/initializers/presenter_config.rb | 1 - .../speedy_af/proxy/admin/collection_spec.rb | 23 ++++++++++++ .../speedy_af/proxy/derivative_spec.rb | 34 ++++++++++++++---- spec/presenters/speedy_af/proxy/lease_spec.rb | 35 +++++++++++++++++++ .../speedy_af/proxy/master_file_spec.rb | 30 ++++++++++++++++ .../speedy_af/proxy/media_object_spec.rb | 16 +++++++++ 8 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 spec/presenters/speedy_af/proxy/lease_spec.rb diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index c150e91aad..8b546dac9d 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -163,6 +163,10 @@ def build_caption_hash(caption) } end + def supplemental_file_captions + supplemental_files(tag: 'caption') + end + # Supplies the route to the master_file as an rdf formatted URI # @return [String] the route as a uri # @example uri for a mf on avalon.iu.edu with a id of: avalon:1820 diff --git a/app/models/master_file.rb b/app/models/master_file.rb index 876c79cf5b..79d04342d6 100644 --- a/app/models/master_file.rb +++ b/app/models/master_file.rb @@ -470,10 +470,6 @@ def self.post_processing_move_filename(oldpath, options = {}) end end - def supplemental_file_captions - supplemental_files(tag: 'caption') - end - def has_audio? # The MasterFile doesn't have an audio track unless the first derivative does # This is useful to skip unnecessary waveform generation diff --git a/config/initializers/presenter_config.rb b/config/initializers/presenter_config.rb index 698d78dc40..4463f75a0a 100644 --- a/config/initializers/presenter_config.rb +++ b/config/initializers/presenter_config.rb @@ -14,7 +14,6 @@ file_size: nil, date_digitized: nil, file_checksum: nil, - supplemental_file_captions: [], identifier: [] } include MasterFileIntercom diff --git a/spec/presenters/speedy_af/proxy/admin/collection_spec.rb b/spec/presenters/speedy_af/proxy/admin/collection_spec.rb index 4a0c62278c..e86d2f554a 100644 --- a/spec/presenters/speedy_af/proxy/admin/collection_spec.rb +++ b/spec/presenters/speedy_af/proxy/admin/collection_spec.rb @@ -18,6 +18,29 @@ let(:collection) { FactoryBot.create(:collection) } let(:presenter) { described_class.find(collection.id) } + describe 'attributes' do + let(:collection) { FactoryBot.create(:collection, dropbox_directory_name: "dir", identifier: ["1234"], default_lending_period: 10000, cdl_enabled: true, default_read_users: ['user1'], default_read_groups: ['group1'], default_hidden: true) } + + it 'returns all attributes' do + expect(presenter.name).to be_present + expect(presenter.unit).to be_present + expect(presenter.description).to be_present + expect(presenter.contact_email).to be_present + expect(presenter.website_label).to be_present + expect(presenter.website_url).to be_present + expect(presenter.dropbox_directory_name).to be_present + expect(presenter.default_read_groups).to be_present + expect(presenter.default_read_users).to be_present + expect(presenter.default_hidden).not_to be_nil + expect(presenter.identifier).to be_present + expect(presenter.default_lending_period).to be_present + expect(presenter.cdl_enabled).not_to be_nil + expect(presenter.collection_managers).to be_present + expect(presenter.edit_users).to be_present + expect(presenter.read_users).to be_present + end + end + describe 'cdl_enabled' do context 'collections disabled at the application level' do before { allow(Settings.controlled_digital_lending).to receive(:collections_enabled).and_return(false) } diff --git a/spec/presenters/speedy_af/proxy/derivative_spec.rb b/spec/presenters/speedy_af/proxy/derivative_spec.rb index 2c7d049530..c99e3c54f8 100644 --- a/spec/presenters/speedy_af/proxy/derivative_spec.rb +++ b/spec/presenters/speedy_af/proxy/derivative_spec.rb @@ -16,15 +16,37 @@ describe SpeedyAF::Proxy::Derivative do let(:derivative) { FactoryBot.create(:derivative) } - before(:each) do - derivative.video_codec = nil - derivative.video_bitrate = nil - derivative.mime_type = nil - derivative.save - end subject(:presenter) { described_class.find(derivative.id) } + describe 'attributes' do + let(:derivative) { FactoryBot.create(:derivative, mime_type: 'video/mp4') } + + it 'returns all attributes' do + expect(presenter.location_url).to be_present #also stored as stream_path_ssi? + expect(presenter.hls_url).to be_present + expect(presenter.duration).to be_present + expect(presenter.track_id).to be_present + expect(presenter.hls_track_id).to be_present + expect(presenter.managed).not_to be_nil + expect(presenter.derivativeFile).to be_present + expect(presenter.quality).to be_present + expect(presenter.mime_type).to be_present + expect(presenter.audio_bitrate).to be_present + expect(presenter.audio_codec).to be_present + expect(presenter.video_bitrate).to be_present + expect(presenter.video_codec).to be_present + expect(presenter.resolution).to be_present + end + end + describe "#defaults" do + before(:each) do + derivative.video_codec = nil + derivative.video_bitrate = nil + derivative.mime_type = nil + derivative.save + end + it "sets video_bitrate to nil" do expect(subject.inspect).to include("video_bitrate") expect(subject.video_bitrate).to be_nil diff --git a/spec/presenters/speedy_af/proxy/lease_spec.rb b/spec/presenters/speedy_af/proxy/lease_spec.rb new file mode 100644 index 0000000000..a09c73e615 --- /dev/null +++ b/spec/presenters/speedy_af/proxy/lease_spec.rb @@ -0,0 +1,35 @@ +# 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 +# specific language governing permissions and limitations under the License. +# --- END LICENSE_HEADER BLOCK --- + +require 'rails_helper' + +describe SpeedyAF::Proxy::Lease do + let(:lease) { FactoryBot.create(:lease, lease_type: "user") } + subject(:presenter) { described_class.find(lease.id) } + + it "returns all fields" do + expect(subject.begin_time).to be_present + expect(subject.end_time).to be_present + expect(subject.lease_type).to be_present + end + + describe "#defaults" do + let(:lease) { FactoryBot.create(:lease) } + + it "sets lease_type to nil" do + expect(subject.inspect).to include("lease_type") + expect(subject.lease_type).to be_nil + end + end +end diff --git a/spec/presenters/speedy_af/proxy/master_file_spec.rb b/spec/presenters/speedy_af/proxy/master_file_spec.rb index b02a932cf4..543d29ca05 100644 --- a/spec/presenters/speedy_af/proxy/master_file_spec.rb +++ b/spec/presenters/speedy_af/proxy/master_file_spec.rb @@ -18,6 +18,36 @@ let(:master_file) { FactoryBot.create(:master_file) } subject(:presenter) { described_class.find(master_file.id) } + describe 'attributes' do + let(:master_file) { FactoryBot.create(:master_file, :with_comments, permalink: 'http://permalink', supplemental_files_json: '[]', title: 'Castle', file_checksum: 'abcd1234', file_size: 10, physical_description: 'LP', encoder_classname: 'ActiveEncode::Base', working_file_path: ['path/to/file']) } + + it 'returns all attributes' do + expect(presenter.permalink).to be_present + expect(presenter.supplemental_files_json).to be_present + expect(presenter.title).to be_present + expect(presenter.file_location).to be_present + expect(presenter.file_checksum).to be_present + expect(presenter.file_size).to be_present + expect(presenter.duration).to be_present + expect(presenter.display_aspect_ratio).to be_present + expect(presenter.width).to be_present + expect(presenter.height).to be_present + expect(presenter.original_frame_size).to be_present + expect(presenter.file_format).to be_present + expect(presenter.poster_offset).to be_present + expect(presenter.thumbnail_offset).to be_present + expect(presenter.date_digitized).to be_present + expect(presenter.physical_description).to be_present + expect(presenter.masterFile).to be_present + expect(presenter.identifier).to be_present + expect(presenter.comment).to be_present + expect(presenter.workflow_id).to be_present + expect(presenter.encoder_classname).to be_present + expect(presenter.workflow_name).to be_present + expect(presenter.working_file_path).to be_present + end + end + describe "#encoder_class" do it "should default to WatchedEncode" do expect(subject.encoder_class).to eq(WatchedEncode) diff --git a/spec/presenters/speedy_af/proxy/media_object_spec.rb b/spec/presenters/speedy_af/proxy/media_object_spec.rb index 625d362feb..9c84ec2912 100644 --- a/spec/presenters/speedy_af/proxy/media_object_spec.rb +++ b/spec/presenters/speedy_af/proxy/media_object_spec.rb @@ -67,4 +67,20 @@ expect(presenter.visibility).to eq media_object.visibility end end + + describe 'attributes' do + let(:media_object) { FactoryBot.create(:fully_searchable_media_object, :with_master_file, permalink: 'http://permalink', supplemental_files_json: '[]', duration: 10, avalon_uploader: 'user1', identifier: ['abc123'], lending_period: 12000) } + + it 'returns all attributes' do + expect(presenter.permalink).to be_present + expect(presenter.supplemental_files_json).to be_present + expect(presenter.duration).to be_present + expect(presenter.avalon_resource_type).to be_present + expect(presenter.avalon_publisher).to be_present + expect(presenter.avalon_uploader).to be_present + expect(presenter.identifier).to be_present + expect(presenter.comment).to be_present + expect(presenter.lending_period).to be_present + end + end end From a362d1b6b2dea7d65a4b2b9c3383c4f84136b85e Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Fri, 17 Nov 2023 13:18:54 -0500 Subject: [PATCH 2/2] Add defaults for solr fields that don't have backing attributes to avoid reifying when not present --- config/initializers/presenter_config.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/initializers/presenter_config.rb b/config/initializers/presenter_config.rb index 4463f75a0a..b238467210 100644 --- a/config/initializers/presenter_config.rb +++ b/config/initializers/presenter_config.rb @@ -14,7 +14,11 @@ file_size: nil, date_digitized: nil, file_checksum: nil, - identifier: [] + identifier: [], + percent_complete: nil, + status_code: nil, + operation: nil, + error: nil } include MasterFileIntercom include MasterFileBehavior