Merge pull request #1594 from internetee/1452-legaldocs-better-error-handling

Add error handling if legaldoc file not found
This commit is contained in:
Timo Võhmar 2020-06-01 20:13:14 +03:00 committed by GitHub
commit e7b3023412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -5,7 +5,11 @@ module Admin
def show
@ld = LegalDocument.find(params[:id])
filename = @ld.path.split('/').last
send_data File.open(@ld.path).read, filename: filename
file = File.open(@ld.path)&.read
send_data file, filename: filename
rescue Errno::ENOENT
flash[:notice] = I18n.t('legal_doc_not_found')
redirect_to [:admin, @ld.documentable]
end
end
end

View file

@ -0,0 +1,2 @@
en:
legal_doc_not_found: "There is an error downloading legal document: file not found"

View file

@ -0,0 +1,2 @@
et:
legal_doc_not_found: "Viga juriidilise dokumendi allalaadimisel: faili ei leitud"

View file

@ -0,0 +1,21 @@
require 'application_system_test_case'
class AdminAreaDomainsLegalDocTest < ApplicationSystemTestCase
setup do
sign_in users(:admin)
@domain = domains(:shop)
@document = LegalDocument.create(
document_type: 'pdf',
documentable_id: @domain.id,
documentable_type: 'Domain',
path: '\zzz\zzz'
)
end
def test_absent_doc_downloading_without_errors
visit admin_domain_url(@domain)
assert_nothing_raised do
click_on "#{@document.created_at}"
end
end
end