Skip to content

Commit

Permalink
Merge pull request #563 from dxw/fix/1165-support-cols-headed-by-inte…
Browse files Browse the repository at this point in the history
…gers-in-multi-column-mgmt-charge-calc

(fix) Support integer column headings in mgnmt charge calculation
  • Loading branch information
edavey authored Dec 6, 2019
2 parents bf0de8d + 6471bb7 commit 4ae9bf0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(varies_by:, value_to_percentage:)
end

def calculate_for(entry)
column_names_for_entry = Array(varies_by).map { |column| entry.data.dig(column).downcase }
column_names_for_entry = Array(varies_by).map { |column| entry.data.dig(column).to_s.downcase }
percentage = percentage_for(column_names_for_entry)

if percentage.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
expect(calculator.calculate_for(entry)).to eq(6.1725) # 5% of 123.45
end

it 'handles column values that are integers' do
entry = FactoryBot.create(:submission_entry, total_value: 123.45, data: { test_value: 1 })

calculator = Framework::ManagementChargeCalculator::ColumnBased.new(
varies_by: 'test_value',
value_to_percentage: {
'1': BigDecimal('5')
}
)

expect(calculator.calculate_for(entry)).to eq(6.1725) # 5% of 123.45
end

it 'rounds to four decimal places' do
entry = FactoryBot.create(:submission_entry, total_value: 42.424242, data: { test_value: 'test' })

Expand Down

0 comments on commit 4ae9bf0

Please sign in to comment.