mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Prevent negative admin data values from being imported
This commit is contained in:
parent
52a24c3daa
commit
4952849d96
2 changed files with 24 additions and 17 deletions
|
|
@ -6,7 +6,7 @@ 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 if likert_score == 0
|
next unless valid_likert_score(likert_score:)
|
||||||
|
|
||||||
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']
|
||||||
|
|
@ -19,4 +19,10 @@ class AdminDataLoader
|
||||||
admin_data_value.save!
|
admin_data_value.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.valid_likert_score(likert_score:)
|
||||||
|
likert_score >= 1 && likert_score <= 5
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method :valid_likert_score
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ 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
|
||||||
|
|
@ -17,40 +19,39 @@ describe AdminDataLoader do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'self.load_data' do
|
describe 'self.load_data' do
|
||||||
before :each do
|
it 'loads the correct admin data values' do
|
||||||
AdminDataLoader.load_data filepath: path_to_admin_data
|
# it 'assigns the academic year to admin data value' do
|
||||||
end
|
|
||||||
it 'assigns the academic year to admin data value' do
|
|
||||||
expect(AdminDataValue.where(school: attleboro,
|
expect(AdminDataValue.where(school: attleboro,
|
||||||
admin_data_item: chronic_absense_rate).first.academic_year).to eq ay_2018_19
|
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.first.school).to eq attleboro
|
||||||
expect(AdminDataValue.last.school).to eq winchester
|
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.first.admin_data_item).to eq chronic_absense_rate
|
||||||
expect(AdminDataValue.last.admin_data_item).to eq student_to_instructor_ratio
|
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
|
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.first.likert_score).to eq 3.03
|
||||||
expect(AdminDataValue.last.likert_score).to eq 5
|
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,
|
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
|
admin_data_item: AdminDataItem.find_by_admin_data_item_id('a-sust-i3')).first.likert_score).to eq 1
|
||||||
end
|
# end
|
||||||
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
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue