FIX: ensures visits reports are correcttly differencing mobile/all (#6905)

This commit is contained in:
Joffrey JAFFEUX 2019-01-18 17:24:18 +01:00 committed by GitHub
parent 7908a522a0
commit 95f9a369a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -234,7 +234,7 @@ class Report
basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id
add_counts report, UserVisit, 'visited_at' add_counts report, UserVisit, 'visited_at'
report.prev30Days = UserVisit.where(mobile: true).where("visited_at >= ? and visited_at < ?", report.start_date - 30.days, report.start_date).count report.prev30Days = UserVisit.where("visited_at >= ? and visited_at < ?", report.start_date - 30.days, report.start_date).count
end end
def self.report_mobile_visits(report) def self.report_mobile_visits(report)

View File

@ -114,14 +114,42 @@ describe Report do
freeze_time DateTime.parse('2000-01-01') freeze_time DateTime.parse('2000-01-01')
user.user_visits.create(visited_at: 1.hour.from_now) user.user_visits.create(visited_at: 1.hour.from_now)
user.user_visits.create(visited_at: 1.day.ago) user.user_visits.create(visited_at: 1.day.ago)
user.user_visits.create(visited_at: 2.days.ago) user.user_visits.create(visited_at: 2.days.ago, mobile: true)
user.user_visits.create(visited_at: 45.days.ago)
user.user_visits.create(visited_at: 46.days.ago, mobile: true)
expect(report.data).to be_present expect(report.data).to be_present
expect(report.data.count).to eq(3)
expect(report.data.select { |v| v[:x].today? }).to be_present expect(report.data.select { |v| v[:x].today? }).to be_present
expect(report.prev30Days).to eq(2)
end end
end end
end end
describe 'mobile visits report' do
let(:report) { Report.find('mobile_visits') }
include_examples 'no data'
context "with visits" do
let(:user) { Fabricate(:user) }
it "returns a report with data" do
freeze_time DateTime.parse('2000-01-01')
user.user_visits.create(visited_at: 1.hour.from_now)
user.user_visits.create(visited_at: 2.days.ago, mobile: true)
user.user_visits.create(visited_at: 45.days.ago)
user.user_visits.create(visited_at: 46.days.ago, mobile: true)
expect(report.data).to be_present
expect(report.data.count).to eq(1)
expect(report.data.select { |v| v[:x].today? }).not_to be_present
expect(report.prev30Days).to eq(1)
end
end
end
[:signup, :topic, :post, :flag, :like, :email].each do |arg| [:signup, :topic, :post, :flag, :like, :email].each do |arg|
describe "#{arg} report" do describe "#{arg} report" do
pluralized = arg.to_s.pluralize pluralized = arg.to_s.pluralize