Remove surveys table from codebase since it's no longer needed after changing logic surrounding response rates and score calculations

mciea-main
rebuilt 3 years ago
parent 001d3083c8
commit 09963c3323

@ -10,7 +10,7 @@ class Scale < ApplicationRecord
@score ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] = begin
items = []
items << collect_survey_item_average(student_survey_items(school:, academic_year:), school, academic_year)
items << collect_survey_item_average(student_survey_items, school, academic_year)
items << collect_survey_item_average(teacher_survey_items, school, academic_year)
items.remove_blanks.average
@ -38,11 +38,7 @@ class Scale < ApplicationRecord
survey_items.teacher_survey_items
end
def student_survey_items(school:, academic_year:)
survey = Survey.where(school:, academic_year:).first
student_survey_items = survey_items.student_survey_items
return student_survey_items.short_form_items if survey.present? && survey.form == 'short'
student_survey_items
def student_survey_items
survey_items.student_survey_items
end
end

@ -1,9 +1,6 @@
# frozen_string_literal: true
class Survey < ApplicationRecord
belongs_to :academic_year
belongs_to :school
enum form: {
normal: 0,
short: 1

@ -1,5 +1,6 @@
require_relative 'boot'
require 'csv'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems

@ -0,0 +1,11 @@
class DropSurveysTable < ActiveRecord::Migration[7.0]
def change
drop_table :surveys do |t|
t.integer :form
t.references :academic_year, null: false, foreign_key: true
t.references :school, null: false, foreign_key: true
t.timestamps
end
end
end

@ -10,9 +10,8 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
ActiveRecord::Schema[7.0].define(version: 2023_04_21_034505) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
create_table "academic_years", id: :serial, force: :cascade do |t|
@ -360,6 +359,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
t.datetime "updated_at", null: false
t.index ["academic_year_id"], name: "index_response_rates_on_academic_year_id"
t.index ["school_id", "subcategory_id"], name: "index_response_rates_on_school_id_and_subcategory_id"
t.index ["school_id"], name: "index_response_rates_on_school_id"
t.index ["subcategory_id"], name: "index_response_rates_on_subcategory_id"
end
@ -449,6 +449,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
t.index ["response_id"], name: "index_survey_item_responses_on_response_id"
t.index ["school_id", "academic_year_id"], name: "index_survey_item_responses_on_school_id_and_academic_year_id"
t.index ["school_id", "survey_item_id", "academic_year_id", "grade"], name: "index_survey_responses_on_grade"
t.index ["school_id"], name: "index_survey_item_responses_on_school_id"
t.index ["student_id"], name: "index_survey_item_responses_on_student_id"
t.index ["survey_item_id"], name: "index_survey_item_responses_on_survey_item_id"
end
@ -469,16 +470,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
t.index ["survey_item_id"], name: "index_survey_items_on_survey_item_id"
end
create_table "surveys", force: :cascade do |t|
t.integer "form"
t.bigint "academic_year_id", null: false
t.bigint "school_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["academic_year_id"], name: "index_surveys_on_academic_year_id"
t.index ["school_id"], name: "index_surveys_on_school_id"
end
add_foreign_key "admin_data_items", "scales"
add_foreign_key "admin_data_values", "academic_years"
add_foreign_key "admin_data_values", "admin_data_items"
@ -512,6 +503,4 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
add_foreign_key "survey_item_responses", "students"
add_foreign_key "survey_item_responses", "survey_items"
add_foreign_key "survey_items", "scales"
add_foreign_key "surveys", "academic_years"
add_foreign_key "surveys", "schools"
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,238 +1,200 @@
require 'rails_helper'
require "rails_helper"
require "#{Rails.root}/app/lib/seeder"
describe Seeder do
let(:seeder) { Seeder.new }
let(:lowell_seeder) { Seeder.new rules: [Rule::SeedOnlyLowell] }
context 'academic years' do
before { AcademicYear.delete_all }
after :each do
DatabaseCleaner.clean
end
it 'seeds new academic years' do
context "academic years" do
it "seeds new academic years" do
expect do
seeder.seed_academic_years '2020-21', '2021-22', '2022-23'
seeder.seed_academic_years "2020-21", "2021-22", "2022-23"
end.to change { AcademicYear.count }.by(3)
expect(AcademicYear.all.map(&:range)).to eq %w[2020-21 2021-22 2022-23]
end
context 'when partial data already exists' do
before { create(:academic_year, range: '2020-21') }
context "when partial data already exists" do
before { create(:academic_year, range: "2020-21") }
it 'only creates new data' do
it "only creates new data" do
expect do
seeder.seed_academic_years '2020-21', '2021-22'
seeder.seed_academic_years "2020-21", "2021-22"
end.to change { AcademicYear.count }.by(1)
end
end
end
context 'districts and schools' do
context "districts and schools" do
before(:each) do
District.delete_all
School.delete_all
end
it 'seeds new districts and schools' do
it "seeds new districts and schools" do
expect do
seeder.seed_districts_and_schools sample_districts_and_schools_csv
end.to change { District.count }.by(3)
.and change { School.count }.by(4)
.and change { School.count }.by(4)
high_school = School.find_by_dese_id 160_505
expect(high_school.name).to eq 'Attleboro High School'
expect(high_school.name).to eq "Attleboro High School"
expect(high_school.is_hs).to be true
elementary_school = School.find_by_dese_id 350_302
expect(elementary_school.name).to eq 'Samuel Adams Elementary School'
expect(elementary_school.name).to eq "Samuel Adams Elementary School"
expect(elementary_school.is_hs).to be false
end
context 'when partial data already exists' do
let!(:existing_district) { create(:district, name: 'Boston') }
context "when partial data already exists" do
let!(:existing_district) { create(:district, name: "Boston") }
let!(:removed_school) do
create(:school, name: 'John Oldest Academy', dese_id: 12_345, district: existing_district)
create(:school, name: "John Oldest Academy", dese_id: 12_345, district: existing_district)
end
let!(:removed_survey_item_response) { create(:survey_item_response, school: removed_school) }
let!(:removed_respondent) { create(:respondent, school: removed_school) }
let!(:removed_survey) { create(:survey, school: removed_school) }
let!(:existing_school) do
create(:school, name: 'Sam Adams Elementary School', dese_id: 350_302, slug: 'some-slug-for-sam-adams',
district: existing_district)
create(:school, name: "Sam Adams Elementary School", dese_id: 350_302, slug: "some-slug-for-sam-adams",
district: existing_district)
end
it 'only creates new districts and schools' do
it "only creates new districts and schools" do
expect do
seeder.seed_districts_and_schools sample_districts_and_schools_csv
end.to change { District.count }.by(2)
.and change {
School.count
}.by(2) # +2 for schools added from example csv, -1 for old school
.and change {
School.count
}.by(2) # +2 for schools added from example csv, -1 for old school
new_district = District.find_by_name 'Attleboro'
new_district = District.find_by_name "Attleboro"
expect(new_district.qualtrics_code).to eq 1
expect(new_district.slug).to eq 'attleboro'
expect(new_district.slug).to eq "attleboro"
new_school = School.find_by_name 'Attleboro High School'
new_school = School.find_by_name "Attleboro High School"
expect(new_school.dese_id).to eq 160_505
expect(new_school.qualtrics_code).to eq 1
expect(new_school.slug).to eq 'attleboro-high-school'
expect(new_school.slug).to eq "attleboro-high-school"
end
it 'updates existing districts and schools with the correct data' do
it "updates existing districts and schools with the correct data" do
seeder.seed_districts_and_schools sample_districts_and_schools_csv
existing_district.reload
expect(existing_district.qualtrics_code).to eq 2
expect(existing_district.slug).to eq 'boston'
expect(existing_district.slug).to eq "boston"
existing_school.reload
expect(existing_school.qualtrics_code).to eq 1
expect(existing_school.name).to eq 'Samuel Adams Elementary School'
expect(existing_school.slug).to eq 'some-slug-for-sam-adams'
expect(existing_school.name).to eq "Samuel Adams Elementary School"
expect(existing_school.slug).to eq "some-slug-for-sam-adams"
end
it 'removes any schools and associated child objects not contained within the CSV' do
it "removes any schools and associated child objects not contained within the CSV" do
seeder.seed_districts_and_schools sample_districts_and_schools_csv
expect(School.where(id: removed_school)).not_to exist
expect(SurveyItemResponse.where(id: removed_survey_item_response)).not_to exist
expect(Respondent.where(id: removed_respondent)).not_to exist
expect(Survey.where(id: removed_survey)).not_to exist
end
end
context 'when passing a rule to only load lowell schools' do
it 'only loads lowell schools' do
context "when passing a rule to only load lowell schools" do
it "only loads lowell schools" do
expect do
lowell_seeder.seed_districts_and_schools sample_districts_and_schools_csv
end.to change { District.count }.by(1)
.and change {
School.count
}.by(1)
.and change {
School.count
}.by(1)
end
end
end
context 'respondents' do
before :each do
create(:academic_year, range: '2020-21')
seeder.seed_districts_and_schools sample_districts_and_schools_csv
end
it 'seeds the total number of respondents for a school' do
expect do
seeder.seed_respondents sample_districts_and_schools_csv
end.to change { Respondent.count }.by(School.count)
end
it 'seeds idempotently' do
expect do
seeder.seed_respondents sample_districts_and_schools_csv
end.to change { Respondent.count }.by(School.count)
expect(Respondent.all.count).to eq School.count
expect do
seeder.seed_respondents sample_districts_and_schools_csv
end.to change { Respondent.count }.by(0)
end
it 'seeds new respondents for every year in the database' do
expect do
seeder.seed_respondents sample_districts_and_schools_csv
end.to change { Respondent.count }.by School.count
expect do
create(:academic_year, range: '2019-20')
seeder.seed_respondents sample_districts_and_schools_csv
end.to change { Respondent.count }.by School.count
end
it 'seeds the total number of students and teachers even if the original number includes commas' do
seeder.seed_respondents sample_districts_and_schools_csv
school = School.find_by_name('Attleboro High School')
academic_year = AcademicYear.find_by_range('2020-21')
school_with_over_one_thousand_student_respondents = Respondent.where(school:, academic_year:).first
expect(school_with_over_one_thousand_student_respondents.total_students).to eq 1792
end
end
context 'surveys' do
before :each do
create(:academic_year, range: '2020-21')
seeder.seed_districts_and_schools sample_districts_and_schools_csv
seeder.seed_surveys sample_districts_and_schools_csv
end
it 'for one academic year, it seeds a count of surveys equal to the count of schools' do
expect(Survey.count).to eq School.count
end
it 'marks short form schools as short form schools' do
elementary_school = School.find_by_dese_id 160_001
academic_year = AcademicYear.find_by_range '2020-21'
survey = Survey.where(school: elementary_school, academic_year:).first
expect(survey.form).to eq 'short'
end
it 'does not mark long form schools as short form schools' do
elementary_school = School.find_by_dese_id 350_302
academic_year = AcademicYear.find_by_range '2020-21'
survey = Survey.where(school: elementary_school, academic_year:).first
expect(survey.form).to eq 'normal'
end
it 'seed idempotently' do
expect do
seeder.seed_surveys sample_districts_and_schools_csv
end.to change { Survey.count }.by 0
end
it 'seeds new surveys for every year in the database' do
expect do
create(:academic_year, range: '2019-20')
seeder.seed_surveys sample_districts_and_schools_csv
end.to change { Survey.count }.by School.count
end
end
context 'admin data items' do
context 'when deprecated admin items exist in the database' do
# context 'respondents' do
# before :each do
# create(:academic_year, range: '2020-21')
# seeder.seed_districts_and_schools sample_districts_and_schools_csv
# end
# it 'seeds the total number of respondents for a school' do
# expect do
# seeder.seed_respondents sample_districts_and_schools_csv
# end.to change { Respondent.count }.by(School.count)
# end
# it 'seeds idempotently' do
# expect do
# seeder.seed_respondents sample_districts_and_schools_csv
# end.to change { Respondent.count }.by(School.count)
# expect(Respondent.all.count).to eq School.count
# expect do
# seeder.seed_respondents sample_districts_and_schools_csv
# end.to change { Respondent.count }.by(0)
# end
# it 'seeds new respondents for every year in the database' do
# expect do
# seeder.seed_respondents sample_districts_and_schools_csv
# end.to change { Respondent.count }.by School.count
# expect do
# create(:academic_year, range: '2019-20')
# seeder.seed_respondents sample_districts_and_schools_csv
# end.to change { Respondent.count }.by School.count
# end
# it 'seeds the total number of students and teachers even if the original number includes commas' do
# seeder.seed_respondents sample_districts_and_schools_csv
# school = School.find_by_name('Attleboro High School')
# academic_year = AcademicYear.find_by_range('2020-21')
# school_with_over_one_thousand_student_respondents = Respondent.where(school:, academic_year:).first
# expect(school_with_over_one_thousand_student_respondents.total_students).to eq 1792
# end
# end
context "admin data items" do
context "when deprecated admin items exist in the database" do
before :each do
admin_data_item_1 = create(:admin_data_item, admin_data_item_id: 'a-cppm-i1')
admin_data_item_1 = create(:admin_data_item, admin_data_item_id: "a-cppm-i1")
create(:admin_data_value, admin_data_item_id: admin_data_item_1.id)
admin_data_item_2 = create(:admin_data_item, admin_data_item_id: 'a-ovpe-i2')
admin_data_item_2 = create(:admin_data_item, admin_data_item_id: "a-ovpe-i2")
create(:admin_data_value, admin_data_item_id: admin_data_item_2.id)
admin_data_item_3 = create(:admin_data_item, admin_data_item_id: 'a-phys-i2')
admin_data_item_3 = create(:admin_data_item, admin_data_item_id: "a-phys-i2")
create(:admin_data_value, admin_data_item_id: admin_data_item_3.id)
seeder.seed_sqm_framework sample_sqm_framework_csv
end
it 'removes the outdated admin items' do
it "removes the outdated admin items" do
expect(AdminDataItem.count).to eq 31
expect(AdminDataItem.find_by_admin_data_item_id('a-cppm-i1').nil?).to eq true
expect(AdminDataItem.find_by_admin_data_item_id('a-ovpe-i2').nil?).to eq true
expect(AdminDataItem.find_by_admin_data_item_id('a-phys-i2').nil?).to eq true
expect(AdminDataItem.find_by_admin_data_item_id("a-cppm-i1").nil?).to eq true
expect(AdminDataItem.find_by_admin_data_item_id("a-ovpe-i2").nil?).to eq true
expect(AdminDataItem.find_by_admin_data_item_id("a-phys-i2").nil?).to eq true
end
end
end
context 'the sqm framework' do
context "the sqm framework" do
before do
school_culture_category = create(:category, category_id: '2', sort_index: -1)
safety_subcategory = create(:subcategory, subcategory_id: '2A', category: school_culture_category)
physical_safety_measure = create(:measure, measure_id: '2A-i', subcategory: safety_subcategory)
student_physical_safety_scale = create(:scale, scale_id: 's-phys', measure: physical_safety_measure)
create(:survey_item, survey_item_id: 's-phys-q1', scale: student_physical_safety_scale)
admin_physical_safety_scale = create(:scale, scale_id: 'a-phys', measure: physical_safety_measure)
create(:admin_data_item, admin_data_item_id: 'a-phys-i1', scale: admin_physical_safety_scale)
school_culture_category = create(:category, category_id: "2", sort_index: -1)
safety_subcategory = create(:subcategory, subcategory_id: "2A", category: school_culture_category)
physical_safety_measure = create(:measure, measure_id: "2A-i", subcategory: safety_subcategory)
student_physical_safety_scale = create(:scale, scale_id: "s-phys", measure: physical_safety_measure)
create(:survey_item, survey_item_id: "s-phys-q1", scale: student_physical_safety_scale)
admin_physical_safety_scale = create(:scale, scale_id: "a-phys", measure: physical_safety_measure)
create(:admin_data_item, admin_data_item_id: "a-phys-i1", scale: admin_physical_safety_scale)
end
it 'creates new objects as necessary' do
it "creates new objects as necessary" do
expect do
seeder.seed_sqm_framework sample_sqm_framework_csv
end.to change { Category.count }.by(4)
.and change { Subcategory.count }.by(15)
.and change { Measure.count }.by(31).and change {
Scale.count
}.by(51)
.and change { Subcategory.count }.by(15)
.and change { Measure.count }.by(31).and change {
Scale.count
}.by(51)
.and change {
SurveyItem.count
}.by(136)
@ -241,74 +203,74 @@ describe Seeder do
}.by(30)
end
context 'updates records to match given data' do
context "updates records to match given data" do
before :each do
seeder.seed_sqm_framework sample_sqm_framework_csv
end
it 'updates category data' do
teachers_leadership = Category.find_by_name 'Teachers & Leadership'
it "updates category data" do
teachers_leadership = Category.find_by_name "Teachers & Leadership"
expect(teachers_leadership.slug).to eq 'teachers-and-leadership'
expect(teachers_leadership.slug).to eq "teachers-and-leadership"
expect(teachers_leadership.description).to eq("Measures the relevant abilities of a school's teachers and the degree to which they are receiving the support they need to grow as professionals. It considers factors like teacher professional qualifications, effective classroom practices, and school-wide support for teaching development and growth.")
expect(teachers_leadership.short_description).to eq "Measures the relevant abilities of a school's teachers and the degree to which they are receiving the support they need to grow as professionals."
end
it 'updates category sort index to match a predefined order' do
teachers_leadership = Category.find_by_name 'Teachers & Leadership'
school_culture = Category.find_by_name 'School Culture'
it "updates category sort index to match a predefined order" do
teachers_leadership = Category.find_by_name "Teachers & Leadership"
school_culture = Category.find_by_name "School Culture"
expect(teachers_leadership.sort_index).to eq 0
expect(school_culture.sort_index).to eq 1
end
it 'updates subcategory data' do
subcategory = Subcategory.find_by_name 'Safety'
expect(subcategory.description).to eq 'Seeks to determine the degree to which school climate is a safe place for students to learn. It includes measures of student physical safety and student emotional safety.'
it "updates subcategory data" do
subcategory = Subcategory.find_by_name "Safety"
expect(subcategory.description).to eq "Seeks to determine the degree to which school climate is a safe place for students to learn. It includes measures of student physical safety and student emotional safety."
end
it 'updates measure data' do
measure = Measure.find_by_measure_id '2A-i'
expect(measure.name).to eq 'Student Physical Safety'
expect(measure.description).to eq 'Draws on anonymous student reports about the degree to which they feel physically safe at school. It also measures the use of exclusionary discipline at the school.'
it "updates measure data" do
measure = Measure.find_by_measure_id "2A-i"
expect(measure.name).to eq "Student Physical Safety"
expect(measure.description).to eq "Draws on anonymous student reports about the degree to which they feel physically safe at school. It also measures the use of exclusionary discipline at the school."
end
it 'updates scale references' do
scale = Scale.find_by_scale_id 't-pcom'
measure = Measure.find_by_measure_id '1A-iii'
survey_item = SurveyItem.find_by_survey_item_id 't-pcom-q1'
it "updates scale references" do
scale = Scale.find_by_scale_id "t-pcom"
measure = Measure.find_by_measure_id "1A-iii"
survey_item = SurveyItem.find_by_survey_item_id "t-pcom-q1"
expect(scale.measure).to eq measure
expect(scale.survey_items).to include survey_item
end
it 'does not overwrite the survey item benchmarks with admin data benchmarks' do
survey_item = SurveyItem.find_by_survey_item_id 't-prep-q1'
it "does not overwrite the survey item benchmarks with admin data benchmarks" do
survey_item = SurveyItem.find_by_survey_item_id "t-prep-q1"
expect(survey_item.approval_low_benchmark).to eq 3.5
end
it 'updates survey item data' do
survey_item = SurveyItem.find_by_survey_item_id 's-phys-q1'
expect(survey_item.prompt).to eq 'How often do you worry about violence at your school?'
it "updates survey item data" do
survey_item = SurveyItem.find_by_survey_item_id "s-phys-q1"
expect(survey_item.prompt).to eq "How often do you worry about violence at your school?"
expect(survey_item.watch_low_benchmark).to eq 2.79
expect(survey_item.growth_low_benchmark).to eq 3.3
expect(survey_item.approval_low_benchmark).to eq 3.8
expect(survey_item.ideal_low_benchmark).to eq 4.51
expect(survey_item.on_short_form).to eq false
short_form_item = SurveyItem.find_by_survey_item_id 's-peff-q6'
short_form_item = SurveyItem.find_by_survey_item_id "s-peff-q6"
expect(short_form_item.on_short_form).to eq true
end
it 'updates admin data item data' do
admin_data_item = AdminDataItem.find_by_admin_data_item_id 'a-phys-i1'
it "updates admin data item data" do
admin_data_item = AdminDataItem.find_by_admin_data_item_id "a-phys-i1"
expect(admin_data_item.watch_low_benchmark).to eq 2.99
expect(admin_data_item.growth_low_benchmark).to eq 3.5
expect(admin_data_item.approval_low_benchmark).to eq 4
expect(admin_data_item.ideal_low_benchmark).to eq 4.71
expect(admin_data_item.description).to eq 'Percent of students suspended'
expect(admin_data_item.description).to eq "Percent of students suspended"
expect(admin_data_item.hs_only_item).to be false
hs_admin_data_item = AdminDataItem.find_by_admin_data_item_id 'a-curv-i1'
hs_admin_data_item = AdminDataItem.find_by_admin_data_item_id "a-curv-i1"
expect(hs_admin_data_item.hs_only_item).to be true
end
end
@ -317,10 +279,10 @@ describe Seeder do
private
def sample_districts_and_schools_csv
Rails.root.join('spec', 'fixtures', 'sample_districts_and_schools.csv')
Rails.root.join("spec", "fixtures", "sample_districts_and_schools.csv")
end
def sample_sqm_framework_csv
Rails.root.join('spec', 'fixtures', 'sample_sqm_framework.csv')
Rails.root.join("spec", "fixtures", "sample_sqm_framework.csv")
end
end

@ -27,9 +27,7 @@ RSpec.describe Measure, type: :model do
before do
create(:respondent, school:, academic_year:, one: 40)
create(:survey, school:, academic_year:)
create(:respondent, school: short_form_school, academic_year:)
create(:survey, school: short_form_school, academic_year:, form: 'short')
end
describe 'benchmarks' do

@ -1,76 +0,0 @@
require 'rails_helper'
RSpec.describe Report::Pillar, type: :model do
let(:school) { create(:school, name: 'Abraham Lincoln Elementary School') }
let(:subcategory) { create(:subcategory, subcategory_id: '1A') }
let(:measure_1) { create(:measure, measure_id: '1A-iii', subcategory:) }
let(:measure_2) { create(:measure, measure_id: '1B-ii', subcategory:) }
let(:scale_1) { create(:scale, measure: measure_1) }
let(:scale_2) { create(:scale, measure: measure_2) }
let(:survey_item_1) { create(:student_survey_item, scale: scale_1) }
let(:survey_item_2) do
create(:student_survey_item, scale: scale_2, ideal_low_benchmark: 5)
end
let(:measures) do
subcategory.measures
end
let(:academic_year_1) { create(:academic_year, range: '2017-2018') }
let(:academic_year_2) { create(:academic_year, range: '2018-2019') }
let(:academic_years) { [academic_year_1, academic_year_2] }
before :each do
create(:respondent, school:, academic_year: academic_year_1)
create(:survey, school:, academic_year: academic_year_1)
measures
end
context '.pillar' do
it 'returns the GPS pillar' do
pillar = Report::Pillar.new(school:, measures:, indicator: 'Teaching Environment',
period: 'Current', academic_year: academic_year_1)
expect(pillar.pillar).to eq('Operational Efficiency')
end
end
context '.school' do
it 'returns the name of the school' do
pillar = Report::Pillar.new(school:, measures:, indicator: 'The Teaching Environment', period: 'Current',
academic_year: academic_year_1)
expect(pillar.school_name).to eq('Abraham Lincoln Elementary School')
end
end
context '.score' do
before do
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_1, school:, academic_year: academic_year_1,
likert_score: 3)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_1, school:, academic_year: academic_year_1,
likert_score: 5)
end
it 'returns the average score for all the measures in the pillar' do
pillar = Report::Pillar.new(school:, measures:, indicator: 'The Teaching Environment', period: 'Current',
academic_year: academic_year_1)
expect(pillar.score).to eq 4
end
end
context '.zone' do
before do
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_1, school:, academic_year: academic_year_1,
likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_1, school:, academic_year: academic_year_1,
likert_score: 5)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_2, school:, academic_year: academic_year_1,
likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item_2, school:, academic_year: academic_year_1,
likert_score: 5)
end
it 'returns the zone for the average score for all the measures in the pillar' do
pillar = Report::Pillar.new(school:, measures:, indicator: 'The Teaching Environment', period: 'Current',
academic_year: academic_year_1)
expect(pillar.score).to eq 4.5
expect(pillar.zone).to eq 'Approval'
end
end
end

