Skip to content

Commit

Permalink
Fix facility headers validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lmatayoshi committed Jul 1, 2020
1 parent 1f575d5 commit ca38d2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/models/ona_transformation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def self.validate_mapping_headers!(headers)
end

def self.validate_facility_headers!(headers)
raise ArgumentError.new("ONA data.csv file must have a '_id' column containing the facility ids.") unless headers.map{|h| h.downcase}.include?("_id")
raise ArgumentError.new("ONA data.csv file must have an 'id' column containing the facility ids.") unless headers.map{|h| h.downcase}.include?("id")
headers
end

def self.facility_id_column_index(headers)
headers.find_index "_id"
headers.find_index "id"
end

def self.facility_categories(facility_data, categories, mappings)
Expand Down Expand Up @@ -98,4 +98,4 @@ def self.csv_enumerator(path)
def self.file_with_bom?(path)
File.open(path).each_byte.take(3) == [0xEF, 0xBB, 0xBF]
end
end
end
12 changes: 6 additions & 6 deletions spec/ona_transformation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe OnaTransformation do
def facility_data_sample
[
["_id", "fac_field_1", "fac_field_2", "fac_field_3"],
["id", "fac_field_1", "fac_field_2", "fac_field_3"],
["1", "value_1_1", "value_1_2", "value_1_3"]
]
end
Expand Down Expand Up @@ -186,19 +186,19 @@ def mappings_data_sample
OnaTransformation.facility_categories(facility_data, categories, mappings)
end

it "validates there is an _id column in data file" do
it "validates there is an 'id' column in data file" do
facility_data = [["facility_id", "fac_field_1", "fac_field_2", "fac_field_3"]]
categories = categories_data_sample
mappings = mappings_data_sample

expect {OnaTransformation.facility_categories(facility_data, categories, mappings)}
.to raise_error(ArgumentError,
"ONA data.csv file must have a '_id' column containing the facility ids.")
"ONA data.csv file must have an 'id' column containing the facility ids.")
end

it "grabs facility ids from the _id column" do
it "grabs facility ids from the 'id' column" do
facility_data = [
["fac_field_1", "fac_field_2", "_id", "fac_field_3"],
["fac_field_1", "fac_field_2", "id", "fac_field_3"],
["value_1_1", "value_1_2", "1", "value_1_3"]
]
categories = categories_data_sample
Expand All @@ -213,4 +213,4 @@ def mappings_data_sample
["1", "category_id_1"]
])
end
end
end

0 comments on commit ca38d2a

Please sign in to comment.