Refactor domain expirable

#186
This commit is contained in:
Artur Beljajev 2016-10-29 00:51:42 +03:00
parent 14c5c3efed
commit 0cc3a53deb
3 changed files with 26 additions and 30 deletions

View file

@ -12,17 +12,17 @@ module Concerns::Domain::Expirable
end end
def registered? def registered?
valid_to >= Time.zone.now !expired?
end end
def expired? def expired?
statuses.include?(DomainStatus::EXPIRED) expire_time <= Time.zone.now
end end
def expirable? def expirable?
return false if valid_to > Time.zone.now return false if valid_to > Time.zone.now
if expired? && outzone_at.present? && delete_at.present? if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present?
return false return false
end end

View file

@ -283,16 +283,6 @@ class Domain < ActiveRecord::Base
domain_transfers.find_by(status: DomainTransfer::PENDING) domain_transfers.find_by(status: DomainTransfer::PENDING)
end end
def expirable?
return false if valid_to > Time.zone.now
if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present?
return false
end
true
end
def server_holdable? def server_holdable?
return false if statuses.include?(DomainStatus::SERVER_HOLD) return false if statuses.include?(DomainStatus::SERVER_HOLD)
return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE) return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE)

View file

@ -18,38 +18,44 @@ RSpec.describe Domain, db: false do
end end
describe '#registered?' do describe '#registered?' do
before :example do let(:domain) { described_class.new }
travel_to Time.zone.parse('05.07.2010 00:00')
end
context 'when :valid_to is in the future' do context 'when not expired' do
let(:domain) { described_class.new(expire_time: Time.zone.parse('06.07.2010 00:01')) } before :example do
expect(domain).to receive(:expired?).and_return(false)
end
specify { expect(domain).to be_registered } specify { expect(domain).to be_registered }
end end
context 'when :valid_to is the same as current time' do context 'when expired' do
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } before :example do
expect(domain).to receive(:expired?).and_return(true)
specify { expect(domain).to_not be_registered } end
end
context 'when :valid_to is in the past' do
let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) }
specify { expect(domain).to_not be_registered } specify { expect(domain).to_not be_registered }
end end
end end
describe '#expired?' do describe '#expired?' do
context 'when :statuses contains expired status' do before :example do
let(:domain) { described_class.new(statuses: [DomainStatus::EXPIRED]) } travel_to Time.zone.parse('05.07.2010 00:00')
end
context 'when :expire_time is in the past' do
let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) }
specify { expect(domain).to be_expired } specify { expect(domain).to be_expired }
end end
context 'when :statuses does not contain expired status' do context 'when :expire_time is now' do
let(:domain) { described_class.new(statuses: [DomainStatus::CLIENT_HOLD]) } let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) }
specify { expect(domain).to be_expired }
end
context 'when :expire_time is in the future' do
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) }
specify { expect(domain).to_not be_expired } specify { expect(domain).to_not be_expired }
end end