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 b8c69b2f0f..fb3f93563a 100644 --- a/app/controllers/case_contacts/form_controller.rb +++ b/app/controllers/case_contacts/form_controller.rb @@ -34,9 +34,24 @@ def update end end - remove_unwanted_contact_types - remove_nil_draft_ids - if @case_contact.update(case_contact_params) + if params[:case_contact] + remove_unwanted_contact_types + remove_nil_draft_ids + end + if params[:case_contact].empty? + 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| format.html { if step == steps.last @@ -132,10 +147,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 diff --git a/spec/requests/case_contacts/form_spec.rb b/spec/requests/case_contacts/form_spec.rb index afb89b961b..a11bdae262 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(302) + end + end + context "with valid attributes" do let(:attributes) do {