Skip to content

Commit

Permalink
Fix test for Ruby version of sum method
Browse files Browse the repository at this point in the history
In Rails 7.1 the `sum` method no longer overrides `Enumerable#sum`. One change
is that there is no implicit conversion of nil to integer. When a fee is
cleared with `Fee::BaseFee#clear` the amount is set to nil and so
claim.basic_fees.sum(&:amount) fails.

It might be appropriate to change `Fee::BaseFee#clear` so that the values
are set to zero instead of nil. However, this may have other side-effects.
  • Loading branch information
jrmhaig committed Jan 9, 2025
1 parent 541331a commit 94d12e1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spec/services/cleaners/advocate_claim_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
RSpec.shared_examples 'clear basic fees' do
it { expect { call_cleaner }.not_to change { claim.basic_fees.size } }
it { expect { call_cleaner }.to change { claim.basic_fees.flat_map(&:dates_attended).size }.to 0 }
it { expect { call_cleaner }.to change { claim.basic_fees.sum(&:amount) }.to 0 }
it { expect { call_cleaner }.to change { claim.basic_fees.sum { |fee| fee.amount.to_i } }.to 0 }
end

RSpec.shared_examples 'does not clear basic fees' do
Expand Down

0 comments on commit 94d12e1

Please sign in to comment.