Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:yorkulibraries/etd into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jul 23, 2024
2 parents 64a30f3 + 3de15e6 commit 06213e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/uploaders/document_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ def store_dir
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
def filename
return original_filename unless model.user.present? && !model.user.name.nil?
return "#{original_filename}" if model.usage != "thesis"
# return "#{model.usage.upcase}_#{original_filename}" if model.usage != "thesis"

if model.usage == "thesis"
Document.filename_by_convention(model.user.name, model.thesis.exam_date, model.thesis.degree_name, model.thesis.degree_level, original_filename, model.supplemental, model.usage)
elsif model.usage == "licence" || model.usage == "embargo" || model.usage == "embargo_letter"
"#{model.usage.upcase}_#{original_filename}"
elsif model.user.present? && !model.user.name.nil?
original_filename
else
original_filename
end


# return original_filename unless model.user.present? && !model.user.name.nil?
# return "#{original_filename}" if model.usage != "thesis"
# return "#{original_filename}" if model.usage != "thesis"
# # return "#{model.usage.upcase}_#{original_filename}" if model.usage != "thesis"

## Therefore, thesis upload
Document.filename_by_convention(model.user.name, model.thesis.exam_date, model.thesis.degree_name, model.thesis.degree_level, original_filename, model.supplemental, model.usage)

end

def move_to_cache
Expand Down
20 changes: 20 additions & 0 deletions test/models/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ class DocumentTest < ActiveSupport::TestCase
assert_match(/_Supplemental_.*\.\w+$/, t.documents.first.file.to_s)
end

should 'licence files with usage in filename' do
t = create(:thesis)
licence_document = create(:document_for_file_naming, file: fixture_file_upload('html-document.html'), usage: :licence, supplemental: true, thesis: t)

assert_match(/LICENCE_.*\.\w+$/, t.documents.first.file.to_s)

end

should 'embargo file with usage in filename' do
t = create(:thesis)
embargo_document = create(:document_for_file_naming, file: fixture_file_upload('image-example.jpg'), usage: :embargo, supplemental: true, thesis: t)

assert_match(/EMBARGO_.*\.\w+$/, t.documents.first.file.to_s)

embargo_letter_document = create(:document_for_file_naming, file: fixture_file_upload('pdf-document.pdf'), usage: :embargo_letter, supplemental: true, thesis: t)
assert_match(/EMBARGO_LETTER.*\.\w+$/, t.documents[1].file.to_s)

end


should 'save files in sequence for supplementary' do
# t = create(:thesis)

Expand Down

0 comments on commit 06213e3

Please sign in to comment.