From 8e91bbe5b5b82ad407478f37e4e09250d5320ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 24 Aug 2017 01:28:33 +0200 Subject: [PATCH] Fix document validations specs --- app/models/document.rb | 4 ++-- spec/shared/models/document_validations.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/document.rb b/app/models/document.rb index 0aafcfecc..784064a7f 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -17,8 +17,8 @@ class Document < ActiveRecord::Base validate :validate_attachment_size, if: -> { attachment.present? } validates :title, presence: true validates :user_id, presence: true - # validates :documentable_id, presence: true - # validates :documentable_type, presence: true + validates :documentable_id, presence: true, if: -> { persisted? } + validates :documentable_type, presence: true, if: -> { persisted? } def validate_attachment_size if documentable.present? && diff --git a/spec/shared/models/document_validations.rb b/spec/shared/models/document_validations.rb index 6207a850a..3226129a3 100644 --- a/spec/shared/models/document_validations.rb +++ b/spec/shared/models/document_validations.rb @@ -46,12 +46,14 @@ shared_examples "document validations" do |documentable_factory| end it "should not be valid without a documentable_id" do + document.save document.documentable_id = nil expect(document).to_not be_valid end it "should not be valid without a documentable_type" do + document.save document.documentable_type = nil expect(document).to_not be_valid