From dd48bb61d910020fb292660c46875979c9d96121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 10:44:18 +0300 Subject: [PATCH] Verify ref_number_from_description return correct match --- app/models/bank_transaction.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 0370ad666..a610b41f8 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -118,7 +118,11 @@ class BankTransaction < ApplicationRecord def ref_number_from_description (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| - break match if match.length == 7 || Billing::ReferenceNo.valid?(match) + break match if match.length == 7 || valid_ref_no?(match) end end + + def valid_ref_no?(match) + return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match).any? + end end