mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
parent
4fd18c4a26
commit
3b120f0362
3 changed files with 10 additions and 96 deletions
|
@ -1,31 +0,0 @@
|
||||||
module Concerns::Domain::Expirable
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
included do
|
|
||||||
alias_attribute :expire_time, :valid_to
|
|
||||||
end
|
|
||||||
|
|
||||||
class_methods do
|
|
||||||
def expired
|
|
||||||
where("#{attribute_alias(:expire_time)} <= ?", Time.zone.now)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def registered?
|
|
||||||
!expired?
|
|
||||||
end
|
|
||||||
|
|
||||||
def expired?
|
|
||||||
expire_time <= Time.zone.now
|
|
||||||
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
|
|
||||||
end
|
|
|
@ -3,7 +3,6 @@ class Domain < ActiveRecord::Base
|
||||||
include UserEvents
|
include UserEvents
|
||||||
include Versions # version/domain_version.rb
|
include Versions # version/domain_version.rb
|
||||||
include Statuses
|
include Statuses
|
||||||
include Concerns::Domain::Expirable
|
|
||||||
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
|
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
|
||||||
|
|
||||||
attr_accessor :roles
|
attr_accessor :roles
|
||||||
|
@ -11,7 +10,6 @@ class Domain < ActiveRecord::Base
|
||||||
attr_accessor :legal_document_id
|
attr_accessor :legal_document_id
|
||||||
|
|
||||||
alias_attribute :on_hold_time, :outzone_at
|
alias_attribute :on_hold_time, :outzone_at
|
||||||
alias_attribute :delete_time, :delete_at
|
|
||||||
alias_attribute :force_delete_time, :force_delete_at
|
alias_attribute :force_delete_time, :force_delete_at
|
||||||
|
|
||||||
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
|
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||||
|
@ -285,6 +283,16 @@ 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)
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Domain, db: false do
|
|
||||||
it { is_expected.to alias_attribute(:expire_time, :valid_to) }
|
|
||||||
|
|
||||||
describe '::expired', db: true do
|
|
||||||
before :example do
|
|
||||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
|
||||||
|
|
||||||
FactoryGirl.create(:domain, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59'))
|
|
||||||
FactoryGirl.create(:domain, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00'))
|
|
||||||
FactoryGirl.create(:domain, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns expired domains' do
|
|
||||||
expect(described_class.expired.ids).to eq([1, 2])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#registered?' do
|
|
||||||
let(:domain) { described_class.new }
|
|
||||||
|
|
||||||
context 'when not expired' do
|
|
||||||
before :example do
|
|
||||||
expect(domain).to receive(:expired?).and_return(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
specify { expect(domain).to be_registered }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when expired' do
|
|
||||||
before :example do
|
|
||||||
expect(domain).to receive(:expired?).and_return(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
specify { expect(domain).to_not be_registered }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#expired?' do
|
|
||||||
before :example do
|
|
||||||
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 }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when :expire_time is now' do
|
|
||||||
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 }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue