Skip to content

Commit

Permalink
Fix fixed-rates calculation when missing cb fields
Browse files Browse the repository at this point in the history
This if branch is very rare. And we do not set `metric_value` in it,
that means it takes metric_value from the previous loop or crashes.

Introduced in f3506b7.
  • Loading branch information
isimluk committed Nov 21, 2016
1 parent ad93833 commit bf417fc
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class ChargebackRateDetail < ApplicationRecord
def charge(relevant_fields, chargeback_fields_present, metric_rollup_records, hours_in_interval)
result = {}
if (relevant_fields & [metric_keys[0], cost_keys[0]]).present?
metric_value, cost = metric_and_cost_by(metric_rollup_records, hours_in_interval)
if !chargeback_fields_present && fixed?
cost = 0
else
metric_value, cost = metric_and_cost_by(metric_rollup_records, hours_in_interval)
end
metric_keys.each { |field| result[field] = metric_value }
cost_keys.each { |field| result[field] = cost }
Expand Down

0 comments on commit bf417fc

Please sign in to comment.