From 34d06dad04d4964f25cf6da2876bec844022d3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 21 Jul 2017 11:27:40 +0200 Subject: [PATCH] Add document model validations and model shared specs. --- app/models/document.rb | 8 +++- spec/factories.rb | 2 + spec/fixtures/files/empty.pdf | Bin 0 -> 1886 bytes spec/shared/models/document_validatable.rb | 27 ----------- spec/shared/models/document_validations.rb | 52 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 spec/fixtures/files/empty.pdf delete mode 100644 spec/shared/models/document_validatable.rb create mode 100644 spec/shared/models/document_validations.rb diff --git a/app/models/document.rb b/app/models/document.rb index e8dd92b56..688540c09 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -1,8 +1,14 @@ class Document < ActiveRecord::Base + has_attached_file :attachment + belongs_to :user belongs_to :documentable, polymorphic: true - validates :user_id, presence: true + validates_attachment :attachment, presence: true, + content_type: { content_type: "application/pdf" }, + size: { in: 0..3.megabytes } + validates :title, presence: true + validates :user, presence: true validates :documentable_id, presence: true validates :documentable_type, presence: true diff --git a/spec/factories.rb b/spec/factories.rb index 0a82fa365..7b1f6a417 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -369,7 +369,9 @@ FactoryGirl.define do end factory :document do + sequence(:title) { |n| "Document title #{n}" } association :user, factory: :user + attachment { File.new("spec/fixtures/files/empty.pdf") } trait :proposal_document do association :documentable, factory: :proposal diff --git a/spec/fixtures/files/empty.pdf b/spec/fixtures/files/empty.pdf new file mode 100644 index 0000000000000000000000000000000000000000..de2e381483b397922ce1810b1ca6eed5142a1b1f GIT binary patch literal 1886 zcmcIlO>f#j5cPR~#a<$%hp=87d+jR9A<(o@OG6=2E1?|L_8OcRFSVD7^weM8cE;F1 zarz-eMM6TeZ)RuSd$XL3hgWC3*QbP2o9gJEoSzdmmUC562O<-~ZXZ{QvVk-**K=}l zK~#|-5Rco0Ev8N*>}{4*bVglFr+0)6^tv#VAEe?@Hx=(K6+oMdC#urxGKNmDr%yN0 zy^0O|rtErY)1WR7?XYpFgQp(3uS}FZ5{8cd(OEubv9)!oa;1?PCR) zc(Gnalp`aPgRb$k?fRW6=4L^?7E+l~$tC$*(`ZvnwQ0O0b*n>7J`kj>K{W(oGS+iM zODRr(kr`#63uU)zV{lrKV*pGxd7?o9D|s#qrqb^DklFd`@HjmqW=R1l=hbva$hSW%7>0$G=tsm7`t=;cZm zs9pd!j%4*f`Ia5la23{g=(u6Qvc7dWK@g7Nw!_xfV1y0Tmn>GVOZm7vJM`>-8l`ET zZ$0^!?rYSq?H^cuFBWgDv>&rI16uu`^c%_N>37KIlOnd0*K37N`;%_GweEhR1Dmqj z%;bume*a-9YiX@4V?A2d3tUJgO{R;XG;ln8>DXM@!r|O@JuUz+(#dbnVDFQ44E8-` z>#AhAj%CgUD$ixfGTa&XX7K|PJ-g?f^;xxm=Y=IY-fq;WK0OnRWksSky@grkFAg?p zQ>v7}DhI^geW>qwu18b4i=jX9LyLXP0~a5~IEMv2in);0i3Lx@!ftNg1;UT&^*x~c zDCT=zoG-wXM>t`_E*-^!em6Jp!Mew|poC6ukgme zTXJ2bnsPJ~JT?=p;T_ukz8=!qxhwj@4$?Fgf`>`sg(6gOAiTu$