From 3ed4bdaff8fa62e34f5c7ea0eb9e46e2f6f14be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 23 Oct 2020 15:31:25 +0200 Subject: [PATCH] Return no variants when document_number is blank Otherwise the variants returned for document_type="1" and document_number="" will be `["0", "00", "000", "0000", "00000", "000000", "0000000", "00000000"]` which seems to be useless. --- lib/document_parser.rb | 2 ++ spec/lib/document_parser_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/document_parser.rb b/lib/document_parser.rb index 60ebd9d59..7fd4cc92f 100644 --- a/lib/document_parser.rb +++ b/lib/document_parser.rb @@ -1,5 +1,7 @@ module DocumentParser def get_document_number_variants(document_type, document_number) + return [] if document_number.blank? + # Delete all non-alphanumerics document_number = document_number.to_s.gsub(/[^0-9A-Za-z]/i, "") variants = [] diff --git a/spec/lib/document_parser_spec.rb b/spec/lib/document_parser_spec.rb index d44f8c5f0..476f3e2ee 100644 --- a/spec/lib/document_parser_spec.rb +++ b/spec/lib/document_parser_spec.rb @@ -3,6 +3,10 @@ include DocumentParser describe DocumentParser do describe "#get_document_number_variants" do + it "returns no variants when document_number is not defined" do + expect(DocumentParser.get_document_number_variants("1", "")).to be_empty + end + it "trims and cleans up entry" do expect(DocumentParser.get_document_number_variants(2, " 1 2@ 34")).to eq(["1234"]) end