mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 07:40:08 +09:00
Query sidebar directs and shared rooms separately
Load visible direct memberships ordered by room recency and other rooms ordered by name, instead of hydrating every membership and splitting them in Ruby. Fixes #307. Co-authored-by: Thomas Klemm <github@tklemm.eu>
This commit is contained in:
@@ -27,4 +27,25 @@ class Users::SidebarsControllerTest < ActionDispatch::IntegrationTest
|
||||
get user_sidebar_url
|
||||
assert_select ".unread", count: users(:david).memberships.reject { |m| m.room.direct? || !m.unread? }.count
|
||||
end
|
||||
|
||||
test "directs are queried separately and ordered by room recency, not name" do
|
||||
older = rooms(:david_and_jason)
|
||||
newer = rooms(:david_and_kevin)
|
||||
older.update_column :updated_at, 2.days.ago
|
||||
newer.update_column :updated_at, 1.minute.ago
|
||||
|
||||
get user_sidebar_url
|
||||
|
||||
assert_operator @response.body.index(dom_id(newer, :list)), :<, @response.body.index(dom_id(older, :list))
|
||||
end
|
||||
|
||||
test "shared rooms stay ordered by name" do
|
||||
get user_sidebar_url
|
||||
|
||||
shared_ids = users(:david).rooms.without_directs.sort_by { |room| room.name.downcase }.map { |room| dom_id(room, :list) }
|
||||
positions = shared_ids.map { |id| @response.body.index(id) }
|
||||
|
||||
assert positions.all?
|
||||
assert_equal positions.sort, positions
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user