mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Domain name presence validation
This commit is contained in:
parent
bfb9abea8c
commit
8882c36053
5 changed files with 19 additions and 7 deletions
|
@ -8,6 +8,8 @@ class Domain < ActiveRecord::Base
|
||||||
belongs_to :technical_contact, class_name: 'Contact'
|
belongs_to :technical_contact, class_name: 'Contact'
|
||||||
belongs_to :admin_contact, class_name: 'Contact'
|
belongs_to :admin_contact, class_name: 'Contact'
|
||||||
|
|
||||||
|
validates_presence_of :name
|
||||||
|
|
||||||
validates :name, domain_name: true, uniqueness: { message: I18n.t('errors.messages.epp_domain_taken') }
|
validates :name, domain_name: true, uniqueness: { message: I18n.t('errors.messages.epp_domain_taken') }
|
||||||
validates :name_puny, domain_name: true
|
validates :name_puny, domain_name: true
|
||||||
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }
|
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }
|
||||||
|
|
|
@ -16,6 +16,7 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def validate_format(value)
|
def validate_format(value)
|
||||||
|
return true unless value
|
||||||
value = value.mb_chars.downcase.strip
|
value = value.mb_chars.downcase.strip
|
||||||
|
|
||||||
general_domains = /(.pri.ee|.com.ee|.fie.ee|.med.ee|.ee)/
|
general_domains = /(.pri.ee|.com.ee|.fie.ee|.med.ee|.ee)/
|
||||||
|
@ -33,7 +34,8 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
!!(value =~ regexp)
|
!!(value =~ regexp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_reservation(value)
|
def validate_reservation(value)
|
||||||
|
return true unless value
|
||||||
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)
|
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,9 +35,12 @@ en:
|
||||||
blank: "Required parameter missing - email"
|
blank: "Required parameter missing - email"
|
||||||
ident:
|
ident:
|
||||||
blank: "Required parameter missing - ident"
|
blank: "Required parameter missing - ident"
|
||||||
|
domain:
|
||||||
|
attributes:
|
||||||
|
name:
|
||||||
|
blank: 'Required parameter missing - name'
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
messages:
|
messages:
|
||||||
epp_domain_reserved: 'Domain name is reserved or restricted'
|
epp_domain_reserved: 'Domain name is reserved or restricted'
|
||||||
epp_domain_taken: 'Domain name already exists'
|
epp_domain_taken: 'Domain name already exists'
|
||||||
hello: "Hello world"
|
|
||||||
|
|
|
@ -31,10 +31,6 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain with false period' do
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'checks a domain' do
|
it 'checks a domain' do
|
||||||
response = epp_request('domains/check.xml')
|
response = epp_request('domains/check.xml')
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe Domain do
|
||||||
it { should belong_to(:owner_contact) }
|
it { should belong_to(:owner_contact) }
|
||||||
it { should belong_to(:technical_contact) }
|
it { should belong_to(:technical_contact) }
|
||||||
|
|
||||||
it 'creates a resource' do
|
it 'validates domain name' do
|
||||||
d = Fabricate(:domain)
|
d = Fabricate(:domain)
|
||||||
expect(d.name).to_not be_nil
|
expect(d.name).to_not be_nil
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@ describe Domain do
|
||||||
valid_punycode.each do |x|
|
valid_punycode.each do |x|
|
||||||
expect(Fabricate.build(:domain, name: x).valid?).to be true
|
expect(Fabricate.build(:domain, name: x).valid?).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
d = Domain.new
|
||||||
|
expect(d.valid?).to be false
|
||||||
|
|
||||||
|
expect(d.errors.messages).to match_array({
|
||||||
|
name: ['Required parameter missing - name'],
|
||||||
|
period: ['is not a number']
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a reserved domain' do
|
it 'does not create a reserved domain' do
|
||||||
|
@ -46,4 +54,5 @@ describe Domain do
|
||||||
expect(Fabricate.build(:domain, period: 120).valid?).to be false
|
expect(Fabricate.build(:domain, period: 120).valid?).to be false
|
||||||
expect(Fabricate.build(:domain, period: 99).valid?).to be true
|
expect(Fabricate.build(:domain, period: 99).valid?).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue