From 24445a6297a3bcc30dbecb891ccbbf41004534b4 Mon Sep 17 00:00:00 2001 From: Gregg P <117232882+GcioGregg@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:50:18 -0800 Subject: [PATCH] Vfep 956 - add unit tests for Accreditation issues report (#1014) * Add new Rspec tests for Accreditation and optimize test performance * add comment for fix --------- Co-authored-by: nfstern02 --- spec/models/institution_builder_spec.rb | 233 +++++++++++++----------- spec/rails_helper.rb | 8 + 2 files changed, 133 insertions(+), 108 deletions(-) diff --git a/spec/models/institution_builder_spec.rb b/spec/models/institution_builder_spec.rb index 30a8bceaf..3c33b2563 100644 --- a/spec/models/institution_builder_spec.rb +++ b/spec/models/institution_builder_spec.rb @@ -23,7 +23,7 @@ it 'generates a new production version' do create :version old_version = Version.current_production - run_institution_builder(user) + described_class.run(user) version = Version.current_production expect(version).not_to eq(old_version) expect(version.production).to be_truthy @@ -32,41 +32,41 @@ it "writes '#{CommonInstitutionBuilder::VersionGeneration::PUBLISH_COMPLETE_TEXT}' to the log" do allow(Rails.logger).to receive(:info) - run_institution_builder(user) + described_class.run(user) expect(Rails.logger).to have_received(:info).with(/Version\sgenerated\sand\spublished/).at_least(:once) end it 'does not write "error" to the log' do allow(Rails.logger).to receive(:error) - run_institution_builder(user) + described_class.run(user) expect(Rails.logger).to have_received(:error).with(/error/).exactly(0).times end end context 'when not successful' do - it 'logs errors at the database level', strategy: :truncation do + it 'logs errors at the database level' do error_message = 'There was an error occurring at the database level: BOOM!' statement_invalid = ActiveRecord::StatementInvalid.new('BOOM!') statement_invalid.set_backtrace(%(backtrace)) allow(factory_class).to receive(:add_crosswalk).and_raise(statement_invalid) allow(Rails.logger).to receive(:error).with(error_message) - run_institution_builder(user) + described_class.run(user) expect(Rails.logger).to have_received(:error).with(error_message) end - it 'logs errors at the Rails level', strategy: :truncation do + it 'logs errors at the Rails level' do error_message = 'There was an error of unexpected origin: BOOM!' allow(factory_class).to receive(:add_crosswalk).and_raise(StandardError, 'BOOM!') allow(Rails.logger).to receive(:error).with(error_message) - run_institution_builder(user) + described_class.run(user) expect(Rails.logger).to have_received(:error).with(error_message) end - it 'does not change the institutions or versions if not successful', strategy: :truncation do + it 'does not change the institutions or versions if not successful' do allow(factory_class).to receive(:add_crosswalk).and_raise(StandardError, 'BOOM!') create :version version = Version.current_production - run_institution_builder(user) + described_class.run(user) expect(Institution.count).to be_zero expect(Version.current_production).to eq(version) end @@ -77,7 +77,7 @@ let(:institution) { institutions.first } before do - run_institution_builder(user) + described_class.run(user) end it 'adds approved schools only' do @@ -101,7 +101,7 @@ it 'duplicates in WEAMs are not present in institutions' do create :weam, facility_code: '18181818', institution: 'REAL SCHOOL' create :weam, facility_code: '18181818', institution: 'FAKE SCHOOL' - run_institution_builder(user) + described_class.run(user) expect(institutions.where(facility_code: '18181818').count).to eq(1) end end @@ -111,7 +111,7 @@ let(:crosswalk) { Crosswalk.first } before do - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions when weams does not populate xwalk data' do @@ -131,7 +131,7 @@ weam.update_columns(cross: '2YYYYYYY', ope: '00380200') # rubocop:enable Rails/SkipsModelValidations - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions when weams does not populate xwalk data' do @@ -147,7 +147,7 @@ before do create :sva, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -165,7 +165,7 @@ before do create :vsoc, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -181,7 +181,7 @@ before do create :eight_key, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'sets eight_keys to TRUE for every eight_key record' do @@ -196,14 +196,14 @@ describe 'with regards to the time frame' do it 'only adds current accreditations' do create :accreditation_record - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).not_to be_nil end - it 'does not add non-current accreditations' do + it 'does not add non-current accreditations (end date is not null)' do create :accreditation_record_expired - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).to be_nil end @@ -212,25 +212,47 @@ describe 'with regards to the accrediting authority' do it 'adds institutional accreditations' do create :accreditation_record - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).not_to be_nil end - it 'does not add non-institutional accreditations' do + it 'does not add non-institutional accreditations (program id is not 1)' do create :accreditation_record, program_id: 2 - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).to be_nil end end + describe 'with regards to missing intermediate table matches' do + it 'does not add accreditations for institutions that do not have an ope match' do + weam = Weam.first + # rubocop:disable Rails/SkipsModelValidations + weam.update_columns(ope: 'junk') + # rubocop:enable Rails/SkipsModelValidations + create :accreditation_record + described_class.run(user) + + institution = Institution.first + expect(institution.accreditation_type).to be_nil + end + + it 'does not add accreditations when there is no dapip_id match' do + create :accreditation_record, dapip_id: -1 + described_class.run(user) + + institution = Institution.first + expect(institution.accreditation_type).to be_nil + end + end + describe 'the accreditation_type' do AccreditationRecord::ACCREDITATIONS.each_pair do |type, agency_regex_array| agency_regex_array.map(&:source).each do |agency_name| it "is set to #{type} when the agency name contains '#{agency_name}'" do create :accreditation_record, agency_name: 'Agency ' + agency_name - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).to eq(type) end end @@ -239,7 +261,7 @@ it 'prefers national over hybrid' do create :accreditation_record, agency_name: 'Biblical School' create :accreditation_record, agency_name: 'Design School' - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).to eq('national') end @@ -247,7 +269,7 @@ create :accreditation_record, agency_name: 'Biblical School' create :accreditation_record, agency_name: 'Middle School' create :accreditation_record, agency_name: 'Design School' - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_type).to eq('regional') end end @@ -255,31 +277,31 @@ describe 'the accreditation status' do it 'is set only for the `AccreditationAction::PROBATIONARY_STATUSES`' do create :accreditation_action - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_status).to be_nil end AccreditationAction::PROBATIONARY_STATUSES.each do |status| - it "is set for #{status}", strategy: :truncation do + it "is set for #{status}" do create :accreditation_action, action_description: status[1..-2] - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_status).to eq(status[1..-2]) end end AccreditationAction::RESTORATIVE_STATUSES.each do |status| - it "with a current 'restore' action, it doesn't set the accreditation_status", strategy: :truncation do + it "with a current 'restore' action, it doesn't set the accreditation_status" do create :accreditation_action, action_description: AccreditationAction::PROBATIONARY_STATUSES.first[1..-2], action_date: '2019-01-06' create :accreditation_action, action_description: status[1..-2], action_date: '2019-01-09' - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_status).to be_nil end end it 'does not matter if an `accreditation_type` is set' do create :accreditation_action_probationary - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_status).to be_truthy expect(institution.accreditation_type).to be_nil end @@ -287,7 +309,7 @@ it 'does not matter if accreditation is current' do create :accreditation_record, accreditation_end_date: '2011-01-01' create :accreditation_action_probationary - run_institution_builder(user) + described_class.run(user) expect(institution.accreditation_status).to be_truthy expect(institution.accreditation_type).to be_nil end @@ -296,7 +318,7 @@ describe 'the accreditation_action caution_flags' do it 'has flags for any non-nil status' do create :accreditation_action_probationary - run_institution_builder(user) + described_class.run(user) expect(CautionFlag .where({ institution_id: institution.id, @@ -307,7 +329,7 @@ it 'has no flags for any nil status' do create :accreditation_action - run_institution_builder(user) + described_class.run(user) expect(CautionFlag .where({ institution_id: institution.id, @@ -319,7 +341,7 @@ it 'concatenates `action_description` and `justification_description`' do aap = create :accreditation_action_probationary - run_institution_builder(user) + described_class.run(user) caution_flags = CautionFlag.where({ institution_id: institution.id, source: AccreditationCautionFlag::NAME, @@ -337,7 +359,7 @@ before do create :arf_gi_bill, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -351,7 +373,7 @@ before do create :post911_stat, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -368,14 +390,14 @@ it 'copies columns used by institutions' do create :mou, :institution_builder - run_institution_builder(user) + described_class.run(user) expect(mou.dodmou).to eq(institution.dodmou) end describe 'the mou caution_flag' do it 'has flags when dod_status is true' do create :mou, :institution_builder, :by_dod - run_institution_builder(user) + described_class.run(user) expect(CautionFlag .where({ institution_id: institution.id, source: MouCautionFlag::NAME, @@ -385,7 +407,7 @@ it 'has no flags when dod_status is not true' do create :mou, :institution_builder, :by_title_iv - run_institution_builder(user) + described_class.run(user) expect(CautionFlag .where({ institution_id: institution.id, source: MouCautionFlag::NAME, @@ -397,7 +419,7 @@ describe 'the caution_flag_reason' do it 'is set when dod_status is true' do create :mou, :institution_builder, :by_dod - run_institution_builder(user) + described_class.run(user) caution_flags = CautionFlag.where({ institution_id: institution.id, source: MouCautionFlag::NAME, version_id: Version.current_production.id }).count @@ -415,7 +437,7 @@ before do create :scorecard, :institution_builder, :new_mission_fields - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -431,7 +453,7 @@ before do create :ipeds_ic, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -447,7 +469,7 @@ before do create :ipeds_hd, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -463,7 +485,7 @@ before do create :ipeds_ic_ay, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -483,7 +505,7 @@ context 'when the institution fields are nil' do it 'copies columns used by institutions' do create :ipeds_ic_py, :institution_builder - run_institution_builder(user) + described_class.run(user) IpedsIcPy::COLS_USED_IN_INSTITUTION.each do |column| expect(ipeds_ic_py[column]).to eq(institution[column]) end @@ -506,7 +528,7 @@ def check_ipeds_ic_ay it 'the institution record matches the ipeds_ic_ay record' do create :ipeds_ic_ay, :institution_builder create :ipeds_ic_py, :institution_builder - run_institution_builder(user) + described_class.run(user) check_ipeds_ic_py check_ipeds_ic_ay end @@ -521,14 +543,14 @@ def check_ipeds_ic_ay create :va_caution_flag, :not_sec_702, facility_code: weam_row.facility_code create :sec702, state: weam_row.state - run_institution_builder(user) + described_class.run(user) expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).to be_nil end it 'the institution is unaffected by Sec702' do create :sec702, state: weam_row.state - run_institution_builder(user) + described_class.run(user) expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).to be_nil end end @@ -538,7 +560,7 @@ def check_ipeds_ic_ay it 'is set from Section702' do create :sec702, state: weam_row.state - run_institution_builder(user) + described_class.run(user) expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).not_to be_nil expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).to be_falsy end @@ -546,7 +568,7 @@ def check_ipeds_ic_ay it 'is set from VA Caution Flags when a row exists' do create :va_caution_flag, :not_sec_702, facility_code: weam_row.facility_code create :sec702, state: weam_row.state, sec_702: true - run_institution_builder(user) + described_class.run(user) expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).not_to be_nil expect(institutions.find_by(facility_code: weam_row.facility_code).sec_702).to be_falsey end @@ -557,7 +579,7 @@ def check_ipeds_ic_ay it 'has flags from Section702 when sec_702 is false' do create :sec702, state: weam_row.state - run_institution_builder(user) + described_class.run(user) institution = institutions.find_by(facility_code: weam_row.facility_code) expect(CautionFlag @@ -571,7 +593,7 @@ def check_ipeds_ic_ay create :va_caution_flag, :not_sec_702, facility_code: weam_row.facility_code create :sec702, state: weam_row.state, sec_702: true - run_institution_builder(user) + described_class.run(user) institution = institutions.find_by(facility_code: weam_row.facility_code) expect(CautionFlag.where({ source: Sec702CautionFlag::NAME, institution_id: institution.id, @@ -584,7 +606,7 @@ def check_ipeds_ic_ay it 'a caution_flag is set with title and description' do weam_row = create :weam, :weam_builder va_caution_flag = create :va_caution_flag, :settlement, facility_code: weam_row.facility_code - run_institution_builder(user) + described_class.run(user) institution = institutions.find_by(facility_code: weam_row.facility_code) caution_flag = CautionFlag.where({ institution_id: institution.id, source: 'Settlement', @@ -600,7 +622,7 @@ def check_ipeds_ic_ay weam_row1 = create :weam, :weam_builder, facility_code: crosswalk1.facility_code weam_row2 = create :weam, :weam_builder, facility_code: crosswalk2.facility_code va_caution_flag = create :va_caution_flag, :settlement, facility_code: crosswalk1.facility_code - run_institution_builder(user) + described_class.run(user) institution1 = institutions.find_by(facility_code: weam_row1.facility_code) institution2 = institutions.find_by(facility_code: weam_row2.facility_code) @@ -620,7 +642,7 @@ def check_ipeds_ic_ay flag_a = create :va_caution_flag, :settlement, facility_code: weam_row.facility_code flag_b = create :va_caution_flag, :settlement, facility_code: weam_row.facility_code, settlement_title: 'another title' - run_institution_builder(user) + described_class.run(user) institution = institutions.find_by(facility_code: weam_row.facility_code) caution_flags = CautionFlag.where({ institution_id: institution.id, source: 'Settlement', version_id: Version.current_production.id }).count @@ -636,7 +658,7 @@ def check_ipeds_ic_ay describe 'the caution_flag' do it 'has flags for every heightened cash monitoring notice' do create :hcm, :institution_builder - run_institution_builder(user) + described_class.run(user) expect(CautionFlag .where({ institution_id: institution.id, source: HcmCautionFlag::NAME, @@ -648,7 +670,7 @@ def check_ipeds_ic_ay describe 'the caution_flag_reason' do it 'has flag set to the hcm_reason' do create :hcm, :institution_builder - run_institution_builder(user) + described_class.run(user) caution_flags = CautionFlag.where({ institution_id: institution.id, source: HcmCautionFlag::NAME, version_id: Version.current_production.id }).count @@ -661,7 +683,7 @@ def check_ipeds_ic_ay it 'has flag with multiple hcm_reason' do create :hcm, :institution_builder create :hcm, :institution_builder, hcm_reason: 'another reason' - run_institution_builder(user) + described_class.run(user) caution_flags = CautionFlag.where({ institution_id: institution.id, source: HcmCautionFlag::NAME, version_id: Version.current_production.id }).count expect(caution_flags).to be > 0 @@ -681,18 +703,18 @@ def check_ipeds_ic_ay it 'calls update_ope_from_crosswalk' do allow(Complaint).to receive(:update_ope_from_crosswalk) - run_institution_builder(user) + described_class.run(user) expect(Complaint).to have_received(:update_ope_from_crosswalk) end - it 'calls rollup_sums for facility_code and ope6', strategy: :truncation do + it 'calls rollup_sums for facility_code and ope6' do allow(Complaint).to receive(:rollup_sums).twice - run_institution_builder(user) + described_class.run(user) expect(Complaint).to have_received(:rollup_sums).twice end it 'sums complaints by facility_code' do - run_institution_builder(user) + described_class.run(user) Complaint::FAC_CODE_ROLL_UP_SUMS.each_key do |column| expect(institution[column]).to eq(2) @@ -700,7 +722,7 @@ def check_ipeds_ic_ay end it 'sums complaints by ope6' do - run_institution_builder(user) + described_class.run(user) Complaint::OPE6_ROLL_UP_SUMS.each_key do |column| expect(institution[column]).to eq(2) @@ -714,7 +736,7 @@ def check_ipeds_ic_ay before do create :outcome, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'copies columns used by institutions' do @@ -733,7 +755,7 @@ def check_ipeds_ic_ay it 'updates stem_offered' do create :ipeds_cip_code, :institution_builder create :stem_cip_code - run_institution_builder(user) + described_class.run(user) expect(institution.stem_offered).to be(true) end end @@ -742,7 +764,7 @@ def check_ipeds_ic_ay let(:institution) { Institution.first } it 'does not set stem_offered' do - run_institution_builder(user) + described_class.run(user) expect(institution.stem_offered).to be(false) end end @@ -751,7 +773,7 @@ def check_ipeds_ic_ay it 'does not set stem_offered' do create :ipeds_cip_code, :institution_builder, ctotalt: 0 create :stem_cip_code - run_institution_builder(user) + described_class.run(user) expect(institution.stem_offered).to be(false) end end @@ -759,7 +781,7 @@ def check_ipeds_ic_ay context 'when there is no matching stem cip code' do it 'does not set stem_offered' do create :ipeds_cip_code, :institution_builder, cipcode: 0.3 - run_institution_builder(user) + described_class.run(user) expect(institution.stem_offered).to be(false) end end @@ -771,7 +793,7 @@ def check_ipeds_ic_ay before do create :yellow_ribbon_program_source, :institution_builder - run_institution_builder(user) + described_class.run(user) end it 'generates a yellow ribbon program' do @@ -794,7 +816,7 @@ def check_ipeds_ic_ay before do create :va_caution_flag, :school_closing, facility_code: Weam.first.facility_code - run_institution_builder(user) + described_class.run(user) end it 'sets school_closing' do @@ -810,7 +832,7 @@ def check_ipeds_ic_ay describe 'when adding Vet Tec Provider data' do before do create(:weam, :vet_tec) - run_institution_builder(user) + described_class.run(user) end let(:institution) { institutions.find_by(facility_code: '1VZZZZZZ') } @@ -826,7 +848,7 @@ def check_ipeds_ic_ay before do create :weam, :zipcode_rate - run_institution_builder(user) + described_class.run(user) end it 'properly generates zipcode rates from weams data' do @@ -843,7 +865,7 @@ def check_ipeds_ic_ay create :program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) expect(InstitutionProgram.first.institution_id).to eq(Institution.first.id) expect(Institution.first.version_id).to eq(Version.current_production.id) end @@ -853,7 +875,7 @@ def check_ipeds_ic_ay create :edu_program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) end it 'does not generate duplicate institution programs for duplicate edu-programs with differently cased names' do @@ -861,7 +883,7 @@ def check_ipeds_ic_ay create :edu_program, facility_code: '1ZZZZZZZ', vet_tec_program: 'computer science' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) end it 'does not generate duplicate institution programs for duplicate programs' do @@ -869,7 +891,7 @@ def check_ipeds_ic_ay create :program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) end it 'does not generate duplicate institution programs for duplicate programs with differently cased names' do @@ -877,7 +899,7 @@ def check_ipeds_ic_ay create :program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) end it 'defaults deduped InstitutionProgram length_in_weeks to 0' do @@ -885,14 +907,14 @@ def check_ipeds_ic_ay create :edu_program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '1ZZZZZZZ' - expect { run_institution_builder(user) }.to change(InstitutionProgram, :count).from(0).to(1) + expect { described_class.run(user) }.to change(InstitutionProgram, :count).from(0).to(1) expect(InstitutionProgram.first.length_in_weeks).to eq(0) end it 'does not generate institution programs without matching programs and edu_programs' do create :program, facility_code: '1ZZZZZZZ' create :edu_program, facility_code: '0001' - run_institution_builder(user) + described_class.run(user) expect(InstitutionProgram.count).to eq(0) end end @@ -901,7 +923,7 @@ def check_ipeds_ic_ay before do create(:weam, :extension) create(:weam, facility_code: '10X00001', campus_type: 'Y') - run_institution_builder(user) + described_class.run(user) end it 'sets campus_type to "E"' do @@ -918,7 +940,7 @@ def check_ipeds_ic_ay describe 'when setting approved' do before do create(:weam, :as_vet_tec_provider) - run_institution_builder(user) + described_class.run(user) end it 'sets correctly for VET TEC institution' do @@ -930,21 +952,21 @@ def check_ipeds_ic_ay it 'properly generates school certifying official with instituion_id' do weam = create(:weam) create :school_certifying_official, facility_code: weam.facility_code - expect { run_institution_builder(user) }.to change(VersionedSchoolCertifyingOfficial, :count).from(0).to(1) + expect { described_class.run(user) }.to change(VersionedSchoolCertifyingOfficial, :count).from(0).to(1) expect(VersionedSchoolCertifyingOfficial.last.institution_id).to be_present end it 'ignores priority casing' do weam = create(:weam) create :school_certifying_official, facility_code: weam.facility_code, priority: 'primarY' - expect { run_institution_builder(user) }.to change(VersionedSchoolCertifyingOfficial, :count).from(0).to(1) + expect { described_class.run(user) }.to change(VersionedSchoolCertifyingOfficial, :count).from(0).to(1) expect(VersionedSchoolCertifyingOfficial.last.institution_id).to be_present end it 'does not create VSCO for SCO with invalid priority value' do weam = create(:weam) create :school_certifying_official, :invalid_priority, facility_code: weam.facility_code - run_institution_builder(user) + described_class.run(user) expect(VersionedSchoolCertifyingOfficial.count).to be_zero end end @@ -952,7 +974,7 @@ def check_ipeds_ic_ay describe 'when setting section 103 data' do it 'sets default message for IHL institutions' do weam = create :weam, :ihl_facility_code - run_institution_builder(user) + described_class.run(user) expect(institutions.where("facility_code = '#{weam.facility_code}'").first['section_103_message']) .to eq('no') @@ -960,7 +982,7 @@ def check_ipeds_ic_ay it 'does not set default message for nonIHL institutions' do weam = create :weam - run_institution_builder(user) + described_class.run(user) expect(institutions.where("facility_code = '#{weam.facility_code}'").first['section_103_message']) .to eq('no') @@ -970,7 +992,7 @@ def check_ipeds_ic_ay weam = create :weam, :ihl_facility_code create :sec103, facility_code: weam.facility_code - run_institution_builder(user) + described_class.run(user) expect(institutions.where("facility_code = '#{weam.facility_code}'").first['section_103_message']) .to eq('Yes') @@ -980,7 +1002,7 @@ def check_ipeds_ic_ay weam = create :weam, :ihl_facility_code create :sec103, :requires_additional, facility_code: weam.facility_code - run_institution_builder(user) + described_class.run(user) expect(institutions.where("facility_code = '#{weam.facility_code}'").first['section_103_message']) .to eq('Yes') @@ -990,7 +1012,7 @@ def check_ipeds_ic_ay weam = create :weam, :ihl_facility_code, :approved_poo_and_law_code, :with_approved_indicators create :sec103, :does_not_comply, facility_code: weam.facility_code - run_institution_builder(user) + described_class.run(user) expect(institutions.where("facility_code = '#{weam.facility_code}'").first['approved']).to eq(false) end @@ -1000,7 +1022,7 @@ def check_ipeds_ic_ay it 'sets latitude and longitdue from CensusLatLong' do weam = create(:weam) census_lat_long = create(:census_lat_long, facility_code: weam.facility_code) - run_institution_builder(user) + described_class.run(user) institution = institutions.where(facility_code: weam.facility_code).first institution.longitude = census_lat_long.interpolated_longitude_latitude.split(',')[0] institution.latitude = census_lat_long.interpolated_longitude_latitude.split(',')[1] @@ -1027,7 +1049,7 @@ def check_ipeds_ic_ay institution.longitude = 39.14 institution.latitude = -75.09 institution.save - run_institution_builder(user) + described_class.run(user) institution2 = Institution.last expect(institution2.version_id).to eq(Version.current_production.id) @@ -1040,7 +1062,7 @@ def check_ipeds_ic_ay institution.latitude = -75.09 institution.physical_zip = '22222' institution.save - run_institution_builder(user) + described_class.run(user) institution2 = Institution.last expect(institution2.version_id).to eq(Version.current_production.id) expect(institution2.longitude).not_to eq(39.14) @@ -1065,13 +1087,13 @@ def check_ipeds_ic_ay it 'counts number of total institution ratings' do expect(InstitutionSchoolRating.count).to eq(2) - run_institution_builder(user) + described_class.run(user) institution2 = Institution.last expect(institution2.institution_rating.institution_rating_count).to eq(2) end it 'counts the number of responses for each question' do - run_institution_builder(user) + described_class.run(user) institution_rating = Institution.last.institution_rating 1.upto(14) do |j| next if j.eql?(6) # question 6 is yes/no, doesn't get used for ratings @@ -1081,14 +1103,14 @@ def check_ipeds_ic_ay end it 'averages overall institution rating' do - run_institution_builder(user) + described_class.run(user) institution2 = Institution.last expect(institution2.institution_rating.overall_avg).to eq(1.9) end it 'calculates the average response for each question' do create :institution_school_rating, :third_rating - run_institution_builder(user) + described_class.run(user) institution_rating = Institution.last.institution_rating 1.upto(14) do |j| next if j.eql?(6) # question 6 is yes/no, doesn't get used for ratings @@ -1102,13 +1124,13 @@ def check_ipeds_ic_ay weam.facility_code = '11000001' weam.save(validate: false) - run_institution_builder(user) + described_class.run(user) ins = Institution.where(facility_code: '11000001').first expect(ins.institution_rating).to be_nil end it 'calculates correct average ratings for every main category' do - run_institution_builder(user) + described_class.run(user) institution2 = Institution.last expect(institution2.institution_rating.m1_avg).to eq(2.0) expect(institution2.institution_rating.m2_avg).to eq(1.8) @@ -1118,7 +1140,7 @@ def check_ipeds_ic_ay it 'does not include null or <=0 in question counts' do create :institution_school_rating, :nil_rating - run_institution_builder(user) + described_class.run(user) institution_rating = Institution.last.institution_rating 1.upto(14) do |j| next if j.eql?(6) # question 6 is yes/no, doesn't get used for ratings @@ -1132,7 +1154,7 @@ def check_ipeds_ic_ay create :institution_school_rating, :third_rating create :institution_school_rating, :nil_rating - run_institution_builder(user) + described_class.run(user) institution_rating = Institution.last.institution_rating 1.upto(14) do |j| next if j.eql?(6) # question 6 is yes/no, doesn't get used for ratings @@ -1146,7 +1168,7 @@ def check_ipeds_ic_ay create :institution_school_rating, :third_rating create :institution_school_rating, :greater_than_4_rating - run_institution_builder(user) + described_class.run(user) institution_rating = Institution.last.institution_rating 1.upto(14) do |j| next if j.eql?(6) # question 6 is yes/no, doesn't get used for ratings @@ -1175,13 +1197,8 @@ def check_ipeds_ic_ay it "removes from approved institutions with celo other than 'n' " do expect(Institution.approved_institutions(Version.last.id).count).to eq(2) - run_institution_builder(user) + described_class.run(user) expect(Institution.approved_institutions(Version.last.id).count).to eq(1) end end - - def run_institution_builder(user) - described_class.run(user) - sleep(0.2) - end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fc7b107a6..e27480444 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -92,6 +92,14 @@ # each test. (MPH) config.after do DatabaseCleaner.clean + + # After trying numerous hacks recommended by Google searches, this is the only + # hack we found that works and it was homegrown. None of the recommended fixes + # worked at all. + rescue NoMethodError => e + puts "\n\n*** DatabaseCleaner failed: #{e.message}, trying again ***\n\n" + sleep(0.1) + DatabaseCleaner.clean end # RSpec Rails can automatically mix in different behaviours to your tests