Print out invalid values when loading admin data

pull/1/head
rebuilt 3 years ago
parent da2e27e863
commit 7e5b235668

@ -6,7 +6,11 @@ class AdminDataLoader
likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score'] likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score']
likert_score = likert_score.to_f likert_score = likert_score.to_f
likert_score = 1 if likert_score > 0 && likert_score < 1 likert_score = 1 if likert_score > 0 && likert_score < 1
next unless valid_likert_score(likert_score:)
unless valid_likert_score(likert_score:)
puts "This value is not valid #{likert_score}"
next
end
ay = row['Academic Year'] || row['AcademicYear'] ay = row['Academic Year'] || row['AcademicYear']
dese_id = row['DESE ID'] || row['Dese ID'] || row['Dese Id'] dese_id = row['DESE ID'] || row['Dese ID'] || row['Dese Id']

@ -9,5 +9,6 @@ Revere,Beachmont Elementary School,2480013,3-A-i,a-reso-i1,Average class size,17
Winchester,Winchester High School,3440505,3-A-i,a-reso-i1,Average class size,17,4.3,20,,2018-19 Winchester,Winchester High School,3440505,3-A-i,a-reso-i1,Average class size,17,4.3,20,,2018-19
Attleboro,Attleboro High School,160505,3-A-ii,a-sust-i3,Student to instructional support staff ratio,15.28896673,0.4,43.4,,2018-19 Attleboro,Attleboro High School,160505,3-A-ii,a-sust-i3,Student to instructional support staff ratio,15.28896673,0.4,43.4,,2018-19
Milford,Woodland Elementary School,1850090,3-A-ii,a-sust-i3,Student to instructional support staff ratio,22.85714286,2.106649112,43.4,,2018-19 Milford,Woodland Elementary School,1850090,3-A-ii,a-sust-i3,Student to instructional support staff ratio,22.85714286,2.106649112,43.4,,2018-19
Revere,Beachmont Elementary School,2480013,3-A-ii,a-sust-i3,Student to instructional support staff ratio,38,3.502304147,43.4,,2018-19 Revere,Beachmont Elementary School,2480013,3-A-ii,a-sust-i3,Student to instructional support staff ratio,38,3.5,43.4,,2018-19
Winchester,Winchester High School,3440505,3-A-ii,a-sust-i3,Student to instructional support staff ratio,135.9,5,43.4,,2018-19 Winchester,Winchester High School,3440505,3-A-ii,a-sust-i3,Student to instructional support staff ratio,135.9,5,43.4,,2018-19
Attleboro,Attleboro High School,160505,3-A-i,a-sust-i3,Average class size,20.6,100,20,,2018-19

1 District School DESE ID Category Item ID NonLikert Title NL_Value LikertScore Benchmark Data Type Academic Year
9 Winchester Winchester High School 3440505 3-A-i a-reso-i1 Average class size 17 4.3 20 2018-19
10 Attleboro Attleboro High School 160505 3-A-ii a-sust-i3 Student to instructional support staff ratio 15.28896673 0.4 43.4 2018-19
11 Milford Woodland Elementary School 1850090 3-A-ii a-sust-i3 Student to instructional support staff ratio 22.85714286 2.106649112 43.4 2018-19
12 Revere Beachmont Elementary School 2480013 3-A-ii a-sust-i3 Student to instructional support staff ratio 38 3.502304147 3.5 43.4 2018-19
13 Winchester Winchester High School 3440505 3-A-ii a-sust-i3 Student to instructional support staff ratio 135.9 5 43.4 2018-19
14 Attleboro Attleboro High School 160505 3-A-i a-sust-i3 Average class size 20.6 100 20 2018-19

@ -10,8 +10,6 @@ describe AdminDataLoader do
before :each do before :each do
Rails.application.load_seed Rails.application.load_seed
AdminDataLoader.load_data filepath: path_to_admin_data
end end
after :each do after :each do
@ -19,6 +17,9 @@ describe AdminDataLoader do
end end
describe 'self.load_data' do describe 'self.load_data' do
before :each do
AdminDataLoader.load_data filepath: path_to_admin_data
end
it 'loads the correct admin data values' do it 'loads the correct admin data values' do
# it 'assigns the academic year to admin data value' do # it 'assigns the academic year to admin data value' do
expect(AdminDataValue.where(school: attleboro, expect(AdminDataValue.where(school: attleboro,
@ -51,7 +52,27 @@ describe AdminDataLoader do
# it 'rejects importing rows with a value of 0' do # it 'rejects importing rows with a value of 0' do
expect(AdminDataValue.where(school: attleboro, academic_year: ay_2018_19, 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 admin_data_item: AdminDataItem.find_by_admin_data_item_id('a-reso-i1'))).not_to exist
expect(AdminDataValue.where(school: attleboro, academic_year: ay_2018_19,
admin_data_item: AdminDataItem.find_by_admin_data_item_id('a-sust-i3'))).not_to exist
# end # end
end end
end end
describe 'output to console' do
it 'outputs a messsage saying a value has been rejected' do
output = capture_stdout { AdminDataLoader.load_data filepath: path_to_admin_data }.gsub("\n", '')
expect(output).to eq 'This value is not valid 0.0This value is not valid 100.0'
end
end
end
def capture_stdout
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
yield
ensure
$stdout = original_stdout
end
fake.string
end end

Loading…
Cancel
Save