@ -3,7 +3,6 @@ require 'rails_helper'
describe ResponseRateCalculator, type: :model do
let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) }
let(:survey) { create(:survey, school:, academic_year:) }
describe StudentResponseRateCalculator do
let(:subcategory) { create(:subcategory) }
@ -215,7 +214,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the average number of teacher responses per question in a subcategory is at the threshold' do
before :each do
respondent
survey
end
it 'returns 25 percent' do
expect(TeacherResponseRateCalculator.new(subcategory:, school:,
@ -226,7 +224,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the teacher response rate is not a whole number. eg 29.166%' do
before do
respondent
survey
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD + 1, survey_item: sufficient_teacher_survey_item_3,
academic_year:, school:, likert_score: 1)
end
@ -239,7 +236,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the average number of teacher responses is greater than the total possible responses' do
before do
respondent
survey
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD * 11, survey_item: sufficient_teacher_survey_item_3,
academic_year:, school:, likert_score: 1)
end
@ -260,7 +256,6 @@ describe ResponseRateCalculator, type: :model do
context 'and one of the teacher items has no associated survey item responses' do
before do
respondent
survey
insufficient_teacher_survey_item_4
end
it 'ignores the empty survey item and returns only the average response rate of teacher survey items with responses' do

@ -4,9 +4,6 @@ RSpec.describe Scale, type: :model do
let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) }
let(:scale) { create(:scale) }
before do
create(:survey, school:, academic_year:)
end
describe '.score' do
let(:teacher_survey_item_1) { create(:teacher_survey_item, scale:) }
@ -45,12 +42,12 @@ RSpec.describe Scale, type: :model do
context 'when both teacher and student 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)
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
context 'but no survey item responses are linked to student survey items' do
before :each do

