From 95f9a369a5c23771ad7fd8f3a6dd290052b3bea1 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 18 Jan 2019 17:24:18 +0100 Subject: [PATCH] FIX: ensures visits reports are correcttly differencing mobile/all (#6905) --- app/models/report.rb | 2 +- spec/models/report_spec.rb | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/models/report.rb b/app/models/report.rb index 82f23caec41..fa110517900 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -234,7 +234,7 @@ class Report basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id 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 def self.report_mobile_visits(report) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 3001a647bf9..5bc013e0af9 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -114,14 +114,42 @@ describe Report do freeze_time DateTime.parse('2000-01-01') 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: 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.count).to eq(3) expect(report.data.select { |v| v[:x].today? }).to be_present + expect(report.prev30Days).to eq(2) 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| describe "#{arg} report" do pluralized = arg.to_s.pluralize