mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:01:26 +08:00
FIX: Ensure the top 6 categories are shown in the user summary (#12691)
Previously it would pluck 6 categories which the user had posted in, **then** order them. To select the **top 6** categories, we need to perform the ordering in the SQL query before the LIMIT
This commit is contained in:
@ -58,4 +58,24 @@ describe UserSummary do
|
||||
users = UserSummary.new(user, Guardian.new).most_liked_users
|
||||
expect(users).to eq([])
|
||||
end
|
||||
|
||||
it "includes ordered top categories" do
|
||||
u = Fabricate(:user)
|
||||
|
||||
UserSummary::MAX_SUMMARY_RESULTS.times do
|
||||
c = Fabricate(:category)
|
||||
t = Fabricate(:topic, category: c, user: u)
|
||||
Fabricate(:post, user: u, topic: t)
|
||||
end
|
||||
|
||||
top_category = Fabricate(:category)
|
||||
t = Fabricate(:topic, category: top_category, user: u)
|
||||
Fabricate(:post, user: u, topic: t)
|
||||
Fabricate(:post, user: u, topic: t)
|
||||
|
||||
summary = UserSummary.new(u, Guardian.new)
|
||||
|
||||
expect(summary.top_categories.length).to eq(UserSummary::MAX_SUMMARY_RESULTS)
|
||||
expect(summary.top_categories.first[:id]).to eq(top_category.id)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user