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

Add validation on minimum file size #2334

Merged
merged 1 commit into from
Aug 14, 2024
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
2 changes: 2 additions & 0 deletions app/validators/file_upload_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def validate_file_size(record, attribute, uploaded_file)
if uploaded_file.size >= MAX_FILE_SIZE
record.errors.add attribute, :file_size_too_big
end

record.errors.add attribute, :file_size_too_small if uploaded_file.size <= 1
end

def validate_content_type(record, attribute, uploaded_file)
Expand Down
1 change: 0 additions & 1 deletion config/locales/assessor_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ en:
original_attachment:
blank: Upload the required consent document
encrypted_pdf: The selected file is security protected
file_size_too_big: Files must be smaller than 50MB
invalid_content_type: Files must be in PDF, JPG, PNG, DOCX or DOC format
mismatch_content_type: Files must have matching file type and file name. For example, if the upload is called example.doc, it must be a DOC file.
assessor_interface/verify_professional_standing_form:
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ en:
messages:
comparison: can't be before start date
encrypted_pdf: file is encrypted
file_size_too_big: file size is too large
file_size_too_big: Files must be smaller than 50 MB
file_size_too_small: Files must be bigger than 0 MB
future: can't be in the future
invalid_content_type: is not in the correct format
mismatch_content_type: file format doesn't match extension
2 changes: 0 additions & 2 deletions config/locales/teacher_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,11 @@ en:
original_attachment:
blank: Select a file to upload
encrypted_pdf: The selected file is security protected
file_size_too_big: Files must be smaller than 50MB
invalid_content_type: Files must be in PDF, JPG, PNG, DOCX or DOC format
mismatch_content_type: Files must have matching file type and file name. For example, if the upload is called example.doc, it must be a DOC file.
translated_attachment:
blank: Select a translation to upload
encrypted_pdf: The selected file is security protected
file_size_too_big: Files must be smaller than 50MB
invalid_content_type: Files must be in PDF, JPG, PNG, DOCX or DOC format
mismatch_content_type: Files must have matching file type and file name. For example, if the upload is called example.doc, it must be a DOC file.
teacher_interface/work_history_form:
Expand Down
8 changes: 8 additions & 0 deletions spec/validators/file_upload_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@

it { is_expected.not_to be_valid }
end

context "with a small file" do
let(:file) { fixture_file_upload("upload.pdf", "application/pdf") }

before { allow(file).to receive(:size).and_return(1) }

it { is_expected.not_to be_valid }
end
end
Loading