Skip to content

Commit

Permalink
fix: add support for minimum_prices to tarifs
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Sep 30, 2024
1 parent a8305da commit ee7425b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/tarifs/group_minimum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/models/tarifs/group_minimum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit ee7425b

Please sign in to comment.