Files
once-campfire/test/controllers/rooms/directs_controller_test.rb
T
Marcello Costagliola 7b16014f01 Delete a room's messages in a job, one transaction each
Room#destroy destroyed every message inside the room's own
transaction, which holds SQLite's write lock until the last one: on a
room with many messages, every other write in the app waited and
failed. The request now takes the room away from its members and
leaves the rest to Room::DestroyJob, which destroys the messages one
at a time, each in its own short transaction, and then the room.

An open room is closed in the request, so that someone who joins the
account before the job ends isn't given it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bj8KnxpTf9sj2Ysa8aLAVa
2026-10-06 13:57:05 +02:00

65 lines
1.6 KiB
Ruby

require "test_helper"
class Rooms::DirectsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in :david
end
test "create" do
post rooms_directs_url, params: { user_ids: [ users(:jz).id ] }
room = Room.last
assert_redirected_to room_url(room)
assert room.users.include?(users(:david))
assert room.users.include?(users(:jz))
end
test "create only once per user set" do
assert_difference -> { Room.all.count }, +1 do
post rooms_directs_url, params: { user_ids: [ users(:jz).id ] }
post rooms_directs_url, params: { user_ids: [ users(:jz).id ] }
end
end
test "destroy only allowed for all room users" do
sign_in :kevin
assert_difference -> { Room.count }, -1 do
perform_enqueued_jobs do
delete rooms_direct_url(rooms(:david_and_kevin))
assert_redirected_to root_url
end
end
end
test "destroy can't reach a closed room the member didn't create" do
sign_in :kevin
assert_no_difference -> { Room.count } do
delete rooms_direct_url(rooms(:designers))
end
assert rooms(:designers).reload.persisted?
end
test "destroy can't reach an open room the member didn't create" do
sign_in :kevin
assert_no_difference -> { Room.count } do
delete rooms_direct_url(rooms(:hq))
end
assert rooms(:hq).reload.persisted?
end
test "destroy can't reach a room the member isn't in at all" do
sign_in :jz
assert_no_difference -> { Room.count } do
delete rooms_direct_url(rooms(:david_and_kevin))
end
assert rooms(:david_and_kevin).reload.persisted?
end
end