Skip to content

Commit

Permalink
Split test cases for hourly rate
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Jan 2, 2017
1 parent 09cecec commit 4f7e02c
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions spec/models/chargeback_rate_detail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,42 @@
expect(cbd.hourly_cost(cvalue, consumption)).to eq(0.0)
end

it "#hourly" do
[
0,
0.0,
0.00
].each do |rate|
cbd = FactoryGirl.build(:chargeback_rate_detail, :per_time => 'hourly')
describe '#hourly (rate)' do
let(:rate) { 8.26 }
it 'returns 0 when the rate was 0' do
[
0,
0.0,
0.00
].each do |zero|
cbd = FactoryGirl.build(:chargeback_rate_detail, :per_time => 'hourly')
expect(cbd.hourly(zero, consumption)).to eq(0.0)
end
end

expect(cbd.hourly(rate, consumption)).to eq(0.0)
it 'calculates hourly rate for given rate' do
cbdm = FactoryGirl.create(:chargeback_rate_detail_measure)
[
'hourly', 'megabytes', rate,
'daily', 'megabytes', rate / 24,
'weekly', 'megabytes', rate / 24 / 7,
'monthly', 'megabytes', rate / 24 / 30,
'yearly', 'megabytes', rate / 24 / 365
].each_slice(3) do |per_time, per_unit, hourly_rate|
cbd = FactoryGirl.build(:chargeback_rate_detail,
:per_time => per_time,
:per_unit => per_unit,
:metric => 'derived_memory_available',
:chargeback_rate_detail_measure_id => cbdm.id)
expect(cbd.hourly(rate, consumption)).to eq(hourly_rate)
end
end
cbdm = FactoryGirl.create(:chargeback_rate_detail_measure)
rate = 8.26
[
'hourly', 'megabytes', rate,
'daily', 'megabytes', rate / 24,
'weekly', 'megabytes', rate / 24 / 7,
'monthly', 'megabytes', rate / 24 / 30,
'yearly', 'megabytes', rate / 24 / 365
].each_slice(3) do |per_time, per_unit, hourly_rate|
cbd = FactoryGirl.build(:chargeback_rate_detail,
:per_time => per_time,
:per_unit => per_unit,
:metric => 'derived_memory_available',
:chargeback_rate_detail_measure_id => cbdm.id)
expect(cbd.hourly(rate, consumption)).to eq(hourly_rate)

let(:annual_rate) { FactoryGirl.build(:chargeback_rate_detail, :per_time => 'annually') }
it 'cannot calculate for unknown time interval' do
expect { annual_rate.hourly(rate, consumption) }.to raise_error(RuntimeError,
"rate time unit of 'annually' not supported")
end
cbd = FactoryGirl.build(:chargeback_rate_detail, :per_time => 'annually')
expect { cbd.hourly(rate, consumption) }.to raise_error(RuntimeError, "rate time unit of 'annually' not supported")
end

it "#rate_adjustment" do
Expand Down

0 comments on commit 4f7e02c

Please sign in to comment.