From aee64146c285caca2f3e00bb4c0d8a245a26f9da Mon Sep 17 00:00:00 2001 From: compiledwrong Date: Sun, 5 May 2024 11:19:55 -0400 Subject: [PATCH 1/3] spec --- .../case_contacts/form_controller.rb | 2 +- spec/requests/case_contacts/form_spec.rb | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/case_contacts/form_controller.rb b/app/controllers/case_contacts/form_controller.rb index b8c69b2f0f..2d6644112e 100644 --- a/app/controllers/case_contacts/form_controller.rb +++ b/app/controllers/case_contacts/form_controller.rb @@ -36,7 +36,7 @@ def update remove_unwanted_contact_types remove_nil_draft_ids - if @case_contact.update(case_contact_params) + if params[:case_contact] && @case_contact.update(case_contact_params) respond_to do |format| format.html { if step == steps.last diff --git a/spec/requests/case_contacts/form_spec.rb b/spec/requests/case_contacts/form_spec.rb index afb89b961b..771775c99e 100644 --- a/spec/requests/case_contacts/form_spec.rb +++ b/spec/requests/case_contacts/form_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe "CaseContacts::Forms", type: :request do +RSpec.describe "CaseContacts::FormController", type: :request do let(:organization) { build(:casa_org) } let(:admin) { create(:casa_admin, casa_org: organization) } let(:supervisor) { create(:supervisor, casa_org: organization) } @@ -319,6 +319,23 @@ end let(:step) { :expenses } + context "without expenses" do + it "works" do + params = { + "_method": "patch", + "authenticity_token": "9Tca3rlxbuO06MCrqN88ijrAgGKeY0O4X7AsRZipvA6T-COiep9YvWGXoqDws6cv38gBjUKrKljh2j0bFugCug", + "button": "", + "controller": "case_contacts/form", + "action": "update", + "case_contact_id": case_contact.id, + "id": "expenses" + } + patch "/case_contacts/#{case_contact.id}/form/#{step}", params: params + + expect(response.status).to eq("??") + end + end + context "with valid attributes" do let(:attributes) do { From 2ff80a81a15a89046af0bbc52ab67566cde8cf18 Mon Sep 17 00:00:00 2001 From: compiledwrong Date: Sun, 5 May 2024 15:19:46 -0400 Subject: [PATCH 2/3] Fix prod: Error happens when trying to fill in the details page on a case contact for an org that has neither reimbursement or travel expenses enabled. --- .tool-versions | 1 + .../case_contacts/form_controller.rb | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.tool-versions b/.tool-versions index 91cc785efd..24e0bd7611 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ ruby 3.2.2 yarn 1.22.19 +nodejs 22.1.0 \ No newline at end of file diff --git a/app/controllers/case_contacts/form_controller.rb b/app/controllers/case_contacts/form_controller.rb index 2d6644112e..b309abdfbf 100644 --- a/app/controllers/case_contacts/form_controller.rb +++ b/app/controllers/case_contacts/form_controller.rb @@ -34,9 +34,21 @@ def update end end - remove_unwanted_contact_types - remove_nil_draft_ids - if params[:case_contact] && @case_contact.update(case_contact_params) + if params[:case_contact] + remove_unwanted_contact_types + remove_nil_draft_ids + end + if params[:case_contact].empty? + format.html { + if step == steps.last + finish_editing + else + render_wizard @case_contact, {}, {case_contact_id: @case_contact.id} + end + } + format.json { head :ok } + end + if @case_contact.update!(CaseContactParameters.new(params)) respond_to do |format| format.html { if step == steps.last @@ -132,10 +144,6 @@ def create_additional_case_contacts(case_contact) end end - def case_contact_params - CaseContactParameters.new(params) - end - # Deletes the current associations (from the join table) only if the submitted form body has the parameters for # the contact_type ids. def remove_unwanted_contact_types From 15bbf325249ab8cb9eef85d339c890f616e40964 Mon Sep 17 00:00:00 2001 From: compwron Date: Sun, 5 May 2024 15:21:30 -0400 Subject: [PATCH 3/3] fix syntax --- .../case_contacts/form_controller.rb | 19 +++++++++++-------- spec/requests/case_contacts/form_spec.rb | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/case_contacts/form_controller.rb b/app/controllers/case_contacts/form_controller.rb index b309abdfbf..fb3f93563a 100644 --- a/app/controllers/case_contacts/form_controller.rb +++ b/app/controllers/case_contacts/form_controller.rb @@ -39,14 +39,17 @@ def update remove_nil_draft_ids end if params[:case_contact].empty? - format.html { - if step == steps.last - finish_editing - else - render_wizard @case_contact, {}, {case_contact_id: @case_contact.id} - end - } - format.json { head :ok } + respond_to do |format| + format.html { + if step == steps.last + finish_editing + else + render_wizard @case_contact, {}, { case_contact_id: @case_contact.id } + end + } + format.json { head :ok } + end + return end if @case_contact.update!(CaseContactParameters.new(params)) respond_to do |format| diff --git a/spec/requests/case_contacts/form_spec.rb b/spec/requests/case_contacts/form_spec.rb index 771775c99e..a11bdae262 100644 --- a/spec/requests/case_contacts/form_spec.rb +++ b/spec/requests/case_contacts/form_spec.rb @@ -332,7 +332,7 @@ } patch "/case_contacts/#{case_contact.id}/form/#{step}", params: params - expect(response.status).to eq("??") + expect(response.status).to eq(302) end end