Merge pull request #297 from namespaceMarcello/check-paging-without-counting

Check for a second page of messages without counting the room
This commit is contained in:
Stanko Krtalić
2026-10-05 16:45:50 +02:00
committed by GitHub
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ module Message::Pagination
end
def paged?
count > PAGE_SIZE
offset(PAGE_SIZE).exists?
end
end
end
+12
View File
@@ -65,6 +65,18 @@ class MessageTest < ActiveSupport::TestCase
assert_equal room.messages.ordered.first(Message::Pagination::PAGE_SIZE).map(&:id), room.messages.first_page.map(&:id)
end
test "paged? tells whether a room has more than a page of messages without counting them all" do
room = Rooms::Closed.create!(name: "Paging", creator: users(:david))
Message.insert_all Array.new(Message::Pagination::PAGE_SIZE) { |i| { room_id: room.id, creator_id: users(:david).id, client_message_id: "paging-#{i}" } }
assert_no_queries_match(/COUNT/i) do
assert_not room.messages.paged?
Message.insert_all [ { room_id: room.id, creator_id: users(:david).id, client_message_id: "paging-next" } ]
assert room.messages.paged?
end
end
test "search reads quotes and operator words in the query as text" do
message = rooms(:designers).messages.create!(body: "Say hi, NOT bye", client_message_id: "quoted", creator: users(:david))