Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom URI use/type in FileSetDescription #4235

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/hyrax/file_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/services/hyrax/characterization/file_set_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,13 +26,31 @@

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 }

it 'has a mime type from a file' do
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