Skip to content

Commit 96cdad8

Browse files
committed
Fix #6117 handle duplicate contact types
1 parent d3bb74e commit 96cdad8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

app/controllers/case_contacts/form_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def get_contact_types
7373
.joins(:casa_case_contact_types)
7474
.active
7575
.where(casa_case_contact_types: {casa_case_id: @casa_cases.pluck(:id)})
76+
.distinct
7677

7778
if case_contact_types.present?
7879
case_contact_types
@@ -83,6 +84,7 @@ def get_contact_types
8384
.active
8485
.where(contact_type_group: {casa_org: current_organization})
8586
.order("contact_type_group.name ASC", :name)
87+
.distinct
8688
end
8789
end
8890

app/values/case_contact_parameters.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def normalize_params(params)
3636
params[:case_contact][:miles_driven] = convert_miles_driven(params)
3737
end
3838
params[:case_contact][:notes] = params.dig(:case_contact, :notes).presence
39+
params[:case_contact][:contact_type_ids] = params[:case_contact][:contact_type_ids]&.uniq
3940

4041
params
4142
end

spec/requests/case_contacts/form_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@
212212
end
213213
end
214214

215+
context "with duplicate contact type ids in params" do
216+
let(:contact_type_ids) { [contact_types.first.id, contact_types.first.id] }
217+
218+
it "dedupes and updates the contact type ids" do
219+
expect(case_contact.contact_type_ids).to be_empty
220+
request
221+
expect(response).to have_http_status(:redirect)
222+
223+
expect(case_contact.reload.contact_type_ids).to contain_exactly(contact_types.first.id)
224+
end
225+
end
226+
215227
context "when contact types were previously assigned" do
216228
before { case_contact.update!(contact_type_ids: [contact_types.second.id]) }
217229

0 commit comments

Comments
 (0)