@ -12,32 +12,64 @@ RSpec.describe Scale, type: :model do
let ( :teacher_survey_item_1 ) { create ( :teacher_survey_item , scale : ) }
let ( :teacher_survey_item_1 ) { create ( :teacher_survey_item , scale : ) }
let ( :teacher_survey_item_2 ) { create ( :teacher_survey_item , scale : ) }
let ( :teacher_survey_item_2 ) { create ( :teacher_survey_item , scale : ) }
let ( :teacher_survey_item_3 ) { create ( :teacher_survey_item , scale : ) }
let ( :teacher_survey_item_3 ) { create ( :teacher_survey_item , scale : ) }
let ( :student_survey_item_1 ) { create ( :student_survey_item , scale : ) }
before :each do
context 'when only teacher survey items exist' do
before :each do
create ( :survey_item_response ,
survey_item : teacher_survey_item_1 , academic_year : , school : , likert_score : 3 )
create ( :survey_item_response ,
survey_item : teacher_survey_item_2 , academic_year : , school : , likert_score : 4 )
create ( :survey_item_response ,
survey_item : teacher_survey_item_3 , academic_year : , school : , likert_score : 5 )
end
it 'returns the average of the likert scores of the survey items' do
expect ( scale . score ( school : , academic_year : ) ) . to eq 4
end
context 'when other scales exist' do
before :each do
create ( :survey_item_response ,
academic_year : , school : , likert_score : 1 )
create ( :survey_item_response ,
academic_year : , school : , likert_score : 1 )
create ( :survey_item_response ,
academic_year : , school : , likert_score : 1 )
end
it 'does not affect the score for the original scale' do
expect ( scale . score ( school : , academic_year : ) ) . to eq 4
end
end
end
context 'when both teacher and student survey items exist' do
before :each do
create ( :survey_item_response ,
create ( :survey_item_response ,
survey_item : teacher_survey_item_1 , academic_year : , school : , likert_score : 3 )
survey_item : teacher_survey_item_1 , academic_year : , school : , likert_score : 3 )
create ( :survey_item_response ,
create ( :survey_item_response ,
survey_item : teacher_survey_item_2 , academic_year : , school : , likert_score : 4 )
survey_item : teacher_survey_item_2 , academic_year : , school : , likert_score : 4 )
create ( :survey_item_response ,
create ( :survey_item_response ,
survey_item : teacher_survey_item_3 , academic_year : , school : , likert_score : 5 )
survey_item : teacher_survey_item_3 , academic_year : , school : , likert_score : 5 )
end
end
context 'but no survey item responses are linked to student survey items' do
it 'returns the average of the likert scores of the survey items' do
before :each do
expect ( scale . score ( school : , academic_year : ) ) . to eq 4
student_survey_item_1
end
end
context 'when other scales exist' do
it 'returns a score that only averages teacher survey items' do
before :each do
expect ( scale . score ( school : , academic_year : ) ) . to eq 4
create ( :survey_item_response ,
end
academic_year : , school : , likert_score : 1 )
create ( :survey_item_response ,
academic_year : , school : , likert_score : 1 )
create ( :survey_item_response ,
academic_year : , school : , likert_score : 1 )
end
end
it 'does not affect the score for the original scale' do
context 'and some survey item responses exist for a student survey item' do
expect ( scale . score ( school : , academic_year : ) ) . to eq 4
before :each do
create ( :survey_item_response ,
survey_item : student_survey_item_1 , academic_year : , school : , likert_score : 2 )
end
it 'returns a score that gives equal weight to student and teacher survey items' do
expect ( scale . score ( school : , academic_year : ) ) . to eq 3
end
end
end
end
end
end
end