mirror of
https://github.com/internetee/registry.git
synced 2025-07-02 01:03:35 +02:00
Merge remote-tracking branch 'origin/registry-235' into registry-186
# Conflicts: # spec/models/domain_spec.rb
This commit is contained in:
commit
3d1dd1759d
5 changed files with 86 additions and 30 deletions
|
@ -76,7 +76,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
before_create :generate_auth_info
|
||||
before_create :set_validity_dates
|
||||
before_create -> { self.reserved = in_reserved_list?; nil }
|
||||
|
||||
before_save :manage_automatic_statuses
|
||||
|
@ -541,13 +540,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
# rubocop:enable Lint/Loop
|
||||
|
||||
def set_validity_dates
|
||||
self.registered_at = Time.zone.now
|
||||
self.valid_from = Time.zone.now
|
||||
# we need + 1 day as this is more correct from juridical side
|
||||
self.valid_to = valid_from.utc.beginning_of_day + self.class.convert_period_to_time(period, period_unit) + 1.day
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def set_force_delete
|
||||
|
@ -604,24 +596,11 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def set_graceful_expired
|
||||
self.outzone_at = (valid_to + Setting.expire_warning_period.days).utc.beginning_of_day
|
||||
self.delete_at = (outzone_at + Setting.redemption_grace_period.days).utc.beginning_of_day
|
||||
self.outzone_at = valid_to + self.class.expire_warning_period
|
||||
self.delete_at = outzone_at + self.class.redemption_grace_period
|
||||
self.statuses |= [DomainStatus::EXPIRED]
|
||||
end
|
||||
|
||||
def set_expired
|
||||
# TODO: currently valid_to attribute update logic is open
|
||||
# self.valid_to = valid_from + self.class.convert_period_to_time(period, period_unit)
|
||||
self.outzone_at = (valid_to + Setting.expire_warning_period.days).utc.beginning_of_day
|
||||
self.delete_at = (outzone_at + Setting.redemption_grace_period.days).utc.beginning_of_day
|
||||
statuses << DomainStatus::EXPIRED
|
||||
end
|
||||
|
||||
def set_expired!
|
||||
set_expired
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
def pending_update?
|
||||
statuses.include?(DomainStatus::PENDING_UPDATE) && !statuses.include?(DomainStatus::FORCE_DELETE)
|
||||
end
|
||||
|
@ -778,5 +757,13 @@ class Domain < ActiveRecord::Base
|
|||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
end
|
||||
|
||||
def self.expire_warning_period
|
||||
Setting.expire_warning_period.days
|
||||
end
|
||||
|
||||
def self.redemption_grace_period
|
||||
Setting.redemption_grace_period.days
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
||||
|
|
|
@ -53,6 +53,9 @@ class Epp::Domain < Domain
|
|||
domain = Epp::Domain.new
|
||||
domain.attributes = domain.attrs_from(frame, current_user)
|
||||
domain.attach_default_contacts
|
||||
domain.registered_at = Time.zone.now
|
||||
domain.valid_from = Time.zone.now
|
||||
domain.valid_to = domain.valid_from.beginning_of_day + convert_period_to_time(domain.period, domain.period_unit) + 1.day
|
||||
domain
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,8 +36,6 @@ Rails.application.configure do
|
|||
# For rails-settings-cached conflict
|
||||
config.cache_store = :file_store, 'tmp/cache_test'
|
||||
|
||||
config.time_zone = 'UTC'
|
||||
|
||||
config.action_view.raise_on_missing_translations = true
|
||||
|
||||
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown,
|
||||
|
|
|
@ -89,11 +89,6 @@ RSpec.describe Domain do
|
|||
@domain.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should have correct validity dates' do
|
||||
@domain.outzone_at.should be_nil
|
||||
@domain.delete_at.should be_nil
|
||||
end
|
||||
|
||||
it 'should validate uniqueness of tech contacts' do
|
||||
same_contact = Fabricate(:contact, code: 'same_contact')
|
||||
domain = Fabricate(:domain)
|
||||
|
@ -721,6 +716,26 @@ RSpec.describe Domain, db: false do
|
|||
it { is_expected.to alias_attribute(:delete_time, :delete_at) }
|
||||
it { is_expected.to alias_attribute(:force_delete_time, :force_delete_at) }
|
||||
|
||||
describe '::expire_warning_period', db: true do
|
||||
before :example do
|
||||
Setting.expire_warning_period = 1
|
||||
end
|
||||
|
||||
it 'returns expire warning period' do
|
||||
expect(described_class.expire_warning_period).to eq(1.day)
|
||||
end
|
||||
end
|
||||
|
||||
describe '::redemption_grace_period', db: true do
|
||||
before :example do
|
||||
Setting.redemption_grace_period = 1
|
||||
end
|
||||
|
||||
it 'returns redemption grace period' do
|
||||
expect(described_class.redemption_grace_period).to eq(1.day)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set_server_hold' do
|
||||
let(:domain) { described_class.new }
|
||||
|
||||
|
@ -819,4 +834,24 @@ RSpec.describe Domain, db: false do
|
|||
domain.pending_delete!
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set_graceful_expired' do
|
||||
let(:domain) { described_class.new }
|
||||
|
||||
before :example do
|
||||
expect(described_class).to receive(:expire_warning_period).and_return(1.day)
|
||||
expect(described_class).to receive(:redemption_grace_period).and_return(2.days)
|
||||
expect(domain).to receive(:valid_to).and_return(Time.zone.parse('05.07.2010 10:30'))
|
||||
|
||||
domain.set_graceful_expired
|
||||
end
|
||||
|
||||
it 'sets :outzone_at to :valid_to + expire warning period' do
|
||||
expect(domain.outzone_at).to eq(Time.zone.parse('06.07.2010 10:30'))
|
||||
end
|
||||
|
||||
it 'sets :delete_at to :outzone_at + redemption grace period' do
|
||||
expect(domain.delete_at).to eq(Time.zone.parse('08.07.2010 10:30'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
33
spec/models/epp/domain_spec.rb
Normal file
33
spec/models/epp/domain_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Epp::Domain, db: false do
|
||||
describe '::new_from_epp' do
|
||||
let(:domain_blueprint) { described_class.new }
|
||||
subject(:domain) { described_class.new_from_epp(nil, nil) }
|
||||
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010')
|
||||
|
||||
domain_blueprint.period = 1
|
||||
domain_blueprint.period_unit = 'y'
|
||||
|
||||
expect(described_class).to receive(:new).and_return(domain_blueprint)
|
||||
expect(domain_blueprint).to receive(:attrs_from).and_return({})
|
||||
expect(domain_blueprint).to receive(:attach_default_contacts)
|
||||
end
|
||||
|
||||
describe 'domain' do
|
||||
it 'has :registered_at set to now' do
|
||||
expect(domain.registered_at).to eq(Time.zone.parse('05.07.2010'))
|
||||
end
|
||||
|
||||
it 'has :valid_from set to now' do
|
||||
expect(domain.valid_from).to eq(Time.zone.parse('05.07.2010'))
|
||||
end
|
||||
|
||||
it 'has :valid_to set to the beginning of next day after :valid_from' do
|
||||
expect(domain.valid_to).to eq(Time.zone.parse('06.07.2011 00:00'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue