Domain name presence validation

This commit is contained in:
Martin Lensment 2014-07-30 14:54:21 +03:00
parent bfb9abea8c
commit 8882c36053
5 changed files with 19 additions and 7 deletions

View file

@ -8,6 +8,8 @@ class Domain < ActiveRecord::Base
belongs_to :technical_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_puny, domain_name: true
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }

View file

@ -16,6 +16,7 @@ class DomainNameValidator < ActiveModel::EachValidator
class << self
def validate_format(value)
return true unless value
value = value.mb_chars.downcase.strip
general_domains = /(.pri.ee|.com.ee|.fie.ee|.med.ee|.ee)/
@ -34,6 +35,7 @@ class DomainNameValidator < ActiveModel::EachValidator
end
def validate_reservation(value)
return true unless value
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)
end
end

View file

@ -35,9 +35,12 @@ en:
blank: "Required parameter missing - email"
ident:
blank: "Required parameter missing - ident"
domain:
attributes:
name:
blank: 'Required parameter missing - name'
errors:
messages:
epp_domain_reserved: 'Domain name is reserved or restricted'
epp_domain_taken: 'Domain name already exists'
hello: "Hello world"

View file

@ -31,10 +31,6 @@ describe 'EPP Domain', epp: true do
expect(response[:clTRID]).to eq('ABC-12345')
end
it 'does not create a domain with false period' do
end
it 'checks a domain' do
response = epp_request('domains/check.xml')
expect(response[:result_code]).to eq('1000')

View file

@ -7,7 +7,7 @@ describe Domain do
it { should belong_to(:owner_contact) }
it { should belong_to(:technical_contact) }
it 'creates a resource' do
it 'validates domain name' do
d = Fabricate(:domain)
expect(d.name).to_not be_nil
@ -34,6 +34,14 @@ describe Domain do
valid_punycode.each do |x|
expect(Fabricate.build(:domain, name: x).valid?).to be true
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
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: 99).valid?).to be true
end
end