Add domain destroy method #2622

This commit is contained in:
Martin Lensment 2015-06-10 12:20:35 +03:00
parent 21829faf38
commit 3c8bbe18cf
2 changed files with 25 additions and 4 deletions

View file

@ -161,7 +161,13 @@ class Domain < ActiveRecord::Base
def start_delete_period def start_delete_period
Domain.where('delete_at <= ?', Time.zone.now).each do |x| Domain.where('delete_at <= ?', Time.zone.now).each do |x|
x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.deletable? x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.delete_candidateable?
end
end
def destroy_delete_candidates
DomainStatus.where(value: DomainStatus::DELETE_CANDIDATE).each do |x|
x.domain.destroy
end end
end end
end end
@ -208,7 +214,7 @@ class Domain < ActiveRecord::Base
true true
end end
def deletable? def delete_candidateable?
return false if delete_at > Time.zone.now return false if delete_at > Time.zone.now
return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any? return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any?
return false if domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).any? return false if domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).any?
@ -360,7 +366,7 @@ class Domain < ActiveRecord::Base
end end
def manage_automatic_statuses def manage_automatic_statuses
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if deletable? # domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable?
if domain_statuses.empty? && valid? if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK) domain_statuses.create(value: DomainStatus::OK)

View file

@ -59,7 +59,9 @@ describe Domain do
valid_to = Time.zone.now + 1.year valid_to = Time.zone.now + 1.year
@domain.valid_to.should be_within(5).of(valid_to) @domain.valid_to.should be_within(5).of(valid_to)
@domain.outzone_at.should be_within(5).of(valid_to + Setting.expire_warning_period.days) @domain.outzone_at.should be_within(5).of(valid_to + Setting.expire_warning_period.days)
@domain.delete_at.should be_within(5).of(valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days) @domain.delete_at.should be_within(5).of(
valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
)
end end
it 'should validate uniqueness of tech contacts' do it 'should validate uniqueness of tech contacts' do
@ -140,6 +142,19 @@ describe Domain do
@domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 1 @domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 1
end end
it 'should destroy delete candidates' do
Fabricate(:domain)
Domain.count.should == 2
@domain.delete_at = Time.zone.now
@domain.save
Domain.start_delete_period
Domain.destroy_delete_candidates
Domain.count.should == 1
end
context 'about registrant update confirm' do context 'about registrant update confirm' do
before :all do before :all do
@domain.registrant_verification_token = 123 @domain.registrant_verification_token = 123