Refactor debit and credit registrar to include pricelist id #2741

This commit is contained in:
Martin Lensment 2015-07-13 17:39:54 +03:00
parent 9fd38f161a
commit 75a6c27221
11 changed files with 80 additions and 123 deletions

View file

@ -193,13 +193,13 @@ describe Domain do
})
domain = Fabricate(:domain)
domain.price('create').should == 1.50
domain.pricelist('create').price.amount.should == 1.50
domain = Fabricate(:domain, period: 12, period_unit: 'm')
domain.price('create').should == 1.50
domain.pricelist('create').price.amount.should == 1.50
domain = Fabricate(:domain, period: 365, period_unit: 'd')
domain.price('create').should == 1.50
domain.pricelist('create').price.amount.should == 1.50
Fabricate(:pricelist, {
category: 'ee',
@ -211,13 +211,13 @@ describe Domain do
})
domain = Fabricate(:domain, period: 2)
domain.price('create').should == 3.0
domain.pricelist('create').price.amount.should == 3.0
domain = Fabricate(:domain, period: 24, period_unit: 'm')
domain.price('create').should == 3.0
domain.pricelist('create').price.amount.should == 3.0
domain = Fabricate(:domain, period: 730, period_unit: 'd')
domain.price('create').should == 3.0
domain.pricelist('create').price.amount.should == 3.0
Fabricate(:pricelist, {
category: 'ee',
@ -229,13 +229,13 @@ describe Domain do
})
domain = Fabricate(:domain, period: 3)
domain.price('create').should == 6.0
domain.pricelist('create').price.amount.should == 6.0
domain = Fabricate(:domain, period: 36, period_unit: 'm')
domain.price('create').should == 6.0
domain.pricelist('create').price.amount.should == 6.0
domain = Fabricate(:domain, period: 1095, period_unit: 'd')
domain.price('create').should == 6.0
domain.pricelist('create').price.amount.should == 6.0
end
it 'should know its renew price' do
@ -249,13 +249,13 @@ describe Domain do
})
domain = Fabricate(:domain)
domain.price('renew').should == 1.30
domain.pricelist('renew').price.amount.should == 1.30
domain = Fabricate(:domain, period: 12, period_unit: 'm')
domain.price('renew').should == 1.30
domain.pricelist('renew').price.amount.should == 1.30
domain = Fabricate(:domain, period: 365, period_unit: 'd')
domain.price('renew').should == 1.30
domain.pricelist('renew').price.amount.should == 1.30
Fabricate(:pricelist, {
category: 'ee',
@ -267,13 +267,13 @@ describe Domain do
})
domain = Fabricate(:domain, period: 2)
domain.price('renew').should == 3.1
domain.pricelist('renew').price.amount.should == 3.1
domain = Fabricate(:domain, period: 24, period_unit: 'm')
domain.price('renew').should == 3.1
domain.pricelist('renew').price.amount.should == 3.1
domain = Fabricate(:domain, period: 730, period_unit: 'd')
domain.price('renew').should == 3.1
domain.pricelist('renew').price.amount.should == 3.1
Fabricate(:pricelist, {
category: 'ee',
@ -285,13 +285,13 @@ describe Domain do
})
domain = Fabricate(:domain, period: 3)
domain.price('renew').should == 6.1
domain.pricelist('renew').price.amount.should == 6.1
domain = Fabricate(:domain, period: 36, period_unit: 'm')
domain.price('renew').should == 6.1
domain.pricelist('renew').price.amount.should == 6.1
domain = Fabricate(:domain, period: 1095, period_unit: 'd')
domain.price('renew').should == 6.1
domain.pricelist('renew').price.amount.should == 6.1
end
context 'about registrant update confirm' do

View file

@ -70,7 +70,7 @@ describe Pricelist do
end
it 'should return correct price' do
expect { Pricelist.price_for('ee', 'create', '1year') }.to raise_error(NoMethodError)
Pricelist.pricelist_for('ee', 'create', '1year').should == nil
Fabricate(:pricelist, {
category: 'ee',
@ -81,7 +81,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2199-01-01')
})
expect { Pricelist.price_for('ee', 'create', '1year') }.to raise_error(NoMethodError)
Pricelist.pricelist_for('ee', 'create', '1year').should == nil
Fabricate(:pricelist, {
category: 'ee',
@ -92,7 +92,7 @@ describe Pricelist do
valid_to: nil
})
Pricelist.price_for('ee', 'create', '1year').should == 1.50
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.50
Fabricate(:pricelist, {
category: 'ee',
@ -103,7 +103,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.30
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.30
Fabricate.create(:pricelist, {
category: 'ee',
@ -114,7 +114,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
@ -125,7 +125,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
@ -136,7 +136,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
@ -147,7 +147,7 @@ describe Pricelist do
valid_to: nil
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
@ -158,7 +158,7 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.10
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.10
Fabricate.create(:pricelist, {
category: 'ee',
@ -169,6 +169,6 @@ describe Pricelist do
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '2years').should == 1.20
Pricelist.pricelist_for('ee', 'create', '2years').price.amount.should == 1.20
end
end

View file

@ -146,14 +146,14 @@ describe Registrar do
end
it 'should credit and debit registrar cash account' do
@registrar.credit!(13.32, 'Add money')
@registrar.credit!({ sum: 13.32, description: 'Add money' })
@registrar.balance.should == BigDecimal.new('13.32')
@registrar.cash_account.account_activities.count.should == 1
a = @registrar.cash_account.account_activities.last
a.description.should == 'Add money'
a.sum.should == BigDecimal.new('13.32')
@registrar.debit!(10.31, 'Remove money')
@registrar.debit!({ sum: 10.31, description: 'Remove money' })
@registrar.balance.should == BigDecimal.new('3.01')
@registrar.cash_account.account_activities.count.should == 2
a = @registrar.cash_account.account_activities.last