fix: Delete agent bots without deleting the messages (#7754)

This commit is contained in:
Pranav Raj S
2023-08-17 13:48:49 -07:00
committed by GitHub
parent 178bc80b25
commit 29e8e41443
2 changed files with 13 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ class AgentBot < ApplicationRecord
has_many :agent_bot_inboxes, dependent: :destroy_async
has_many :inboxes, through: :agent_bot_inboxes
has_many :messages, as: :sender, dependent: :restrict_with_exception
has_many :messages, as: :sender, dependent: :nullify
belongs_to :account, optional: true
enum bot_type: { webhook: 0, csml: 1 }

View File

@@ -27,4 +27,16 @@ RSpec.describe AgentBot do
expect(agent_bot.errors[:outgoing_url]).to include("is too long (maximum is #{Limits::URL_LENGTH_LIMIT} characters)")
end
end
context 'when agent bot is deleted' do
let(:agent_bot) { create(:agent_bot) }
let(:message) { create(:message, sender: agent_bot) }
it 'nullifies the message sender key' do
expect(message.sender).to eq agent_bot
agent_bot.destroy!
expect(message.reload.sender).to be_nil
end
end
end