diff --git a/app/models/hyrax/file_metadata.rb b/app/models/hyrax/file_metadata.rb index 2d52b95eb6..d20c921d9e 100644 --- a/app/models/hyrax/file_metadata.rb +++ b/app/models/hyrax/file_metadata.rb @@ -13,12 +13,14 @@ module Use THUMBNAIL = ::Valkyrie::Vocab::PCDMUse.ThumbnailImage ## - # @param use [Symbol] + # @param use [RDF::URI, Symbol] # # @return [RDF::URI] # @raise [ArgumentError] if no use is known for the argument def uri_for(use:) case use + when RDF::URI + use when :original_file ORIGINAL_FILE when :extracted_file diff --git a/app/services/hyrax/characterization/file_set_description.rb b/app/services/hyrax/characterization/file_set_description.rb index dd310f5485..1ce747df2d 100644 --- a/app/services/hyrax/characterization/file_set_description.rb +++ b/app/services/hyrax/characterization/file_set_description.rb @@ -16,9 +16,9 @@ class FileSetDescription ## # @param [Hyrax::FileSet] file_set - # @param [Symbol] primary_file a symbol mapping to the file_set member - # used for characterization - def initialize(file_set:, primary_file: :original_file) + # @param [RDF::URI, Symbol] primary_file the type of file_set member to + # use for characterization + def initialize(file_set:, primary_file: Hyrax::FileMetadata::Use::ORIGINAL_FILE) self.file_set = file_set @primary_file_type_uri = diff --git a/spec/services/hyrax/characterization/file_set_description_spec.rb b/spec/services/hyrax/characterization/file_set_description_spec.rb index 0ef61ff3b0..be78d5cf4a 100644 --- a/spec/services/hyrax/characterization/file_set_description_spec.rb +++ b/spec/services/hyrax/characterization/file_set_description_spec.rb @@ -7,6 +7,7 @@ let(:file) { Rack::Test::UploadedFile.new('spec/fixtures/world.png', ctype) } let(:file_set) { FactoryBot.valkyrie_create(:hyrax_file_set, file_ids: file_ids) } let(:file_ids) { [] } + let(:original_file) { Hyrax.persister.save(resource: Hyrax::FileMetadata.for(file: file)) } describe '#mime_type' do context 'before the file set is saved' do @@ -25,7 +26,6 @@ context 'when it has an original file' do let(:file_ids) { [original_file.id] } - let(:original_file) { Hyrax.persister.save(resource: Hyrax::FileMetadata.for(file: file)) } it { is_expected.to be_image } @@ -33,5 +33,24 @@ expect(description.mime_type).to eq ctype end end + + context 'when it uses a custom URI type' do + subject(:description) { described_class.new(file_set: file_set, primary_file: custom_type) } + let(:file_ids) { [custom_file.id, original_file.id] } + let(:custom_type) { RDF::URI('http://example.com/HyraxTestCustomType') } + let(:other_ctype) { 'image/jpg' } + let(:other_file) { Rack::Test::UploadedFile.new('spec/fixtures/1.5mb-avatar.jpg', other_ctype) } + + let(:custom_file) do + resource = Hyrax::FileMetadata.for(file: other_file).new(type: custom_type) + Hyrax.persister.save(resource: resource) + end + + it { is_expected.to be_image } + + it 'has a mime type from a file' do + expect(description.mime_type).to eq other_ctype + end + end end end