Skip to content

Commit

Permalink
renane method and use new display only if newly calculated data present
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Sep 30, 2024
1 parent 20b4e12 commit 704dae9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Charge < ApplicationRecord

scope :pay_in_advance, -> { where(pay_in_advance: true) }

def simple_percentage?
def basic_rate_percentage?
return false unless percentage?

properties.keys == ['rate']
Expand Down
4 changes: 2 additions & 2 deletions app/views/templates/invoices/v4/charge.slim
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ html
td.body-2 = I18n.t('invoice.amount')
- fees.order(:succeeded_at, :created_at).each do |fee|
tr
- if fee.charge.percentage?
- if fee.charge.simple_percentage?
- if fee.charge.percentage? && fee.amount_details.present?
- if fee.charge.basic_rate_percentage?
tr
td.body-1
= fee.invoice_name + FeeDisplayHelper.grouped_by_display(fee)
Expand Down
8 changes: 4 additions & 4 deletions spec/models/charge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,17 @@
end
end

describe '#simple_percentage?' do
describe '#basic_rate_percentage?' do
it 'returns false if charge model is not percentage' do
expect(build(:standard_charge)).not_to be_simple_percentage
expect(build(:standard_charge)).not_to basic_rate_percentage
end

it 'returns false if charge model is percentage but has other properties except rate' do
expect(build(:charge, charge_model: 'percentage', properties: {fixed_amount: '20'})).not_to be_simple_percentage
expect(build(:charge, charge_model: 'percentage', properties: {fixed_amount: '20'})).not_to basic_rate_percentage
end

it 'returns true only if properties of percentage charge contain only rate' do
expect(build(:charge, charge_model: 'percentage', properties: {rate: '0.20'})).to be_simple_percentage
expect(build(:charge, charge_model: 'percentage', properties: {rate: '0.20'})).to basic_rate_percentage
end
end
end

0 comments on commit 704dae9

Please sign in to comment.