diff --git a/app/models/tarifs/group_minimum.rb b/app/models/tarifs/group_minimum.rb index 269789561..e990bf460 100644 --- a/app/models/tarifs/group_minimum.rb +++ b/app/models/tarifs/group_minimum.rb @@ -55,7 +55,7 @@ def group_price(usage) end def group_used_units(usage) - usages_in_group(usage).sum(&:used_units) + usages_in_group(usage).sum { _1.used_units || 0 } end def minimum_prices_with_difference(usage) # rubocop:disable Metrics/AbcSize diff --git a/spec/models/tarifs/group_minimum_spec.rb b/spec/models/tarifs/group_minimum_spec.rb index 638fc6379..768160a40 100644 --- a/spec/models/tarifs/group_minimum_spec.rb +++ b/spec/models/tarifs/group_minimum_spec.rb @@ -53,9 +53,11 @@ let(:tarif) { create(:tarif, type: described_class.sti_name, price_per_unit:, organisation:, tarif_group:) } let(:other_tarif1) { create(:tarif, price_per_unit:, organisation:, tarif_group:) } let(:other_tarif2) { create(:tarif, price_per_unit: 12, organisation:, tarif_group:) } + let(:other_tarif3) { create(:tarif, price_per_unit: 0, organisation:, tarif_group:) } let!(:usage) { create(:usage, booking:, tarif:) } let!(:other_usage1) { create(:usage, booking:, tarif: other_tarif1, used_units: 7) } let!(:other_usage2) { create(:usage, booking:, tarif: other_tarif2, used_units: 8) } + let!(:other_usage3) { create(:usage, booking:, tarif: other_tarif3, used_units: nil) } describe '#minimum_prices' do subject(:minimum_prices) { tarif.minimum_prices_with_difference(usage) }