File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
app/controllers/case_contacts
spec/requests/case_contacts Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ def case_contact_params
165165 # Deletes the current associations (from the join table) only if the submitted form body has the parameters for
166166 # the contact_type ids.
167167 def remove_unwanted_contact_types
168- @case_contact . contact_types . clear if params . dig ( :case_contact , :contact_type_ids )
168+ @case_contact . case_contact_contact_types . destroy_all if params . dig ( :case_contact , :contact_type_ids )
169169 end
170170
171171 def remove_nil_draft_ids
Original file line number Diff line number Diff line change 234234 case_contact . reload
235235 expect ( case_contact . contact_type_ids ) . to contain_exactly ( contact_types . first . id )
236236 end
237+
238+ it "allows re-assigning the same contact type without uniqueness validation error" do
239+ # This test prevents regression of Bugsnag error:
240+ # "Validation failed: Case contact has already been taken"
241+ case_contact . update! ( contact_type_ids : [ contact_types . first . id ] )
242+ expect ( case_contact . contact_type_ids ) . to contain_exactly ( contact_types . first . id )
243+
244+ # Re-submit form with same contact type (simulates user editing and saving)
245+ request
246+
247+ case_contact . reload
248+ expect ( case_contact . contact_type_ids ) . to contain_exactly ( contact_types . first . id )
249+ end
237250 end
238251
239252 context "when contact topic answers in params" do
You can’t perform that action at this time.
0 commit comments