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'
mciea-main
Nelson Jovel 2 years ago
parent fe039e3d04
commit d79635054c

@ -12,7 +12,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
@ -117,6 +118,7 @@ RSpec.describe SurveyItemValues, type: :model do
context ".school" do
it "returns the school that maps to the dese id provided" do
attleboro
headers = ["DeseID"]
row = { "DeseID" => "1234" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.school).to eq attleboro
@ -377,6 +379,49 @@ 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- SIS" => "Caucasian and Asian and African American", "HispanicLatino" => "true" }
headers.push("HispanicLatino")
headers.push("Race- SIS")
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
@ -538,15 +583,15 @@ RSpec.describe SurveyItemValues, type: :model do
expect(values.sped).to eq "Not Special Education"
end
it 'tranlsates NA into "Unknown"' do
it 'tranlsates NA into "Not Special Education"' do
headers = ["Raw SpEd"]
row = { "Raw SpEd" => "NA" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.sped).to eq "Unknown"
expect(values.sped).to eq "Not Special Education"
row = { "Raw SpEd" => "#NA" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.sped).to eq "Unknown"
expect(values.sped).to eq "Not Special Education"
end
end
@ -668,15 +713,14 @@ RSpec.describe SurveyItemValues, type: :model do
end
context "when progress is invalid" do
it "when there are fewer than 17 standard survey items valid_progress returns true" do
it "when there are fewer than 11 standard survey items valid_progress returns true" do
headers = standard_survey_items
row = { "s-peff-q1" => 1, "s-peff-q2" => 1, "s-peff-q3" => 1, "s-peff-q4" => 1,
"s-peff-q5" => 1, "s-peff-q6" => 1, "s-phys-q1" => 1, "s-phys-q2" => 1,
"s-phys-q3" => 1, "s-phys-q4" => 1, "s-emsa-q1" => 1, "s-emsa-q2" => 1,
"s-emsa-q3" => 1, "s-sbel-q1" => 1, "s-sbel-q2" => 1, "s-sbel-q3" => 1 }
"s-emsa-q3" => 1, "s-sbel-q1" => 1 }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:,
schools:)
expect(values.progress).to eq 16
expect(values.progress).to eq 10
expect(values.valid_progress?).to eq false
end
@ -722,14 +766,14 @@ RSpec.describe SurveyItemValues, type: :model do
attleboro_respondents
end
it "returns true for students" do
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate]
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate DeseID]
values = SurveyItemValues.new(row: { "grade" => "9", "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_grade?).to eq true
end
it "returns true for teachers" do
headers = %w[t-sbel-q5 t-phys-q2 grade RecordedDate]
headers = %w[t-sbel-q5 t-phys-q2 grade RecordedDate DeseID]
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_grade?).to eq true
@ -742,7 +786,7 @@ RSpec.describe SurveyItemValues, type: :model do
attleboro_respondents
end
it "returns false" do
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate]
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate DeseID]
values = SurveyItemValues.new(row: { "grade" => "2", "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_grade?).to eq false

Loading…
Cancel
Save