Skip to content

Commit

Permalink
correct uploaded file naming convention by removing unnecessaarydegre…
Browse files Browse the repository at this point in the history
…e level
  • Loading branch information
amtuannguyen committed Oct 12, 2024
1 parent 52a31aa commit 868a812
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def uploaded_filename(original_filename)

full_name = thesis.student.name
year = thesis.exam_date.year
level = thesis.degree_level == 'Doctoral' ? 'PhD' : 'Masters'
level = thesis.degree_level
deg_name = thesis.degree_name
ext = File.extname(original_filename)

Expand All @@ -107,6 +107,6 @@ def uploaded_filename(original_filename)
embargo_count = embargo_count + 1 if self.new_record?
file_sequence = "_#{self.document_type}_#{embargo_count}" if document_type == 'embargo'

return "#{full_name}_#{year}_#{deg_name}_#{level}#{file_sequence}".gsub(/[\s\.]/, '_') + ext
return "#{full_name}_#{year}_#{deg_name}#{file_sequence}".gsub(/[\s\.]/, '_') + ext
end
end
30 changes: 15 additions & 15 deletions test/models/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ class DocumentTest < ActiveSupport::TestCase
student_name = t.student.name.gsub(/[\s\.]/, '_')
assert_match /^#{student_name}_.+/, uploaded_filename, "file name should start with #{student_name}"

# the file name should end with Level.pdf
level = t.degree_level == 'Doctoral' ? 'PhD' : 'Masters'
assert_match /#{level}.pdf$/, uploaded_filename, "the file name should end with #{level}.pdf"
# the file name should end with degree_name.pdf
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /#{degree_name}.pdf$/, uploaded_filename, "the file name should end with #{degree_name}.pdf"

# the file name should contain _year_
year = t.exam_date.year
assert_match /_#{year}_/, uploaded_filename, "the file name should contain _#{year}_"

# the file name should contain _degree_name_
# the file name should contain _degree_name
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /_#{degree_name}_/, uploaded_filename, "the file name should contain _#{degree_name}_"
assert_match /_#{degree_name}/, uploaded_filename, "the file name should contain _#{degree_name}"

# now upload first supplimentary file
d = create(:document_for_file_naming, file: fixture_file_upload(original_filename), usage: :thesis, supplemental: true, thesis: t)
Expand Down Expand Up @@ -223,17 +223,17 @@ class DocumentTest < ActiveSupport::TestCase
student_name = t.student.name.gsub(/[\s\.]/, '_')
assert_match /^#{student_name}_.+/, uploaded_filename, "file name should start with #{student_name}"

# the file name should end with Level.pdf
level = t.degree_level == 'Doctoral' ? 'PhD' : 'Masters'
assert_match /#{level}.pdf$/, uploaded_filename, "the file name should end with #{level}.pdf"
# the file name should end with degree_name.pdf
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /#{degree_name}.pdf$/, uploaded_filename, "the file name should end with #{degree_name}.pdf"

# the file name should contain _year_
year = t.exam_date.year
assert_match /_#{year}_/, uploaded_filename, "the file name should contain _#{year}_"

# the file name should contain _degree_name_
# the file name should contain _degree_name
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /_#{degree_name}_/, uploaded_filename, "the file name should contain _#{degree_name}_"
assert_match /_#{degree_name}/, uploaded_filename, "the file name should contain _#{degree_name}"

# now upload first licence file
d = create(:document_for_file_naming, file: fixture_file_upload(original_filename), usage: :licence, supplemental: true, thesis: t)
Expand Down Expand Up @@ -332,17 +332,17 @@ class DocumentTest < ActiveSupport::TestCase
student_name = t.student.name.gsub(/[\s\.]/, '_')
assert_match /^#{student_name}_.+/, uploaded_filename, "file name should start with #{student_name}"

# the file name should end with Level.pdf
level = t.degree_level == 'Doctoral' ? 'PhD' : 'Masters'
assert_match /#{level}.pdf$/, uploaded_filename, "the file name should end with #{level}.pdf"
# the file name should end with degree_name.pdf
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /#{degree_name}.pdf$/, uploaded_filename, "the file name should end with #{degree_name}.pdf"

# the file name should contain _year_
year = t.exam_date.year
assert_match /_#{year}_/, uploaded_filename, "the file name should contain _#{year}_"

# the file name should contain _degree_name_
# the file name should contain _degree_name
degree_name = t.degree_name.gsub(/[\s\.]/, '_')
assert_match /_#{degree_name}_/, uploaded_filename, "the file name should contain _#{degree_name}_"
assert_match /_#{degree_name}/, uploaded_filename, "the file name should contain _#{degree_name}"

# now upload first licence file
d = create(:document_for_file_naming, file: fixture_file_upload(original_filename), usage: :embargo, supplemental: true, thesis: t)
Expand Down

0 comments on commit 868a812

Please sign in to comment.