From 5728305044ec18c3e0594b96ff10af33fb4b495b Mon Sep 17 00:00:00 2001 From: Jon Roberts Date: Tue, 24 Sep 2024 22:16:03 -0400 Subject: [PATCH 1/2] spec changes --- app/models/case_contact.rb | 13 ++----------- config/locales/en.yml | 14 ++++++++++++++ config/routes.rb | 2 +- spec/factories/casa_cases.rb | 10 ++++++++++ spec/factories/casa_orgs.rb | 5 +++++ spec/factories/case_contacts.rb | 4 +++- spec/factories/supervisors.rb | 10 ++++++++++ spec/factories/volunteers.rb | 9 +++++---- spec/models/case_contact_spec.rb | 6 +++--- spec/requests/case_contacts/form_spec.rb | 2 +- spec/spec_helper.rb | 2 ++ spec/support/capybara.rb | 2 +- .../fill_out_minimum_required_form_fields.rb | 15 --------------- spec/system/case_contacts/new_spec.rb | 2 +- 14 files changed, 58 insertions(+), 38 deletions(-) delete mode 100644 spec/support/fill_out_minimum_required_form_fields.rb diff --git a/app/models/case_contact.rb b/app/models/case_contact.rb index 7a8451074b..cad1fdacc6 100644 --- a/app/models/case_contact.rb +++ b/app/models/case_contact.rb @@ -4,7 +4,7 @@ class CaseContact < ApplicationRecord attr_accessor :duration_hours - validate :contact_made_chosen + validates :contact_made, inclusion: {in: [true, false], message: :must_be_true_or_false} validates :miles_driven, numericality: {greater_than_or_equal_to: 0, less_than: 10000} validates :medium_type, presence: true, if: :active_or_details? validates :duration_minutes, presence: true, if: :active_or_details? @@ -35,7 +35,7 @@ class CaseContact < ApplicationRecord belongs_to :casa_case, optional: true has_one :casa_org, through: :casa_case validates :casa_case_id, presence: true, if: :active? - validate :draft_case_ids_not_empty, unless: :started? + validates :draft_case_ids, presence: {message: :must_be_selected}, unless: :started? has_many :case_contact_contact_types has_many :contact_types, through: :case_contact_contact_types @@ -231,15 +231,6 @@ def volunteer_address_is_valid end end - def contact_made_chosen - errors.add(:base, "Must enter whether the contact was made.") if contact_made.nil? - !contact_made.nil? - end - - def draft_case_ids_not_empty - errors.add(:base, "You must select at least one casa case.") if draft_case_ids.empty? - end - def supervisor_id supervisor.id end diff --git a/config/locales/en.yml b/config/locales/en.yml index 97346e5d9e..3e42aaf7a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -33,10 +33,24 @@ en: activerecord: attributes: case_contact: + case_contact_contact_types: + one: Contact Type + other: Contact Types + contact_types: + one: Contact Type + other: Contact Types + draft_case_ids: + one: CASA Case + other: CASA Cases occurred_at: Date + case_contact/additional_expenses: + other_expenses_amount: Expense amount + other_expenses_describe: Expense description errors: messages: cant_be_future: can't be in the future + must_be_selected: must be selected + must_be_true_or_false: must be true or false time: formats: day_and_date: "%A, %b %d, %Y" diff --git a/config/routes.rb b/config/routes.rb index ac967a6435..95b62d5c59 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,7 +90,7 @@ member do post :restore end - resources :form, controller: "case_contacts/form" + resources :form, controller: "case_contacts/form", only: %i[show update] resources :followups, only: %i[create], controller: "case_contacts/followups", shallow: true do patch :resolve, on: :member end diff --git a/spec/factories/casa_cases.rb b/spec/factories/casa_cases.rb index 64531979a8..39d4987313 100644 --- a/spec/factories/casa_cases.rb +++ b/spec/factories/casa_cases.rb @@ -6,6 +6,16 @@ court_report_status { :not_submitted } case_court_orders { [] } + transient do + volunteers { [] } + end + + after(:create) do |casa_case, evaluator| + Array.wrap(evaluator.volunteers).each do |volunteer| + create(:case_assignment, casa_case:, volunteer:) + end + end + trait :pre_transition do birth_month_year_youth { 13.years.ago } end diff --git a/spec/factories/casa_orgs.rb b/spec/factories/casa_orgs.rb index 7017f88bf8..d4146bebdf 100644 --- a/spec/factories/casa_orgs.rb +++ b/spec/factories/casa_orgs.rb @@ -13,6 +13,11 @@ logo { Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "org_logo.jpeg")) } end + trait :all_reimbursements_enabled do + additional_expenses_enabled { true } + show_driving_reimbursement { true } + end + trait :with_placement_types do transient { placement_names { ["Reunification", "Adoption", "Foster Care", "Kinship"] } } diff --git a/spec/factories/case_contacts.rb b/spec/factories/case_contacts.rb index 474df9e186..ad62fa9004 100644 --- a/spec/factories/case_contacts.rb +++ b/spec/factories/case_contacts.rb @@ -13,7 +13,7 @@ association :creator, factory: :user casa_case - contact_types { [create(:contact_type)] } + contact_types { [association(:contact_type)] } duration_minutes { 60 } occurred_at { Time.zone.today } contact_made { false } @@ -38,12 +38,14 @@ trait :wants_reimbursement do miles_driven { 456 } want_driving_reimbursement { true } + volunteer_address { "123 Contact Factory St" } end trait :started_status do started # enum trait casa_case { nil } + contact_types { [] } draft_case_ids { [] } medium_type { nil } occurred_at { nil } diff --git a/spec/factories/supervisors.rb b/spec/factories/supervisors.rb index 8ac1ebe4c7..0dc47b61f6 100644 --- a/spec/factories/supervisors.rb +++ b/spec/factories/supervisors.rb @@ -3,6 +3,16 @@ display_name { Faker::Name.unique.name } active { true } + transient do + volunteers { [] } + end + + after(:create) do |supervisor, evaluator| + Array.wrap(evaluator.volunteers).each do |volunteer| + create(:supervisor_volunteer, supervisor:, volunteer:) + end + end + trait :with_casa_cases do after(:create) do |user, _| volunteer = create(:volunteer) diff --git a/spec/factories/volunteers.rb b/spec/factories/volunteers.rb index c53bced149..768d98b5ba 100644 --- a/spec/factories/volunteers.rb +++ b/spec/factories/volunteers.rb @@ -31,10 +31,11 @@ end trait :with_assigned_supervisor do - transient { supervisor { create(:supervisor) } } + transient { supervisor { nil } } - after(:create) do |user, evaluator| - create(:supervisor_volunteer, volunteer: user, supervisor: evaluator.supervisor) + after(:create) do |volunteer, evaluator| + supervisor = evaluator.supervisor || create(:supervisor, casa_org: volunteer.casa_org) + create(:supervisor_volunteer, volunteer:, supervisor:) end end @@ -46,7 +47,7 @@ end end - trait :with_disasllow_reimbursement do + trait :with_disallow_reimbursement do after(:create) do |user, _| create(:case_assignment, :disallow_reimbursement, casa_case: create(:casa_case, casa_org: user.casa_org), volunteer: user) end diff --git a/spec/models/case_contact_spec.rb b/spec/models/case_contact_spec.rb index 9cf470418c..af6078516e 100644 --- a/spec/models/case_contact_spec.rb +++ b/spec/models/case_contact_spec.rb @@ -68,7 +68,7 @@ it "validates that contact_made cannot be null" do case_contact = build_stubbed(:case_contact, contact_made: nil) expect(case_contact).not_to be_valid - expect(case_contact.errors[:base]).to eq(["Must enter whether the contact was made."]) + expect(case_contact.errors.full_messages).to include("Contact made must be true or false") end it "can be updated even if it is old" do @@ -113,7 +113,7 @@ it "requires a case to be selected" do case_contact = build_stubbed(:case_contact, :details_status, draft_case_ids: []) expect(case_contact).not_to be_valid - expect(case_contact.errors.full_messages).to include("You must select at least one casa case.") + expect(case_contact.errors.full_messages).to include("CASA Case must be selected") end it "requires occurred at" do @@ -140,7 +140,7 @@ it "requires a case to be selected" do obj = build_stubbed(:case_contact, :expenses_status, :wants_reimbursement, draft_case_ids: []) expect(obj).not_to be_valid - expect(obj.errors.full_messages).to include("You must select at least one casa case.") + expect(obj.errors.full_messages).to include("CASA Case must be selected") end end diff --git a/spec/requests/case_contacts/form_spec.rb b/spec/requests/case_contacts/form_spec.rb index a5bfca2fd2..7d5dc048ba 100644 --- a/spec/requests/case_contacts/form_spec.rb +++ b/spec/requests/case_contacts/form_spec.rb @@ -194,7 +194,7 @@ end context "when updating contact types" do - let(:old_contact_type) { create(:case_contact_contact_type, case_contact: case_contact, contact_type: contact_type_group_b.contact_types.first.id) } + let!(:old_contact_type) { create(:case_contact_contact_type, case_contact: case_contact, contact_type: contact_type_group_b.contact_types.first) } it "removes unselected ones" do expect(case_contact.contact_types.count).to eq 1 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3a28b666ee..fd672a2981 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,4 +44,6 @@ # the seed, which is printed after each run. # --seed 1234 config.order = :random + + RSpec::Matchers.define_negated_matcher :not_change, :change end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 4ed308b033..4964d10e7f 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -45,7 +45,7 @@ def self.capybara_tmp_path # used without docker Capybara.register_driver :selenium_chrome_headless do |app| - options.add_argument("--headless") + options.add_argument("--headless") unless ENV.fetch("HEADED", false) options.add_argument("--disable-site-isolation-trials") options.add_preference(:download, prompt_for_download: false, default_directory: DownloadHelpers::PATH.to_s) diff --git a/spec/support/fill_out_minimum_required_form_fields.rb b/spec/support/fill_out_minimum_required_form_fields.rb deleted file mode 100644 index cbccd2055c..0000000000 --- a/spec/support/fill_out_minimum_required_form_fields.rb +++ /dev/null @@ -1,15 +0,0 @@ -module FillOutMinimumRequiredFields - def fill_out_minimum_required_fields_for_case_contact_form - check "School" - within "#enter-contact-details" do - choose "Yes" - end - choose "Video" - - fill_in "case_contact_duration_hours", with: "1" - end -end - -RSpec.configure do |config| - config.include FillOutMinimumRequiredFields, type: :system -end diff --git a/spec/system/case_contacts/new_spec.rb b/spec/system/case_contacts/new_spec.rb index 9858dcf139..69b1050b72 100644 --- a/spec/system/case_contacts/new_spec.rb +++ b/spec/system/case_contacts/new_spec.rb @@ -225,7 +225,7 @@ context "when driving reimbursement is hidden when volunteer not allowed to request" do let(:casa_org) { build(:casa_org, show_driving_reimbursement: true) } - let(:volunteer) { create(:volunteer, :with_disasllow_reimbursement, casa_org:) } + let(:volunteer) { create(:volunteer, :with_disallow_reimbursement, casa_org:) } it "does not show for case_contacts" do subject From 9adb1208769f8673a5dacf45f62b34624d707a46 Mon Sep 17 00:00:00 2001 From: Jon Roberts Date: Wed, 25 Sep 2024 21:49:11 -0400 Subject: [PATCH 2/2] revert headed env addition --- spec/support/capybara.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 4964d10e7f..4ed308b033 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -45,7 +45,7 @@ def self.capybara_tmp_path # used without docker Capybara.register_driver :selenium_chrome_headless do |app| - options.add_argument("--headless") unless ENV.fetch("HEADED", false) + options.add_argument("--headless") options.add_argument("--disable-site-isolation-trials") options.add_preference(:download, prompt_for_download: false, default_directory: DownloadHelpers::PATH.to_s)