fix: instead of looking for 'asian' at the start of a word, look for it

after a word boundary.  This means it still doesn't get confused with
caucasian and it's more flexible whan asian appears inside other text
such as 'Caucasian and Asian and Black'
rpp-main
Nelson Jovel 2 years ago
parent 8a0ba0dbea
commit a15b01a3e1

@ -14,7 +14,7 @@ class Race < ApplicationRecord
case word
when /Native\s*American|American\s*Indian|Alaskan\s*Native|1/i
1
when /^Asian|Pacific\s*Island|Hawaiian|2/i
when /\bAsian|Pacific\s*Island|Hawaiian|2/i
2
when /Black|African\s*American|3/i
3

@ -23,6 +23,7 @@ RSpec.describe SurveyItemValues, type: :model do
create(:race, qualtrics_code: 7)
create(:race, qualtrics_code: 8)
create(:race, qualtrics_code: 99)
create(:race, qualtrics_code: 100)
Race.by_qualtrics_code
end
@ -378,6 +379,48 @@ RSpec.describe SurveyItemValues, type: :model do
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
end
end
context "when there are multiple races" do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "1,2,3" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "Alaskan Native, Pacific Islander, Black" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native, Asian, African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "n/a" }
row = { "Race" => "American Indian or Alaskan Native, Asian and African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native and Asian and African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native and Asian, and African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
row = { "Race" => "Asian, Caucasian and African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2, 5, 3, 100]
row = { "Race" => "Caucasian and Asian and African American" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5, 2, 3, 100]
row = { "Race" => "Caucasian and Asian and African American", "HispanicLatino" => "true" }
headers.push("HispanicLatino")
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5, 2, 3, 4, 100]
end
end
end
context ".respondent_type" do

Loading…
Cancel
Save