Add method to return correct price for an operation #2741

This commit is contained in:
Martin Lensment 2015-07-02 13:06:58 +03:00
parent bdbf59e6d1
commit ec5a219456
2 changed files with 103 additions and 4 deletions

View file

@ -15,8 +15,8 @@ describe Pricelist do
it 'should not be valid' do
@pricelist.valid?
@pricelist.errors.full_messages.should match_array([
"Category is missing",
"Duration is missing",
"Category is missing",
"Duration is missing",
"Operation category is missing"
])
end
@ -36,7 +36,6 @@ describe Pricelist do
it 'should not have name' do
@pricelist.name.should == ' '
end
end
context 'with valid attributes' do
@ -69,4 +68,94 @@ describe Pricelist do
end
end
end
it 'should return correct price' do
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.50,
valid_from: Time.zone.parse('2198-01-01'),
valid_to: Time.zone.parse('2199-01-01')
})
expect { Pricelist.price_for('ee', 'create', '1year') }.to raise_error(NoMethodError)
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.50,
valid_from: Time.zone.parse('2015-01-01'),
valid_to: nil
})
Pricelist.price_for('ee', 'create', '1year').should == 1.50
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.30,
valid_from: Time.zone.parse('2015-01-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.30
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.20,
valid_from: Time.zone.parse('2015-06-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2014-01-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2999-02-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2015-06-02'),
valid_to: nil
})
Pricelist.price_for('ee', 'create', '1year').should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2015-07-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.price_for('ee', 'create', '1year').should == 1.10
end
end