Skip to content

Commit

Permalink
fix currency support in bill_data
Browse files Browse the repository at this point in the history
According to the documentation, `currency` can be specified within
the `bill_data`, but previously, it had no impact since 'CHF' was
hardcoded. This fix utilizes the currency value and defaults to
'CHF' when the currency is no specified.
  • Loading branch information
franco committed Apr 12, 2024
1 parent 3728796 commit 3332c44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/prawn/swiss_qr_bill/sections/payment_amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def draw_currency
doc.bounding_box([doc.bounds.left, doc.bounds.top],
width: CURRENCY_WIDTH, height: specs.height) do
label I18n.t('currency', scope: i18n_scope)
content 'CHF'
content @data.fetch(:currency, 'CHF')
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/swiss_qr_bill/sections/receipt_amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def draw_currency
doc.bounding_box([doc.bounds.left, doc.bounds.top],
width: CURRENCY_WIDTH, height: specs.height) do
doc.pad_top(1.4) { label I18n.t('currency', scope: i18n_scope) }
doc.pad_top(2.5) { content 'CHF' }
doc.pad_top(2.5) { content @data.fetch(:currency, 'CHF') }
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/features/pdf_generation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@
expect(reader_for_bill.pages.length).to eq(1)
end
end

context 'when currency EUR' do
let(:bill_data) { DataManager.build_bill(:default).merge(currency: 'EUR') }

it 'generates a correct pdf' do
expect(reader_for_bill.pages[0].text).to include('EUR').twice
end
end
end

0 comments on commit 3332c44

Please sign in to comment.