Skip to content

Commit

Permalink
Merge pull request #6119 from thejonroberts/fix-contact-type-validation
Browse files Browse the repository at this point in the history
Fix #6117 handle duplicate contact types
  • Loading branch information
compwron authored Dec 9, 2024
2 parents b8dfab4 + 96cdad8 commit 6597e4f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_contact_types
.joins(:casa_case_contact_types)
.active
.where(casa_case_contact_types: {casa_case_id: @casa_cases.pluck(:id)})
.distinct

if case_contact_types.present?
case_contact_types
Expand All @@ -83,6 +84,7 @@ def get_contact_types
.active
.where(contact_type_group: {casa_org: current_organization})
.order("contact_type_group.name ASC", :name)
.distinct
end
end

Expand Down
1 change: 1 addition & 0 deletions app/values/case_contact_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def normalize_params(params)
params[:case_contact][:miles_driven] = convert_miles_driven(params)
end
params[:case_contact][:notes] = params.dig(:case_contact, :notes).presence
params[:case_contact][:contact_type_ids] = params[:case_contact][:contact_type_ids]&.uniq

params
end
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/case_contacts/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@
end
end

context "with duplicate contact type ids in params" do
let(:contact_type_ids) { [contact_types.first.id, contact_types.first.id] }

it "dedupes and updates the contact type ids" do
expect(case_contact.contact_type_ids).to be_empty
request
expect(response).to have_http_status(:redirect)

expect(case_contact.reload.contact_type_ids).to contain_exactly(contact_types.first.id)
end
end

context "when contact types were previously assigned" do
before { case_contact.update!(contact_type_ids: [contact_types.second.id]) }

Expand Down

0 comments on commit 6597e4f

Please sign in to comment.