mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Refactor epp errors to concern
This commit is contained in:
parent
b944516f17
commit
6b86af3048
4 changed files with 15 additions and 65 deletions
|
@ -2,8 +2,6 @@ class Domain < ActiveRecord::Base
|
|||
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
#TODO most inputs should be trimmed before validatation, probably some global logic?
|
||||
|
||||
|
||||
|
||||
include EppErrors
|
||||
|
||||
belongs_to :registrar
|
||||
|
@ -77,8 +75,6 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
save
|
||||
|
||||
# add_child_collection_errors(:nameservers, :ns)
|
||||
|
||||
validate_nameservers_count
|
||||
|
||||
errors.empty?
|
||||
|
@ -102,24 +98,6 @@ class Domain < ActiveRecord::Base
|
|||
self.nameservers.build(attrs)
|
||||
end
|
||||
|
||||
def add_child_collection_errors(attr_key, epp_obj_name)
|
||||
send(attr_key).each do |obj|
|
||||
obj.errors.keys.each do |key|
|
||||
add_errors_with_value(attr_key, epp_obj_name, obj, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_errors_with_value(attr_key, epp_obj_name, obj, key)
|
||||
obj.errors[key].each do |x|
|
||||
errors.add(attr_key, {
|
||||
obj: epp_obj_name,
|
||||
val: obj.send(key),
|
||||
msg: x
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def validate_nameservers_count
|
||||
unless nameservers.count.between?(1, 13)
|
||||
errors.add(:nameservers, :out_of_range, {min: 1, max: 13})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue