diff --git a/app/models/post.rb b/app/models/post.rb index b23464cd3..034812ad3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1036,7 +1036,6 @@ class Post < ApplicationRecord def with_flag_stats relation = left_outer_joins(:flags).group(:id).select("posts.*") relation.select("COUNT(post_flags.id) AS flag_count") - relation end def with_appeal_stats diff --git a/test/unit/post_query_builder_test.rb b/test/unit/post_query_builder_test.rb index 01a6afc87..775b38537 100644 --- a/test/unit/post_query_builder_test.rb +++ b/test/unit/post_query_builder_test.rb @@ -465,6 +465,23 @@ class PostQueryBuilderTest < ActiveSupport::TestCase assert_tag_match([posts[2]], "-note_count:1") end + should "return posts for the flag_count: metatag" do + posts = create_list(:post, 3) + create(:post_flag, post: posts[1], status: :succeeded) + create(:post_flag, post: posts[2], status: :rejected, created_at: 4.days.ago) + create(:post_flag, post: posts[2], status: :pending) + + assert_tag_match([posts[0]], "flag_count:0") + assert_tag_match([posts[1]], "flag_count:1") + assert_tag_match([posts[2]], "flag_count:2") + + assert_tag_match([posts[0]], "flags:0") + assert_tag_match([posts[1]], "flags:1") + assert_tag_match([posts[2]], "flags:2") + + assert_tag_match([posts[2], posts[0]], "-flags:1") + end + should "return posts for the commentaryupdater: metatag" do user1 = create(:user) user2 = create(:user)