Extract method to check for a filesystem storage

We'll use this method to write a test dealing with remote storages.
This commit is contained in:
Javi Martín
2021-11-10 22:43:46 +01:00
parent b548e16ba0
commit e5fbd34eac

View File

@@ -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",