From eecca8ee96b3f88a065e8accfbe3895f8bc637e4 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 24 Nov 2023 12:41:02 +1100 Subject: [PATCH] Refactor: match url with regexp And remove unnecessary button click. --- spec/system/admin/orders_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index bd313ee5de..20c56ac4ab 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -574,12 +574,12 @@ describe ' context "can bulk print invoices" do def extract_pdf_content - pdf_href = page.all('a').pluck('href') - page.find(class: "button", text: "VIEW FILE").click - invoice_file_number = pdf_href[0][45..59] - invoice_path = "tmp/invoices/#{invoice_file_number}.pdf" - reader = PDF::Reader.new(invoice_path) + # Extract last part of invoice URL + link = page.find(class: "button", text: "VIEW FILE") + filename = link[:href].match %r{/invoices/.*} + # Load invoice temp file directly instead of downloading + reader = PDF::Reader.new("tmp/#{filename}.pdf") reader.pages.map(&:text) end