mirror of
https://github.com/internetee/registry.git
synced 2025-06-13 08:04:45 +02:00
Merge pull request #1594 from internetee/1452-legaldocs-better-error-handling
Add error handling if legaldoc file not found
This commit is contained in:
commit
e7b3023412
4 changed files with 30 additions and 1 deletions
|
@ -5,7 +5,11 @@ module Admin
|
||||||
def show
|
def show
|
||||||
@ld = LegalDocument.find(params[:id])
|
@ld = LegalDocument.find(params[:id])
|
||||||
filename = @ld.path.split('/').last
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
2
config/locales/admin/legal_documents.en.yml
Normal file
2
config/locales/admin/legal_documents.en.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
en:
|
||||||
|
legal_doc_not_found: "There is an error downloading legal document: file not found"
|
2
config/locales/admin/legal_documents.et.yml
Normal file
2
config/locales/admin/legal_documents.et.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
et:
|
||||||
|
legal_doc_not_found: "Viga juriidilise dokumendi allalaadimisel: faili ei leitud"
|
21
test/system/admin_area/domains/legal_doc_test.rb
Normal file
21
test/system/admin_area/domains/legal_doc_test.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue