Use documentables helper method within specs and document model.

This commit is contained in:
Senén Rodero Rodríguez
2017-07-24 14:34:09 +02:00
parent 17ad148cd7
commit 92e8468e89
5 changed files with 28 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
class Document < ActiveRecord::Base
include DocumentsHelper
include DocumentablesHelper
has_attached_file :attachment
belongs_to :user
@@ -21,16 +22,16 @@ class Document < ActiveRecord::Base
attachment_file_size > documentable.class.max_file_size
errors[:attachment] = I18n.t("documents.errors.messages.in_between",
min: "0 Bytes",
max: "#{bytesToMeg(documentable.class.max_file_size)} MB")
max: "#{max_file_size(documentable)} MB")
end
end
def validate_attachment_content_type
if documentable.present? &&
!documentable.class.accepted_content_types.include?(attachment_content_type)
!accepted_content_types(documentable).include?(attachment_content_type)
errors[:attachment] = I18n.t("documents.errors.messages.wrong_content_type",
content_type: attachment_content_type,
accepted_content_types: documentable.class.accepted_content_types.join(", "))
accepted_content_types: humanized_accepted_content_types(documentable))
end
end