From 3332c44938412a03678d3eeaabcc746775d80b19 Mon Sep 17 00:00:00 2001 From: Franco Sebregondi Date: Fri, 12 Apr 2024 15:56:46 -0500 Subject: [PATCH] fix currency support in bill_data 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. --- lib/prawn/swiss_qr_bill/sections/payment_amount.rb | 2 +- lib/prawn/swiss_qr_bill/sections/receipt_amount.rb | 2 +- spec/features/pdf_generation_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/prawn/swiss_qr_bill/sections/payment_amount.rb b/lib/prawn/swiss_qr_bill/sections/payment_amount.rb index 8f71950..7bb1d53 100644 --- a/lib/prawn/swiss_qr_bill/sections/payment_amount.rb +++ b/lib/prawn/swiss_qr_bill/sections/payment_amount.rb @@ -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 diff --git a/lib/prawn/swiss_qr_bill/sections/receipt_amount.rb b/lib/prawn/swiss_qr_bill/sections/receipt_amount.rb index cb0dac4..61648b3 100644 --- a/lib/prawn/swiss_qr_bill/sections/receipt_amount.rb +++ b/lib/prawn/swiss_qr_bill/sections/receipt_amount.rb @@ -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 diff --git a/spec/features/pdf_generation_spec.rb b/spec/features/pdf_generation_spec.rb index 1ca580d..092c7b6 100644 --- a/spec/features/pdf_generation_spec.rb +++ b/spec/features/pdf_generation_spec.rb @@ -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