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

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

diff --git a/app/models/report.rb b/app/models/report.rb
index 82f23ca..fa11051 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 3001a64..5bc013e 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

GitHub sha: 95f9a369