diff --git a/app/models/domain.rb b/app/models/domain.rb index 9960b12a0..1ea6d0b98 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -78,6 +78,7 @@ 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 @@ -532,6 +533,13 @@ 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 diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 2441555c1..61ee6a2d8 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -51,9 +51,6 @@ class Epp::Domain < Domain class << self def new_from_epp(frame, current_user) domain = Epp::Domain.new - domain.registered_at = Time.zone.now - domain.valid_from = Time.zone.now - domain.expire_time = domain.valid_from.beginning_of_day + convert_period_to_time(domain.period, domain.period_unit) + 1.day domain.attributes = domain.attrs_from(frame, current_user) domain.attach_default_contacts domain diff --git a/config/environments/test.rb b/config/environments/test.rb index 9f6a888d1..4e0b47bcb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -36,6 +36,8 @@ 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, diff --git a/spec/models/epp/domain_spec.rb b/spec/models/epp/domain_spec.rb deleted file mode 100644 index 4b91b8947..000000000 --- a/spec/models/epp/domain_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -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 :expire_time set to now' do - expire_time = Time.zone.parse('05.07.2010') + 1.year + 1.day - expect(domain.expire_time).to eq(expire_time) - end - end - end -end