mirror of
https://github.com/we-promise/sure.git
synced 2026-09-07 23:54:25 +00:00
fix(messages): handle chat not found during message creation (#2896)
* fix(messages): handle chat not found during message creation * test(messages): cover missing chat race --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: sure-admin <sure-admin@splashblot.com>
This commit is contained in:
co-authored by
sure-admin
parent
705878807b
commit
521946b9d6
@@ -15,6 +15,8 @@ class MessagesController < ApplicationController
|
||||
else
|
||||
redirect_to chat_path(@chat), alert: @message.errors.full_messages.to_sentence
|
||||
end
|
||||
rescue ActiveRecord::InvalidForeignKey
|
||||
redirect_to chats_path, alert: t(".chat_not_found")
|
||||
end
|
||||
|
||||
# Called by the chat watchdog when an assistant "Thinking…" bubble has waited
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
---
|
||||
en:
|
||||
messages:
|
||||
create:
|
||||
chat_not_found: This chat is no longer available.
|
||||
chat_form:
|
||||
placeholder: "Ask anything ..."
|
||||
disclaimer: "AI responses are informational only. Not financial advice!"
|
||||
|
||||
@@ -12,6 +12,15 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to chat_path(@chat, thinking: true)
|
||||
end
|
||||
|
||||
test "redirects to chats when message save races with chat deletion" do
|
||||
UserMessage.any_instance.stubs(:save).raises(ActiveRecord::InvalidForeignKey)
|
||||
|
||||
post chat_messages_url(@chat), params: { message: { content: "Hello", ai_model: "gpt-4.1" } }
|
||||
|
||||
assert_redirected_to chats_path
|
||||
assert_equal I18n.t("messages.create.chat_not_found"), flash[:alert]
|
||||
end
|
||||
|
||||
test "cannot create a message if AI is disabled" do
|
||||
@user.update!(ai_enabled: false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user