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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user