From f6eb2ebdad044b4c8bb32053ab102e7a8fbdce53 Mon Sep 17 00:00:00 2001 From: Mitosch Date: Tue, 7 May 2024 10:14:03 -0600 Subject: [PATCH] add specs, update version and changelog --- CHANGELOG.md | 4 ++ Gemfile.lock | 2 + lib/prawn/swiss_qr_bill/version.rb | 2 +- prawn-swiss_qr_bill.gemspec | 2 + spec/features/pdf_generation_spec.rb | 20 ++++++++- spec/prawn/swiss_qr_bill/qr/data_spec.rb | 29 +++++++++++++ .../sections/payment_amount_spec.rb | 7 ++++ spec/support/bill_data.yml | 41 +++++++++++++++++++ 8 files changed, 104 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0bc3fc..4d3734a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ * no changes +### 0.5.3 - 2024-05-07 + +* Fix bug where currency could not be set to EUR. Thanks to @franco. + ### 0.5.2 - 2022-08-25 * Add additional information (unstructured_message, bill_information). Thanks to @noefroidevaux. diff --git a/Gemfile.lock b/Gemfile.lock index adeca8a..cc17222 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: prawn-swiss_qr_bill (0.5.2) i18n (~> 1.8) + matrix (~> 0.4) prawn (~> 2.0) rqrcode (~> 2.0) @@ -19,6 +20,7 @@ GEM hashery (2.1.2) i18n (1.12.0) concurrent-ruby (~> 1.0) + matrix (0.4.2) parallel (1.21.0) parser (3.1.0.0) ast (~> 2.4.1) diff --git a/lib/prawn/swiss_qr_bill/version.rb b/lib/prawn/swiss_qr_bill/version.rb index 0e64f2d..3174789 100644 --- a/lib/prawn/swiss_qr_bill/version.rb +++ b/lib/prawn/swiss_qr_bill/version.rb @@ -2,6 +2,6 @@ module Prawn module SwissQRBill - VERSION = '0.5.2' + VERSION = '0.5.3' end end diff --git a/prawn-swiss_qr_bill.gemspec b/prawn-swiss_qr_bill.gemspec index 57558cd..5982744 100644 --- a/prawn-swiss_qr_bill.gemspec +++ b/prawn-swiss_qr_bill.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'i18n', '~> 1.8' spec.add_dependency 'prawn', '~> 2.0' + spec.add_dependency 'matrix', '~> 0.4' spec.add_dependency 'rqrcode', '~> 2.0' spec.add_development_dependency 'pdf-reader', '~> 2.3' @@ -34,6 +35,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'simplecov', '~> 0.16' spec.add_development_dependency 'simplecov-cobertura', '~> 2.0' + spec.metadata = { 'rubygems_mfa_required' => 'true' } diff --git a/spec/features/pdf_generation_spec.rb b/spec/features/pdf_generation_spec.rb index 092c7b6..ffeb60e 100644 --- a/spec/features/pdf_generation_spec.rb +++ b/spec/features/pdf_generation_spec.rb @@ -91,8 +91,24 @@ end end - context 'when currency EUR' do - let(:bill_data) { DataManager.build_bill(:default).merge(currency: 'EUR') } + context 'when currency is CHF' do + let(:bill_data) { DataManager.build_bill } + + it 'generates a correct pdf' do + expect(reader_for_bill.pages[0].text).to include('CHF').twice + end + end + + context 'when no currency' do + let(:bill_data) { DataManager.build_bill(:no_currency) } + + it 'generates a correct pdf' do + expect(reader_for_bill.pages[0].text).to include('CHF').twice + end + end + + context 'when currency is EUR' do + let(:bill_data) { DataManager.build_bill(:currency_eur) } it 'generates a correct pdf' do expect(reader_for_bill.pages[0].text).to include('EUR').twice diff --git a/spec/prawn/swiss_qr_bill/qr/data_spec.rb b/spec/prawn/swiss_qr_bill/qr/data_spec.rb index bd265d9..06662ba 100644 --- a/spec/prawn/swiss_qr_bill/qr/data_spec.rb +++ b/spec/prawn/swiss_qr_bill/qr/data_spec.rb @@ -2,6 +2,8 @@ describe Prawn::SwissQRBill::QR::Data do let(:bill_data) { DataManager.build_bill(:default, flat: true) } + let(:bill_data_no_currency) { DataManager.build_bill(:no_currency, flat: true) } + let(:bill_data_currency_eur) { DataManager.build_bill(:currency_eur, flat: true) } describe '.new' do it 'initializes the qr data with defaults' do @@ -119,5 +121,32 @@ expect(qr_data.reference).to eq('000000000000022022020299991') end end + + context 'with currency CHF' do + it 'generates data with CHF' do + qr_data = described_class.new(bill_data) + qr_data_string = qr_data.generate + qr_data_array = qr_data_string.split("\r\n") + expect(qr_data_array[19]).to eq('CHF') + end + end + + context 'without currency' do + it 'generates data with CHF' do + qr_data = described_class.new(bill_data_no_currency) + qr_data_string = qr_data.generate + qr_data_array = qr_data_string.split("\r\n") + expect(qr_data_array[19]).to eq('CHF') + end + end + + context 'with currency EUR' do + it 'generates data with EUR' do + qr_data = described_class.new(bill_data_currency_eur) + qr_data_string = qr_data.generate + qr_data_array = qr_data_string.split("\r\n") + expect(qr_data_array[19]).to eq('EUR') + end + end end end diff --git a/spec/prawn/swiss_qr_bill/sections/payment_amount_spec.rb b/spec/prawn/swiss_qr_bill/sections/payment_amount_spec.rb index 724478a..61ba90e 100644 --- a/spec/prawn/swiss_qr_bill/sections/payment_amount_spec.rb +++ b/spec/prawn/swiss_qr_bill/sections/payment_amount_spec.rb @@ -5,6 +5,7 @@ let(:document) { Prawn::Document.new } let(:bill_data) { DataManager.build_bill } let(:bill_data_no_amount) { DataManager.build_bill(:no_amount) } + let(:bill_data_no_currency) { DataManager.build_bill(:no_currency) } describe '.new' do it 'initializes the section' do @@ -24,5 +25,11 @@ described_class.new(document, bill_data_no_amount).draw end end + + context 'when currency is not given' do + it 'draws currency as CHF and a corner box for amount' do + described_class.new(document, bill_data_no_currency).draw + end + end end end diff --git a/spec/support/bill_data.yml b/spec/support/bill_data.yml index 349be7a..26bcdd8 100644 --- a/spec/support/bill_data.yml +++ b/spec/support/bill_data.yml @@ -44,6 +44,47 @@ bill_data: reference_type: QRR unstructured_message: Auftrag vom 15.06.2020 bill_information: //S1/10/10201409/11/170309/20/14000000/30/106017086 + no_currency: + creditor: + iban: CH08 3080 8004 1110 4136 9 + address: + name: Mischa Schindowski + line1: Schybenächerweg 553 + postal_code: 5324 + city: Full-Reuenthal + country: CH + debtor: + address: + name: Simon Muster + line1: Musterstrasse 1 + postal_code: 8000 + city: Zürich + country: CH + reference: 00 00000 00000 02202 20202 99991 + reference_type: QRR + unstructured_message: Auftrag vom 15.06.2020 + bill_information: //S1/10/10201409/11/170309/20/14000000/30/106017086 + currency_eur: + creditor: + iban: CH08 3080 8004 1110 4136 9 + address: + name: Mischa Schindowski + line1: Schybenächerweg 553 + postal_code: 5324 + city: Full-Reuenthal + country: CH + debtor: + address: + name: Simon Muster + line1: Musterstrasse 1 + postal_code: 8000 + city: Zürich + country: CH + currency: EUR + reference: 00 00000 00000 02202 20202 99991 + reference_type: QRR + unstructured_message: Auftrag vom 15.06.2020 + bill_information: //S1/10/10201409/11/170309/20/14000000/30/106017086 no_reference: creditor: iban: CH08 3080 8004 1110 4136 9