FIX: corrects typo and adds a spec for likes report (#6439)

* FIX: corrects typo and adds a spec for likes report

* save!
This commit is contained in:
Joffrey JAFFEUX 2018-10-02 11:27:43 +02:00 committed by Guo Xiang Tan
parent 3b1e13e4ab
commit a515ba8612
2 changed files with 37 additions and 1 deletions

View File

@ -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

View File

@ -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