From 9e1aabe6d39f49461d6d21f730ad2a74cdc596e6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 3 Jul 2015 17:55:31 +0300 Subject: [PATCH] Add tests #2741 --- app/models/domain.rb | 6 +++--- spec/epp/domain_spec.rb | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index a39f7b8da..ae81ce474 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -146,9 +146,9 @@ class Domain < ActiveRecord::Base class << self def convert_period_to_time(period, unit) - return period.to_i.days if unit == 'd' - return period.to_i.months if unit == 'm' - return period.to_i.years if unit == 'y' + return (period.to_i / 365).years if unit == 'd' + return (period.to_i / 12).years if unit == 'm' + return period.to_i.years if unit == 'y' end def included diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index a3460db90..a94254b57 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -20,6 +20,8 @@ describe 'EPP Domain', epp: true do Fabricate(:reserved_domain) Fabricate(:blocked_domain) Fabricate(:pricelist, valid_to: nil) + Fabricate(:pricelist, duration: '2years', price: 20, valid_to: nil) + Fabricate(:pricelist, duration: '3years', price: 30, valid_to: nil) Fabricate(:pricelist, operation_category: 'renew', price: 15, valid_to: nil) @uniq_no = proc { @i ||= 0; @i += 1 } @@ -341,7 +343,7 @@ describe 'EPP Domain', epp: true do it 'creates a domain with period in days' do old_balance = @registrar1.balance old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml(period_value: 365, period_unit: 'd') + xml = domain_create_xml(period: { value: '365', attrs: { unit: 'd' }}) response = epp_plain_request(xml) response[:msg].should == 'Command completed successfully' @@ -354,6 +356,38 @@ describe 'EPP Domain', epp: true do a.sum.should == -BigDecimal.new('10.0') end + it 'creates a domain with longer periods' do + old_balance = @registrar1.balance + old_activities = @registrar1.cash_account.account_activities.count + xml = domain_create_xml(period: { value: '2', attrs: { unit: 'y' }}) + + response = epp_plain_request(xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + Domain.last.valid_to.should be_within(60).of(2.years.since) + @registrar1.balance.should be < old_balance + @registrar1.cash_account.account_activities.count.should == old_activities + 1 + a = @registrar1.cash_account.account_activities.last + a.description.should == "Create #{Domain.last.name}" + a.sum.should == -BigDecimal.new('20.0') + end + + it 'creates a domain with longer periods' do + old_balance = @registrar1.balance + old_activities = @registrar1.cash_account.account_activities.count + xml = domain_create_xml(period: { value: '36', attrs: { unit: 'm' }}) + + response = epp_plain_request(xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + Domain.last.valid_to.should be_within(60).of(3.years.since) + @registrar1.balance.should be < old_balance + @registrar1.cash_account.account_activities.count.should == old_activities + 1 + a = @registrar1.cash_account.account_activities.last + a.description.should == "Create #{Domain.last.name}" + a.sum.should == -BigDecimal.new('30.0') + end + it 'does not create a domain with invalid period' do old_balance = @registrar1.balance old_activities = @registrar1.cash_account.account_activities.count