From 4f9d9bf593d8fdafc927feed1d1d1c14c2a5b2ca Mon Sep 17 00:00:00 2001 From: Dan Drinkard Date: Tue, 7 Jul 2020 09:31:20 -0400 Subject: [PATCH 1/2] regression: handle empty quotes in fallback response --- lib/vertex_client/responses/quotation_fallback.rb | 2 +- test/responses/quotation_fallback_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/vertex_client/responses/quotation_fallback.rb b/lib/vertex_client/responses/quotation_fallback.rb index 5cb0e17..0b96107 100644 --- a/lib/vertex_client/responses/quotation_fallback.rb +++ b/lib/vertex_client/responses/quotation_fallback.rb @@ -11,7 +11,7 @@ def subtotal end def total_tax - @total_tax ||= line_items.sum(&:total_tax).round(2, :half_even) + @total_tax ||= line_items.sum(&:total_tax).to_d.round(2, :half_even) end def total diff --git a/test/responses/quotation_fallback_test.rb b/test/responses/quotation_fallback_test.rb index 219f355..5bf966a 100644 --- a/test/responses/quotation_fallback_test.rb +++ b/test/responses/quotation_fallback_test.rb @@ -18,6 +18,11 @@ it 'is the sum of price from line_items' do assert_equal 135.5, response.subtotal.to_f end + + it 'handles empty quotes' do + working_quote_params[:line_items] = [] + assert_equal 0.0, response.subtotal.to_f + end end describe 'total_tax' do @@ -25,6 +30,11 @@ it 'is the sum of total_tax from line_items' do assert_equal 8.66, response.total_tax.to_f end + + it 'handles empty quotes' do + working_quote_params[:line_items] = [] + assert_equal 0.0, response.total_tax.to_f + end end describe 'for EU customer' do From 31c9813c727f74b26f785e5519bc077c46bfbdc2 Mon Sep 17 00:00:00 2001 From: Dan Drinkard Date: Tue, 7 Jul 2020 09:32:37 -0400 Subject: [PATCH 2/2] Update changelog with bugfix --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6283946..32ec317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,16 @@ This file tracks all the changes (https://keepachangelog.com/en/1.0.0/) made to the client. This allows parsers such as Dependabot to provide a clean overview in pull requests. -## [v0.9.2] - 2020-07-06 +## [v0.9.2] - 2020-07-07 #### Added - Quotation, Invoice and DistributeTax payloads now accept a `:tax_only_adjustment` param to make tax adjustments that need not be correlated with a total cost adjustment +#### Changed + +- Fix a bug with fallback quotation responses where an empty set of line items would raise `ArgumentError` + ## [v0.9.1] - 2020-03-24 #### Added