Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec #5658

Closed
wants to merge 3 commits into from
Closed

spec #5658

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ruby 3.2.2
yarn 1.22.19
nodejs 22.1.0
25 changes: 18 additions & 7 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/requests/case_contacts/form_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down Expand Up @@ -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
{
Expand Down
Loading