FEATURE: allow filtering posts report by multiple categories (#23669)

This commit is contained in:
Arpit Jalan 2023-09-26 21:56:47 +05:30 committed by GitHub
parent 53a211b77e
commit 3669723a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -889,7 +889,7 @@ class Post < ActiveRecord::Base
if include_subcategories
result = result.where("topics.category_id IN (?)", Category.subcategory_ids(category_id))
else
result = result.where("topics.category_id = ?", category_id)
result = result.where("topics.category_id IN (?)", category_id)
end
end
if group_ids

View File

@ -2166,6 +2166,32 @@ RSpec.describe Post do
expect(Post.public_posts_count_per_day(10.days.ago, 5.days.ago)).to be_empty
end
it "returns the correct number of public posts per day with category filter" do
category = Fabricate(:category)
another_category = Fabricate(:category)
topic = Fabricate(:topic, category: category)
another_topic = Fabricate(:topic, category: another_category)
Fabricate(:post, topic: topic, created_at: 6.days.ago)
Fabricate(:post, topic: topic, created_at: 7.days.ago)
Fabricate(:post, topic: another_topic, created_at: 6.days.ago)
Fabricate(:post, topic: another_topic, created_at: 7.days.ago)
expect(Post.public_posts_count_per_day(10.days.ago, 5.days.ago, category.id)).to eq(
6.days.ago.to_date => 1,
7.days.ago.to_date => 1,
)
expect(
Post.public_posts_count_per_day(
10.days.ago,
5.days.ago,
[category.id, another_category.id],
),
).to eq(6.days.ago.to_date => 2, 7.days.ago.to_date => 2)
end
it "returns the correct number of public posts per day with group filter" do
user = Fabricate(:user)
group_user = Fabricate(:user)