mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
Refactor validity dates to model
This commit is contained in:
parent
4c4edd3747
commit
80440d741b
5 changed files with 22 additions and 14 deletions
|
@ -6,11 +6,7 @@ class Admin::DomainsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@domain = Domain.new({
|
||||
valid_from: Date.today,
|
||||
valid_to: Date.today + 1.year,
|
||||
registered_at: Time.zone.now
|
||||
}.merge(domain_params))
|
||||
@domain = Domain.new(domain_params)
|
||||
|
||||
if @domain.save
|
||||
redirect_to [:admin, @domain]
|
||||
|
@ -48,7 +44,7 @@ class Admin::DomainsController < ApplicationController
|
|||
end
|
||||
|
||||
def domain_params
|
||||
params.require(:domain).permit(:name, :period, :registrar_id, :owner_contact_id)
|
||||
params.require(:domain).permit(:name, :period, :period_unit, :registrar_id, :owner_contact_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -106,9 +106,7 @@ module Epp::DomainsHelper
|
|||
registrar_id: current_epp_user.registrar.try(:id),
|
||||
registered_at: Time.now,
|
||||
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
|
||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y',
|
||||
valid_from: Date.today,
|
||||
valid_to: valid_to
|
||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class Domain < ActiveRecord::Base
|
|||
delegate :name, to: :registrar, prefix: true
|
||||
|
||||
before_create :generate_auth_info
|
||||
before_create :set_validity_dates
|
||||
after_create :attach_default_contacts
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
|
@ -112,6 +113,12 @@ class Domain < ActiveRecord::Base
|
|||
admin_contacts << owner_contact if admin_contacts_count.zero? && owner_contact.citizen?
|
||||
end
|
||||
|
||||
def set_validity_dates
|
||||
self.registered_at = Time.zone.now
|
||||
self.valid_from = Date.today
|
||||
self.valid_to = valid_from + self.class.convert_period_to_time(period, period_unit)
|
||||
end
|
||||
|
||||
def tech_contacts_count
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }.count
|
||||
end
|
||||
|
|
|
@ -11,7 +11,11 @@
|
|||
= f.text_field(:name, class: 'form-control')
|
||||
.form-group
|
||||
= f.label :period
|
||||
.row
|
||||
.col-md-6
|
||||
= f.text_field(:period, class: 'form-control')
|
||||
.col-md-6
|
||||
= f.select :period_unit, options_for_select(['y', 'm', 'd'], @domain.period_unit), {}, {class: 'form-control'}
|
||||
.col-md-6
|
||||
.form-group.has-feedback
|
||||
= f.label :registrar
|
||||
|
|
|
@ -323,10 +323,12 @@ describe 'EPP Domain', epp: true do
|
|||
before(:each) { Fabricate(:domain, name: 'example.ee', registrar: EppUser.first.registrar) }
|
||||
|
||||
it 'renews a domain' do
|
||||
response = epp_request(domain_renew_xml, :xml)
|
||||
exp_date = (Date.today + 1.year)
|
||||
xml = domain_renew_xml(curExpDate: exp_date.to_s)
|
||||
response = epp_request(xml, :xml)
|
||||
ex_date = response[:parsed].css('renData exDate').text
|
||||
name = response[:parsed].css('renData name').text
|
||||
expect(ex_date).to eq('2015-08-07 00:00:00 UTC')
|
||||
expect(ex_date).to eq("#{(exp_date + 1.year)} 00:00:00 UTC")
|
||||
expect(name).to eq('example.ee')
|
||||
end
|
||||
|
||||
|
@ -339,7 +341,8 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'returns an error when period is invalid' do
|
||||
xml = domain_renew_xml(period_value: 4)
|
||||
exp_date = (Date.today + 1.year)
|
||||
xml = domain_renew_xml(period_value: 4, curExpDate: exp_date.to_s)
|
||||
|
||||
response = epp_request(xml, :xml)
|
||||
expect(response[:results][0][:result_code]).to eq('2004')
|
||||
|
@ -554,7 +557,7 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'deletes domain' do
|
||||
expect(DomainContact.count).to eq(1)
|
||||
expect(DomainContact.count).to eq(2)
|
||||
response = epp_request(domain_delete_xml, :xml)
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue