From e5fbd34eac28264991ec804114531df73519f81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 10 Nov 2021 22:43:46 +0100 Subject: [PATCH] Extract method to check for a filesystem storage We'll use this method to write a test dealing with remote storages. --- app/models/concerns/attachable.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/attachable.rb b/app/models/concerns/attachable.rb index 1fbe15512..8aec7ec65 100644 --- a/app/models/concerns/attachable.rb +++ b/app/models/concerns/attachable.rb @@ -26,7 +26,7 @@ module Attachable end def set_cached_attachment_from_attachment - self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem + self.cached_attachment = if filesystem_storage? attachment.path else attachment.url @@ -34,7 +34,7 @@ module Attachable end def set_attachment_from_cached_attachment - if Paperclip::Attachment.default_options[:storage] == :filesystem + if filesystem_storage? File.open(cached_attachment) { |file| self.attachment = file } else self.attachment = URI.open(cached_attachment) @@ -51,6 +51,10 @@ module Attachable private + def filesystem_storage? + Paperclip::Attachment.default_options[:storage] == :filesystem + end + def validate_attachment_size if association_class && attachment_file_size > max_file_size.megabytes errors.add(:attachment, I18n.t("#{model_name.plural}.errors.messages.in_between",