From eb09447ee1bbf846d616daa699f775fa3106a341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 7 Jul 2020 14:04:56 +0300 Subject: [PATCH] Check legaldoc size only if it's not persisted --- app/models/legal_document.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 70ab1f37b..d3729cafb 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -14,8 +14,7 @@ class LegalDocument < ApplicationRecord belongs_to :documentable, polymorphic: true - - validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?} + validate :val_body_length, if: ->(file) { file.path.blank? } before_create :add_creator before_save :save_to_filesystem, if: :body @@ -29,6 +28,14 @@ class LegalDocument < ApplicationRecord end def val_body_length + if body.start_with? ENV['legal_documents_dir'] + if File.exist? body + self.path = body + self.body = nil + return + end + end + errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE end