Skip to content

Commit

Permalink
Mapping failing when having nil values in data (#185)
Browse files Browse the repository at this point in the history
Fixes #184
  • Loading branch information
lmatayoshi authored Jul 2, 2020
1 parent ca38d2a commit 790dd68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/ona_transformation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def self.facility_categories(facility_data, categories, mappings)

false_match = false
false_values.each do |false_v|
false_match = false_match || mapping_value.include?(false_v)
false_match = false_match || (!mapping_value.nil? && mapping_value.include?(false_v))
end

if !false_match
true_match = false
true_values.each do |true_v|
true_match = true_match || mapping_value.include?(true_v)
true_match = true_match || (!mapping_value.nil? && mapping_value.include?(true_v))
end

if true_values.length == 0 || true_match
Expand Down
19 changes: 19 additions & 0 deletions spec/ona_transformation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,23 @@ def mappings_data_sample
["1", "category_id_1"]
])
end

it "allows data to be nil for a mapped field" do
facility_data = [
["id", "fac_field_1", "fac_field_2", "fac_field_3"],
["1", nil, "value_1_2", "value_1_3"]
]

categories = categories_data_sample

mappings = [
MAPPINGS_HEADER,
["category_id_1", "fac_field_1", "", "no result"]
]
expect(OnaTransformation.facility_categories(facility_data, categories, mappings))
.to eq([
FACILITY_CATEGORIES_HEADER,
["1", "category_id_1"]
])
end
end

0 comments on commit 790dd68

Please sign in to comment.