mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-07 07:10:10 +09:00
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:
@@ -49,7 +49,7 @@ module Message::Pagination
|
||||
end
|
||||
|
||||
def paged?
|
||||
count > PAGE_SIZE
|
||||
offset(PAGE_SIZE).exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user