Handle OK status automatically

This commit is contained in:
Martin Lensment 2014-09-29 15:54:02 +03:00
parent 8892a25947
commit 77510cc3fa
5 changed files with 19 additions and 10 deletions

View file

@ -36,6 +36,7 @@ class Domain < ActiveRecord::Base
before_create :generate_auth_info before_create :generate_auth_info
before_create :set_validity_dates before_create :set_validity_dates
after_create :attach_default_contacts after_create :attach_default_contacts
after_save :manage_automatic_statuses
validates :name_dirty, domain_name: true, uniqueness: true validates :name_dirty, domain_name: true, uniqueness: true
validates :period, numericality: { only_integer: true } validates :period, numericality: { only_integer: true }
@ -201,6 +202,14 @@ class Domain < ActiveRecord::Base
domain_contacts.reject(&:marked_for_destruction?).select { |x| x.contact_type == DomainContact::ADMIN }.count domain_contacts.reject(&:marked_for_destruction?).select { |x| x.contact_type == DomainContact::ADMIN }.count
end end
def manage_automatic_statuses
if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK)
else
domain_statuses.find_by(value: DomainStatus::OK).try(:destroy)
end
end
class << self class << self
def convert_period_to_time(period, unit) def convert_period_to_time(period, unit)
return period.to_i.days if unit == 'd' return period.to_i.days if unit == 'd'

View file

@ -366,10 +366,17 @@ describe 'EPP Domain', epp: true do
expect(response[:results][0][:value]).to eq('4') expect(response[:results][0][:value]).to eq('4')
end end
it 'sets ok status by default' do
response = epp_request(domain_info_xml, :xml)
inf_data = response[:parsed].css('resData infData')
expect(inf_data.css('status').first[:s]).to eq('ok')
end
it 'returns domain info' do it 'returns domain info' do
d = Domain.first d = Domain.first
d.domain_statuses.create(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') d.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.')
d.nameservers.create(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') d.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A')
d.save
response = epp_request(domain_info_xml, :xml) response = epp_request(domain_info_xml, :xml)
expect(response[:results][0][:result_code]).to eq('1000') expect(response[:results][0][:result_code]).to eq('1000')

View file

@ -2,7 +2,7 @@ require 'rails_helper'
describe Domain do describe Domain do
it { should belong_to(:registrar) } it { should belong_to(:registrar) }
it { should have_and_belong_to_many(:nameservers) } it { should have_many(:nameservers) }
it { should belong_to(:owner_contact) } it { should belong_to(:owner_contact) }
it { should have_many(:tech_contacts) } it { should have_many(:tech_contacts) }
it { should have_many(:admin_contacts) } it { should have_many(:admin_contacts) }

View file

@ -1,6 +0,0 @@
require 'rails_helper'
describe NsSet do
it { should belong_to(:registrar) }
it { should have_and_belong_to_many(:nameservers) }
end

View file

@ -3,7 +3,6 @@ require 'rails_helper'
describe Registrar do describe Registrar do
it { should belong_to(:country) } it { should belong_to(:country) }
it { should have_many(:domains) } it { should have_many(:domains) }
it { should have_many(:ns_sets) }
it { should have_many(:epp_users) } it { should have_many(:epp_users) }
it { should have_many(:users) } it { should have_many(:users) }
end end