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.
This commit is contained in:
Javi Martín
2020-04-16 12:04:10 +02:00
parent ca2dc10ee9
commit 95a90b1895
3 changed files with 1 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ module DocumentablesHelper
end end
def max_file_size(documentable_class) def max_file_size(documentable_class)
bytes_to_mega(documentable_class.max_file_size) documentable_class.max_file_size / Numeric::MEGABYTE
end end
def accepted_content_types(documentable_class) def accepted_content_types(documentable_class)

View File

@@ -7,10 +7,6 @@ module DocumentsHelper
document.errors[:attachment].join(", ") if document.errors.key?(:attachment) document.errors[:attachment].join(", ") if document.errors.key?(:attachment)
end end
def bytes_to_mega(bytes)
bytes / Numeric::MEGABYTE
end
def render_destroy_document_link(builder, document) def render_destroy_document_link(builder, document)
if !document.persisted? && document.cached_attachment.present? if !document.persisted? && document.cached_attachment.present?
link_to t("documents.form.delete_button"), link_to t("documents.form.delete_button"),

View File

@@ -1,5 +1,4 @@
shared_examples "document validations" do |documentable_factory| shared_examples "document validations" do |documentable_factory|
include DocumentsHelper
include DocumentablesHelper include DocumentablesHelper
let!(:document) { build(:document, documentable_factory.to_sym) } let!(:document) { build(:document, documentable_factory.to_sym) }