mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 17:01:44 +02:00
parent
4d5830efdf
commit
d5197962ee
5 changed files with 40 additions and 28 deletions
|
@ -12,7 +12,7 @@ class Contact::Ident
|
|||
|
||||
validates :type, presence: true, inclusion: { in: proc { types } }
|
||||
validates :country_code, presence: true, iso31661_alpha2: true
|
||||
validate :mismatched
|
||||
validates_with MismatchValidator
|
||||
|
||||
def self.epp_code_map
|
||||
{
|
||||
|
@ -35,14 +35,6 @@ class Contact::Ident
|
|||
%w[org priv birthday]
|
||||
end
|
||||
|
||||
Mismatch = Struct.new(:type, :country)
|
||||
|
||||
def self.mismatches
|
||||
[
|
||||
Mismatch.new('birthday', Country.new('EE'))
|
||||
]
|
||||
end
|
||||
|
||||
def marked_for_destruction?
|
||||
false
|
||||
end
|
||||
|
@ -66,10 +58,7 @@ class Contact::Ident
|
|||
private
|
||||
|
||||
# https://github.com/rails/rails/issues/1513
|
||||
def validation_context=(_value); end
|
||||
|
||||
def mismatched
|
||||
mismatched = self.class.mismatches.include?(Mismatch.new(type, country))
|
||||
errors.add(:base, :mismatch, type: type, country: country) if mismatched
|
||||
def validation_context=(_value)
|
||||
;
|
||||
end
|
||||
end
|
||||
|
|
20
app/validators/contact/ident/mismatch_validator.rb
Normal file
20
app/validators/contact/ident/mismatch_validator.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
class Contact::Ident::MismatchValidator < ActiveModel::Validator
|
||||
Mismatch = Struct.new(:type, :country)
|
||||
|
||||
def self.mismatches
|
||||
[
|
||||
Mismatch.new('birthday', Country.new('EE')),
|
||||
]
|
||||
end
|
||||
|
||||
def validate(record)
|
||||
record.errors.add(:base, :mismatch, type: record.type, country: record.country) if mismatched?(record)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mismatched?(record)
|
||||
mismatch = Mismatch.new(record.type, record.country)
|
||||
self.class.mismatches.include?(mismatch)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue