File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
controllers/case_contacts
spec/requests/case_contacts Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments