From b68c3e0e5aee122ad812cf5df0eb6dde3e82eee8 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 3 Dec 2018 01:51:10 +0500 Subject: [PATCH] Add method Passport#can_have_confirmations? --- app/models/passport.rb | 4 ++++ app/models/passport_confirmation.rb | 16 ++++------------ spec/models/passport_spec.rb | 1 + 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/models/passport.rb b/app/models/passport.rb index e02c537..77d2962 100644 --- a/app/models/passport.rb +++ b/app/models/passport.rb @@ -22,6 +22,10 @@ class Passport < ApplicationRecord images.order(created_at: :asc).last end + def can_have_confirmations? + passport_map && image + end + def enough_confirmations? passport_confirmations.count >= REQUIRED_CONFIRMATIONS end diff --git a/app/models/passport_confirmation.rb b/app/models/passport_confirmation.rb index 44559f9..4ef200e 100644 --- a/app/models/passport_confirmation.rb +++ b/app/models/passport_confirmation.rb @@ -6,21 +6,13 @@ class PassportConfirmation < ApplicationRecord validates :account_id, uniqueness: { scope: :passport_id } - validate :passport_has_passport_map - validate :passport_has_image + validate :passport_can_have_confirmations private - def passport_has_passport_map - return if passport.nil? - return unless passport.passport_map.nil? + def passport_can_have_confirmations + return if passport.nil? || passport.can_have_confirmations? - errors.add :passport, 'must have a passport map' - end - - def passport_has_image - return if passport.nil? - - errors.add :passport, 'must have an image' if passport.image.nil? + errors.add :passport, 'must have a passport map and an image' end end diff --git a/spec/models/passport_spec.rb b/spec/models/passport_spec.rb index 1125ec4..1b48776 100644 --- a/spec/models/passport_spec.rb +++ b/spec/models/passport_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Passport do pending '#passport_map' pending '#image' + pending '#can_have_confirmations?' pending '#enough_confirmations?' describe '#confirmed' do