iachat/spec/models
Gabriel Jablonski 079d4b4996
fix(conversations): enforce NOT NULL on contact_id + cleanup orphans (#273)
* fix(conversations): enforce NOT NULL + FK on contact_id

Conversations had contact_id nullable with no FK to contacts. Combined
with dependent: :destroy_async on Contact#conversations, deleting a
contact could leave conversations pointing to a missing contact,
breaking the conversations#index API with
"undefined method 'additional_attributes' for nil" from the contact
partial.

Changes:
- Migration cleans up existing orphans, sets contact_id NOT NULL and
  adds a FK with ON DELETE CASCADE so the invariant is enforced at the
  DB level (complements the existing Rails presence validation).
- ContactMergeAction uses update_all for conversations/messages/notes/
  contact_inboxes so a failing callback cannot silently leave records
  pointing to the mergee contact before it is destroyed.
- Drop the now-redundant orphan filter in Conversations::ResolutionJob
  and its spec; the invariant is enforced at the schema level.

* fix: address review feedback

- Drop the ON DELETE CASCADE FK on conversations.contact_id. Several
  conversation-owned tables (messages, mentions, conversation_participants,
  reporting_events, csat_survey_responses, calls, applied_slas, sla_events,
  and polymorphic notifications) still have plain conversation_id references
  without FK cascades. The DB-level cascade would skip Conversation's
  dependent: cleanup and replace the NULL-contact bug with orphan children,
  and would also conflict with the existing non-cascade FKs on
  scheduled_messages/recurring_scheduled_messages. Keep the invariant at the
  Rails layer (NOT NULL + presence validation + dependent: :destroy_async).
- Clean up orphan conversations in the migration via Rails destroy so
  dependent associations are propagated correctly, instead of a raw
  DELETE FROM conversations that would orphan all child rows.
- Revert ContactMergeAction.merge_* methods back to per-record update! so
  Conversation#after_update_commit still fires (notify_status_change /
  CONVERSATION_CONTACT_CHANGED) for contact_id changes. The bang form
  still removes the silent-failure risk of the original .update call.
2026-04-22 13:57:40 -03:00
..
channel feat(whatsapp): convert inbox between WhatsApp providers (#268) 2026-04-18 20:57:27 -03:00
concerns Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
enterprise/audit feat: Add conversation delete feature (#11677) 2025-06-05 15:53:17 -05:00
integrations feat: new Captain Editor (#13235) 2026-01-21 13:39:07 +05:30
internal_chat feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
.keep Fix url in emails, add frontendURL helper (#19) 2019-08-25 19:59:28 +05:30
account_spec.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
account_user_spec.rb fix: update notification setting to clear selected email flags (#100) 2025-08-25 18:11:29 -03:00
agent_bot_inbox_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
agent_bot_spec.rb feat: Implement UI for Agent Bots in settings and remove CSML support (#11276) 2025-04-16 18:02:49 +05:30
application_record_external_credentials_encryption_spec.rb feat: Secure external credentials with database encryption (#12648) 2025-10-13 18:05:12 +05:30
article_spec.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
assignment_policy_spec.rb feat: Add assignment policies controllers with jbuilder views (#12199) 2025-08-18 19:15:21 -07:00
attachment_spec.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
automation_rule_spec.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
campaign_spec.rb chore: Add validations to campaign model 2025-03-19 17:29:08 -07:00
category_spec.rb chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
contact_inbox_spec.rb feat: group conversations (#228) 2026-03-19 21:56:58 -03:00
contact_spec.rb feat: group conversations (#228) 2026-03-19 21:56:58 -03:00
conversation_participants_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
conversation_spec.rb fix(conversations): enforce NOT NULL on contact_id + cleanup orphans (#273) 2026-04-22 13:57:40 -03:00
csat_survey_response_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
custom_attribute_definition_spec.rb feat: harden filter service 2026-03-09 21:19:20 +05:30
data_import_spec.rb chore: Add delay before running dataimport job (#8039) 2023-10-03 22:18:57 -07:00
folder_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
inbox_member_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
inbox_signature_spec.rb feat: add per-inbox signature management (#226) 2026-02-26 19:53:03 -03:00
inbox_spec.rb Merge branch 'main' into chatwoot/develop 2025-07-16 09:37:08 -03:00
installation_config_spec.rb fix: Annotaterb model annotation incomplete migration (#13132) 2026-03-25 17:51:06 -07:00
label_spec.rb chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
macro_spec.rb test: reset Current.user after spec (#8123) 2023-10-17 18:06:54 +05:30
mention_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
message_spec.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
note_spec.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
notification_setting_spec.rb Feature: Add new notification settings for user (#569) 2020-02-29 20:41:09 +05:30
notification_spec.rb feat: speed up circleci and github actions (#12849) 2025-11-19 15:32:48 +05:30
platform_app_permissible_spec.rb feat: Add Platform APIs (#1456) 2021-01-14 20:35:22 +05:30
platform_app_spec.rb chore: Limit objects returned by conversation API (#2721) 2021-07-31 21:19:42 +05:30
portal_spec.rb refactor: update webhook job parameters to include account webhook and delivery ID 2026-03-20 00:48:50 -03:00
related_category_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
reporting_event_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
reporting_events_rollup_spec.rb feat(rollup): add models and write path [1/3] (#13796) 2026-03-19 13:12:36 +05:30
scheduled_message_spec.rb fix: prevent deletion of scheduled messages that have been sent or failed (#212) 2026-02-05 18:42:46 -03:00
team_member_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
team_spec.rb feat: invalidate cache after inbox members or team members update (#10869) 2025-02-20 21:28:38 -08:00
user_spec.rb fix(mailer): fall back to user account for devise email locale (#267) 2026-04-17 21:58:08 -03:00
webhook_spec.rb feat: add per-webhook secret with backfill migration (#13573) 2026-02-26 17:26:12 +05:30
working_hour_spec.rb chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00