@ -10,7 +10,6 @@ RSpec.describe Subcategory, type: :model do
let(:student_scale) { create(:student_scale, measure: measure_2) }
before do
create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end
describe '.score' do
@ -25,21 +24,21 @@ RSpec.describe Subcategory, type: :model do
before :each do
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 2)
survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 2)
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 3)
survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 3)
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 4)
survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_1, academic_year:, school:, likert_score: 1)
survey_item: student_survey_item_1, academic_year:, school:, likert_score: 1)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_2, academic_year:, school:, likert_score: 2)
survey_item: student_survey_item_2, academic_year:, school:, likert_score: 2)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_3, academic_year:, school:, likert_score: 3)
survey_item: student_survey_item_3, academic_year:, school:, likert_score: 3)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_4, academic_year:, school:, likert_score: 4)
survey_item: student_survey_item_4, academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_5, academic_year:, school:, likert_score: 5)
survey_item: student_survey_item_5, academic_year:, school:, likert_score: 5)
end
it 'returns the average of the likert scores of the measures' do

@ -3,9 +3,6 @@ RSpec.describe SurveyItem, type: :model do
let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) }
let(:scale) { create(:scale) }
before :each do
create(:survey, school:, academic_year:)
end
describe '.score' do
let(:teacher_survey_item) { create(:teacher_survey_item, scale:) }

