Skip to content

Commit

Permalink
No need to selectively filter blank fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kenfodder committed Sep 13, 2024
1 parent 98634bc commit 2384917
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
15 changes: 3 additions & 12 deletions app/models/claim/matching_attribute_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def matching_claims
# Claim attributes
CLAIM_ATTRIBUTE_GROUPS_TO_MATCH.each do |attributes|
vals = values_for_attributes(@source_claim, attributes)

next if vals.blank?

concatenated_columns = "CONCAT(#{attributes.join(",")})"
Expand All @@ -38,12 +37,10 @@ def matching_claims

# Eligibility attributes
eligibility_ids = eligibility_attributes_groups_to_match.map { |attributes|
present_attributes = attributes_for(@source_claim.eligibility, attributes).reject { |_, v| v.blank? }.map(&:first)
next if present_attributes.empty?

vals = values_for_attributes(@source_claim.eligibility, present_attributes)
concatenated_columns = "CONCAT(#{present_attributes.join(",")})"
vals = values_for_attributes(@source_claim.eligibility, attributes)
next if vals.blank?

concatenated_columns = "CONCAT(#{attributes.join(",")})"
policies_to_find_matches.map { |policy|
policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join)
}
Expand Down Expand Up @@ -81,11 +78,5 @@ def values_for_attributes(object, attributes)
object.read_attribute(attribute)
}.reject(&:blank?)
end

def attributes_for(object, attributes)
attributes.map { |attribute|
[attribute, object.read_attribute(attribute)]
}
end
end
end
32 changes: 32 additions & 0 deletions spec/models/claim/matching_attribute_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,36 @@

it { is_expected.to eq [other_claim] }
end

describe "matching_claims - blank trn, another field group with same contract type, blank provision_search" do
before do
stub_const("Policies::FurtherEducationPayments::ELIGIBILITY_MATCHING_ATTRIBUTES", [["teacher_reference_number"], ["provision_search", "contract_type"]])
end

let(:policy) { Policies::FurtherEducationPayments }

let!(:source_claim) {
eligibility = create(:further_education_payments_eligibility, :eligible, contract_type: "permanent", provision_search: nil)
create(
:claim,
:submitted,
policy: policy,
eligibility: eligibility
)
}

let!(:other_claim) {
eligibility = create(:further_education_payments_eligibility, :eligible, contract_type: "permanent", provision_search: nil)
create(
:claim,
:submitted,
policy: policy,
eligibility: eligibility
)
}

subject(:matching_claims) { Claim::MatchingAttributeFinder.new(source_claim).matching_claims }

it { is_expected.to eq [other_claim] }
end
end

0 comments on commit 2384917

Please sign in to comment.