diff --git a/app/models/ona_transformation.rb b/app/models/ona_transformation.rb index 6f9c5ca..371b199 100644 --- a/app/models/ona_transformation.rb +++ b/app/models/ona_transformation.rb @@ -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 diff --git a/spec/ona_transformation_spec.rb b/spec/ona_transformation_spec.rb index c35a8d6..7d21556 100644 --- a/spec/ona_transformation_spec.rb +++ b/spec/ona_transformation_spec.rb @@ -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