From cf00121563e28ba0f78fc1f126407fe90c383fe7 Mon Sep 17 00:00:00 2001 From: Thomas Burkhalter Date: Thu, 29 Feb 2024 00:15:28 +0100 Subject: [PATCH] Improve invoice_form_test --- test/integration/invoice_form_test.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/integration/invoice_form_test.rb b/test/integration/invoice_form_test.rb index 6498c5b1..51a21aef 100644 --- a/test/integration/invoice_form_test.rb +++ b/test/integration/invoice_form_test.rb @@ -43,13 +43,8 @@ class NewInvoiceTest < ActionDispatch::IntegrationTest end test 'sets calculated total on page load' do - expected_total = '%.2f' % (billable_hours * rate).round(2) - - text_on_page = - find('#invoice_total_amount') - .text - .delete("'") - .delete(''') + expected_total = delimited_number(billable_hours * rate) + text_on_page = find('#invoice_total_amount').text assert_match expected_total, text_on_page end @@ -213,4 +208,12 @@ def assert_checkboxes(checkboxes, models, checked = models) send assertion, checkboxes.find { |checkbox| checkbox.value == model.id.to_s }.checked? end end + + def delimited_number(number) + ActiveSupport::NumberHelper.number_to_rounded( + number, + precision: 2, + delimiter: "'" + ) + end end