@ -79,8 +79,6 @@ describe GroupedBarColumnPresenter do
before do
create(:respondent, school:, academic_year:, total_students: 1, total_teachers: 1)
create(:survey, form: :normal, school:, academic_year:)
create(:survey, form: :normal, school:, academic_year: another_academic_year)
end
shared_examples_for 'measure_name' do

@ -10,7 +10,6 @@ describe MeasurePresenter do
let(:measure_presenter) { MeasurePresenter.new(measure:, academic_year:, school:) }
before do
create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end
it 'returns the id of the measure' do

@ -50,7 +50,6 @@ describe SubcategoryPresenter do
before do
create(:respondent, school:, academic_year:, one: 40)
create(:survey, school:, academic_year:)
end
it 'returns the name of the subcategory' do

@ -1,140 +0,0 @@
require 'rails_helper'
describe ResponseRateLoader do
let(:school) { School.find_by_slug 'milford-high-school' }
let(:academic_year) { AcademicYear.find_by_range '2020-21' }
let(:respondents) do
respondents = Respondent.where(school:, academic_year:).first
respondents.total_students = 10
respondents.total_teachers = 10
respondents.save
end
let(:short_form_survey) do
survey = Survey.find_by(school:, academic_year:)
survey.form = :short
survey.save
survey
end
let(:subcategory) { Subcategory.find_by_subcategory_id '5D' }
let(:s_acst_q1) { SurveyItem.find_by_survey_item_id 's-acst-q1' }
let(:s_acst_q2) { SurveyItem.find_by_survey_item_id 's-acst-q2' } # short form
let(:s_acst_q3) { SurveyItem.find_by_survey_item_id 's-acst-q3' }
let(:s_poaf_q1) { SurveyItem.find_by_survey_item_id 's-poaf-q1' }
let(:s_poaf_q2) { SurveyItem.find_by_survey_item_id 's-poaf-q2' }
let(:s_poaf_q3) { SurveyItem.find_by_survey_item_id 's-poaf-q3' } # short form
let(:s_poaf_q4) { SurveyItem.find_by_survey_item_id 's-poaf-q4' }
let(:t_phya_q2) { SurveyItem.find_by_survey_item_id 't-phya-q2' }
let(:t_phya_q3) { SurveyItem.find_by_survey_item_id 't-phya-q3' }
let(:s_acst) { Scale.find_by_scale_id 's-acst' }
let(:s_poaf) { Scale.find_by_scale_id 's-poaf' }
let(:t_phya) { Scale.find_by_scale_id 't-phya' }
let(:response_rate) { ResponseRate.find_by(subcategory:, school:, academic_year:) }
before :each do
Rails.application.load_seed
respondents
end
after :each do
DatabaseCleaner.clean
end
describe 'self.reset' do
context 'When resetting response rates' do
context 'and half the students responded to each question' do
before :each do
create_list(:survey_item_response, 5, survey_item: s_acst_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_acst_q2, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_acst_q3, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q2, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q3, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q4, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: t_phya_q2, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: t_phya_q3, likert_score: 3, school:, academic_year:)
ResponseRateLoader.reset(schools: [school], academic_years: [academic_year])
end
it 'populates the database with response rates' do
expect(s_acst_q1.survey_item_id).to eq 's-acst-q1'
expect(subcategory.subcategory_id).to eq '5D'
expect(subcategory.name).to eq 'Health'
expect(s_acst.score(school:, academic_year:)).to eq 3
expect(s_poaf.score(school:, academic_year:)).to eq 3
expect(t_phya.score(school:, academic_year:)).to eq 3
expect(response_rate.student_response_rate).to eq 50
expect(response_rate.teacher_response_rate).to eq 50
expect(response_rate.meets_student_threshold).to be true
expect(response_rate.meets_teacher_threshold).to be true
end
context 'when running the loader a second time' do
it 'is idempotent' do
response_count = ResponseRate.count
ResponseRateLoader.reset(schools: [school], academic_years: [academic_year])
second_count = ResponseRate.count
expect(response_count).to eq second_count
end
end
end
context 'and only the first question for each scale was asked; e.g. like on a short form' do
before :each do
create_list(:survey_item_response, 5, survey_item: s_acst_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: t_phya_q2, likert_score: 3, school:, academic_year:)
ResponseRateLoader.reset(schools: [school], academic_years: [academic_year])
end
it 'only takes into account the first question and ignores the other questions in the scale' do
expect(response_rate.student_response_rate).to eq 50
expect(response_rate.teacher_response_rate).to eq 50
end
end
context 'and no respondent entry exists for the school and year' do
before do
Respondent.destroy_all
create_list(:survey_item_response, 5, survey_item: s_acst_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: s_poaf_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 5, survey_item: t_phya_q2, likert_score: 3, school:, academic_year:)
ResponseRateLoader.reset(schools: [school], academic_years: [academic_year])
end
it 'since no score can be calculated, it returns a default of 100' do
expect(response_rate.student_response_rate).to eq 100
expect(response_rate.teacher_response_rate).to eq 100
end
end
context 'and the school took the short form student survey' do
before :each do
create_list(:survey_item_response, 1, survey_item: s_acst_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 6, survey_item: s_acst_q2, likert_score: 3, school:, academic_year:) # short form
create_list(:survey_item_response, 1, survey_item: s_acst_q3, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 1, survey_item: s_poaf_q1, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 1, survey_item: s_poaf_q2, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 6, survey_item: s_poaf_q3, likert_score: 3, school:, academic_year:) # short form
create_list(:survey_item_response, 1, survey_item: s_poaf_q4, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 1, survey_item: t_phya_q2, likert_score: 3, school:, academic_year:)
create_list(:survey_item_response, 1, survey_item: t_phya_q3, likert_score: 3, school:, academic_year:)
short_form_survey
ResponseRateLoader.reset(schools: [school], academic_years: [academic_year])
end
it 'only counts responses from survey items on the short form' do
expect(response_rate.student_response_rate).to eq 60
end
end
end
end
end

@ -13,7 +13,6 @@ describe 'SQM Application' do
driven_by :rack_test
page.driver.browser.basic_authorize(username, password)
create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
ResponseRate.create!(subcategory:, school:, academic_year:,
student_response_rate: 0, teacher_response_rate: 0, meets_student_threshold: false, meets_teacher_threshold: false)
end

@ -119,7 +119,6 @@ describe 'analyze/index' do
assign :genders, genders
assign :selected_genders, selected_genders
create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end
context 'when all the presenters have a nil score' do
before do

@ -76,7 +76,6 @@ describe 'categories/show' do
assign :academic_years, [academic_year]
create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end
context 'for each category' do

Loading…
Cancel
Save