1
0
Fork 0

Add method Passport#can_have_confirmations?

This commit is contained in:
Alex Kotov 2018-12-03 01:51:10 +05:00
parent 9d75e9b01b
commit b68c3e0e5a
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
3 changed files with 9 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -19,6 +19,7 @@ RSpec.describe Passport do
pending '#passport_map'
pending '#image'
pending '#can_have_confirmations?'
pending '#enough_confirmations?'
describe '#confirmed' do