diff --git a/app/services/admin_data_loader.rb b/app/services/admin_data_loader.rb index 947fd3a2..296703bf 100644 --- a/app/services/admin_data_loader.rb +++ b/app/services/admin_data_loader.rb @@ -6,7 +6,7 @@ class AdminDataLoader likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score'] likert_score = likert_score.to_f likert_score = 1 if likert_score > 0 && likert_score < 1 - next if likert_score == 0 + next unless valid_likert_score(likert_score:) ay = row['Academic Year'] || row['AcademicYear'] dese_id = row['DESE ID'] || row['Dese ID'] || row['Dese Id'] @@ -19,4 +19,10 @@ class AdminDataLoader admin_data_value.save! end end + + def self.valid_likert_score(likert_score:) + likert_score >= 1 && likert_score <= 5 + end + + private_class_method :valid_likert_score end diff --git a/spec/services/admin_data_loader_spec.rb b/spec/services/admin_data_loader_spec.rb index cd9febe7..49bae3d6 100644 --- a/spec/services/admin_data_loader_spec.rb +++ b/spec/services/admin_data_loader_spec.rb @@ -10,6 +10,8 @@ describe AdminDataLoader do before :each do Rails.application.load_seed + + AdminDataLoader.load_data filepath: path_to_admin_data end after :each do @@ -17,40 +19,39 @@ describe AdminDataLoader do end describe 'self.load_data' do - before :each do - AdminDataLoader.load_data filepath: path_to_admin_data - end - it 'assigns the academic year to admin data value' do + it 'loads the correct admin data values' do + # it 'assigns the academic year to admin data value' do expect(AdminDataValue.where(school: attleboro, admin_data_item: chronic_absense_rate).first.academic_year).to eq ay_2018_19 - end + # end - it 'assigns the school to the admin data value' do + # it 'assigns the school to the admin data value' do expect(AdminDataValue.first.school).to eq attleboro expect(AdminDataValue.last.school).to eq winchester - end + # end - it 'links the admin data value to the correct admin data item' do + # it 'links the admin data value to the correct admin data item' do expect(AdminDataValue.first.admin_data_item).to eq chronic_absense_rate expect(AdminDataValue.last.admin_data_item).to eq student_to_instructor_ratio - end + # end - it 'loads all the admin data values in the target csv file' do + # it 'loads all the admin data values in the target csv file' do expect(AdminDataValue.count).to eq 11 - end + # end - it 'captures the likert score ' do + # it 'captures the likert score ' do expect(AdminDataValue.first.likert_score).to eq 3.03 expect(AdminDataValue.last.likert_score).to eq 5 - end + # end - it 'rounds up any likert_scores between 0 and 1 (non-inclusive) to 1' do + # it 'rounds up any likert_scores between 0 and 1 (non-inclusive) to 1' do expect(AdminDataValue.where(school: attleboro, academic_year: ay_2018_19, admin_data_item: AdminDataItem.find_by_admin_data_item_id('a-sust-i3')).first.likert_score).to eq 1 - end - it 'rejects importing rows with a value of 0' do + # end + # it 'rejects importing rows with a value of 0' do expect(AdminDataValue.where(school: attleboro, academic_year: ay_2018_19, admin_data_item: AdminDataItem.find_by_admin_data_item_id('a-reso-i1'))).not_to exist + # end end end end