mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 10:19:45 +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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@domain = Domain.new({
|
@domain = Domain.new(domain_params)
|
||||||
valid_from: Date.today,
|
|
||||||
valid_to: Date.today + 1.year,
|
|
||||||
registered_at: Time.zone.now
|
|
||||||
}.merge(domain_params))
|
|
||||||
|
|
||||||
if @domain.save
|
if @domain.save
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
|
@ -48,7 +44,7 @@ class Admin::DomainsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_params
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -106,9 +106,7 @@ module Epp::DomainsHelper
|
||||||
registrar_id: current_epp_user.registrar.try(:id),
|
registrar_id: current_epp_user.registrar.try(:id),
|
||||||
registered_at: Time.now,
|
registered_at: Time.now,
|
||||||
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
|
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
|
||||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y',
|
period_unit: Epp::EppDomain.parse_period_unit_from_frame(parsed_frame) || 'y'
|
||||||
valid_from: Date.today,
|
|
||||||
valid_to: valid_to
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Domain < ActiveRecord::Base
|
||||||
delegate :name, to: :registrar, prefix: true
|
delegate :name, to: :registrar, prefix: true
|
||||||
|
|
||||||
before_create :generate_auth_info
|
before_create :generate_auth_info
|
||||||
|
before_create :set_validity_dates
|
||||||
after_create :attach_default_contacts
|
after_create :attach_default_contacts
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
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?
|
admin_contacts << owner_contact if admin_contacts_count.zero? && owner_contact.citizen?
|
||||||
end
|
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
|
def tech_contacts_count
|
||||||
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }.count
|
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }.count
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,11 @@
|
||||||
= f.text_field(:name, class: 'form-control')
|
= f.text_field(:name, class: 'form-control')
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :period
|
= f.label :period
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
= f.text_field(:period, class: 'form-control')
|
= 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
|
.col-md-6
|
||||||
.form-group.has-feedback
|
.form-group.has-feedback
|
||||||
= f.label :registrar
|
= f.label :registrar
|
||||||
|
|
|
@ -323,10 +323,12 @@ describe 'EPP Domain', epp: true do
|
||||||
before(:each) { Fabricate(:domain, name: 'example.ee', registrar: EppUser.first.registrar) }
|
before(:each) { Fabricate(:domain, name: 'example.ee', registrar: EppUser.first.registrar) }
|
||||||
|
|
||||||
it 'renews a domain' do
|
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
|
ex_date = response[:parsed].css('renData exDate').text
|
||||||
name = response[:parsed].css('renData name').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')
|
expect(name).to eq('example.ee')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -339,7 +341,8 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an error when period is invalid' do
|
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)
|
response = epp_request(xml, :xml)
|
||||||
expect(response[:results][0][:result_code]).to eq('2004')
|
expect(response[:results][0][:result_code]).to eq('2004')
|
||||||
|
@ -554,7 +557,7 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes domain' do
|
it 'deletes domain' do
|
||||||
expect(DomainContact.count).to eq(1)
|
expect(DomainContact.count).to eq(2)
|
||||||
response = epp_request(domain_delete_xml, :xml)
|
response = epp_request(domain_delete_xml, :xml)
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue