Skip to content

Commit

Permalink
Fix #6117 handle duplicate contact types
Browse files Browse the repository at this point in the history
  • Loading branch information
thejonroberts committed Dec 4, 2024
1 parent d3bb74e commit 96cdad8
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 96cdad8

Please sign in to comment.