From 16d00c3e2e120ac0f9f4acf3cfda43910c480199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Tue, 25 Oct 2016 14:09:42 +0200 Subject: [PATCH] Rename cost to hourly_cost As it better describes what it does. It calculates hourly cost for a given metric. --- app/models/chargeback.rb | 2 +- app/models/chargeback_rate_detail.rb | 2 +- spec/models/chargeback_rate_detail_spec.rb | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/chargeback.rb b/app/models/chargeback.rb index d3c7b931990..d1bfacc1fd7 100644 --- a/app/models/chargeback.rb +++ b/app/models/chargeback.rb @@ -146,7 +146,7 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval) else r.hours_in_interval = hours_in_interval metric_value = r.metric_value_by(metric_rollup_records) - cost = r.cost(metric_value) * hours_in_interval + cost = r.hourly_cost(metric_value) * hours_in_interval end accumulate_metrics_and_costs_per_rate(r.rate_name, r.group, metric_value, cost) diff --git a/app/models/chargeback_rate_detail.rb b/app/models/chargeback_rate_detail.rb index 1941d376755..42a33750bd4 100644 --- a/app/models/chargeback_rate_detail.rb +++ b/app/models/chargeback_rate_detail.rb @@ -74,7 +74,7 @@ def find_rate(value) :yearly => "Year" } - def cost(value) + def hourly_cost(value) return 0.0 unless self.enabled? value = 1.0 if fixed? diff --git a/spec/models/chargeback_rate_detail_spec.rb b/spec/models/chargeback_rate_detail_spec.rb index 9d58ccf609a..af222988e05 100644 --- a/spec/models/chargeback_rate_detail_spec.rb +++ b/spec/models/chargeback_rate_detail_spec.rb @@ -26,7 +26,7 @@ let(:hours_in_month) { 720 } - it "#cost" do + it '#hourly_cost' do cvalue = 42.0 fixed_rate = 5.0 variable_rate = 8.26 @@ -46,13 +46,13 @@ :fixed_rate => fixed_rate, :variable_rate => variable_rate) cbd.update(:chargeback_tiers => [cbt]) - expect(cbd.cost(cvalue)).to eq(cvalue * cbd.hourly(variable_rate) + cbd.hourly(fixed_rate)) + expect(cbd.hourly_cost(cvalue)).to eq(cvalue * cbd.hourly(variable_rate) + cbd.hourly(fixed_rate)) cbd.group = 'fixed' - expect(cbd.cost(cvalue)).to eq(cbd.hourly(variable_rate) + cbd.hourly(fixed_rate)) + expect(cbd.hourly_cost(cvalue)).to eq(cbd.hourly(variable_rate) + cbd.hourly(fixed_rate)) cbd.enabled = false - expect(cbd.cost(cvalue)).to eq(0.0) + expect(cbd.hourly_cost(cvalue)).to eq(0.0) end it "#hourly" do @@ -195,7 +195,7 @@ :per_time => 'monthly', :chargeback_rate_detail_measure_id => cbdm.id, :hours_in_interval => hours_in_month) - expect(cbd_bytes.cost(100)).to eq(cbd_gigabytes.cost(100)) + expect(cbd_bytes.hourly_cost(100)).to eq(cbd_gigabytes.hourly_cost(100)) end it "#show_rates" do