Add method Passport#can_have_confirmations?
This commit is contained in:
parent
9d75e9b01b
commit
b68c3e0e5a
3 changed files with 9 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,6 +19,7 @@ RSpec.describe Passport do
|
|||
|
||||
pending '#passport_map'
|
||||
pending '#image'
|
||||
pending '#can_have_confirmations?'
|
||||
pending '#enough_confirmations?'
|
||||
|
||||
describe '#confirmed' do
|
||||
|
|
Reference in a new issue