From 61dfe6e1f3486e5c3506c7807cc7f91bd8fdbeee Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 2 Jul 2015 17:49:40 +0300 Subject: [PATCH] Add period unit support to domain price method #2741 --- app/models/domain.rb | 7 ++++++- spec/models/domain_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 6203fe2f4..1800c98ec 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -374,7 +374,12 @@ class Domain < ActiveRecord::Base def price(operation) zone = name.split('.').drop(1).join('.') - p = "#{self.period}year" + + p = period / 365 if period_unit == 'd' + p = period / 12 if period_unit == 'm' + p = period if period_unit == 'y' + + p = "#{p}year" Pricelist.price_for(zone, operation, p) end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 380b907e5..41b0970e7 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -182,6 +182,26 @@ describe Domain do @domain.force_delete_at.should be_nil end + it 'should know its price' do + Fabricate(:pricelist, { + category: 'ee', + operation_category: 'create', + duration: '1year', + price: 1.50, + valid_from: Time.zone.parse('2015-01-01'), + valid_to: nil + }) + + domain = Fabricate(:domain) + domain.price('create').should == 1.50 + + domain = Fabricate(:domain, period: 12, period_unit: 'm') + domain.price('create').should == 1.50 + + domain = Fabricate(:domain, period: 365, period_unit: 'd') + domain.price('create').should == 1.50 + end + context 'about registrant update confirm' do before :all do @domain.registrant_verification_token = 123