From 95a90b1895f046ef80fce844afa06b0d8f05fc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 16 Apr 2020 12:04:10 +0200 Subject: [PATCH] Simplify method to calculate document max size Since we're only doing the convertion from bytes to megabytes in one place, IMHO adding an extra method makes the code harder to read. This way we don't have do include the DocumentsHelper in the specs anymore, reducing the risk of possible method naming collisions. --- app/helpers/documentables_helper.rb | 2 +- app/helpers/documents_helper.rb | 4 ---- spec/shared/models/document_validations.rb | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index be827159d..74d7ccf0d 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -8,7 +8,7 @@ module DocumentablesHelper end def max_file_size(documentable_class) - bytes_to_mega(documentable_class.max_file_size) + documentable_class.max_file_size / Numeric::MEGABYTE end def accepted_content_types(documentable_class) diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index 1200b418a..0a57b7299 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -7,10 +7,6 @@ module DocumentsHelper document.errors[:attachment].join(", ") if document.errors.key?(:attachment) end - def bytes_to_mega(bytes) - bytes / Numeric::MEGABYTE - end - def render_destroy_document_link(builder, document) if !document.persisted? && document.cached_attachment.present? link_to t("documents.form.delete_button"), diff --git a/spec/shared/models/document_validations.rb b/spec/shared/models/document_validations.rb index 9ef685d6f..1a9a59a56 100644 --- a/spec/shared/models/document_validations.rb +++ b/spec/shared/models/document_validations.rb @@ -1,5 +1,4 @@ shared_examples "document validations" do |documentable_factory| - include DocumentsHelper include DocumentablesHelper let!(:document) { build(:document, documentable_factory.to_sym) }