diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 67043291ca5..1f0fe2ddcce 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -143,7 +143,7 @@ class PostAction < ActiveRecord::Base result = unscoped.where(post_action_type_id: post_action_type) result = result.where('post_actions.created_at >= ?', opts[:start_date] || (opts[:since_days_ago] || 30).days.ago) result = result.where('post_actions.created_at <= ?', opts[:end_date]) if opts[:end_date] - result = result.joins(post: :topic).merge(Topic.in_category_and_categories(opts[:category_id])) if opts[:category_id] + result = result.joins(post: :topic).merge(Topic.in_category_and_subcategories(opts[:category_id])) if opts[:category_id] result.group('date(post_actions.created_at)') .order('date(post_actions.created_at)') .count diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index a432bb46321..57d2279789d 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -890,4 +890,40 @@ describe Report do end end end + + describe 'likes' do + let(:report) { Report.find('likes') } + + include_examples 'no data' + + context 'with data' do + include_examples 'with data x/y' + + before(:each) do + topic = Fabricate(:topic, category_id: 2) + post = Fabricate(:post, topic: topic) + PostAction.act(Fabricate(:user), post, PostActionType.types[:like]) + + topic = Fabricate(:topic, category_id: 4) + post = Fabricate(:post, topic: topic) + PostAction.act(Fabricate(:user), post, PostActionType.types[:like]) + PostAction.act(Fabricate(:user), post, PostActionType.types[:like]) + PostAction.act(Fabricate(:user), post, PostActionType.types[:like]).tap do |pa| + pa.created_at = 45.days.ago + end.save! + end + + context "with category filtering" do + let(:report) { Report.find('likes', category_id: 2) } + + include_examples 'category filtering' + + context "on subcategories" do + let(:report) { Report.find('likes', category_id: 3) } + + include_examples 'category filtering on subcategories' + end + end + end + end end