2013-03-20 12:54:32 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Report do
|
|
|
|
|
2013-04-03 12:25:52 -05:00
|
|
|
describe 'visits report' do
|
|
|
|
let(:report) { Report.find('visits') }
|
|
|
|
|
|
|
|
context "no visits" do
|
|
|
|
it "returns an empty report" do
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(report.data).to be_blank
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with visits" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
2014-12-30 08:06:15 -06:00
|
|
|
before(:each) do
|
2014-12-29 06:29:09 -06:00
|
|
|
user.user_visits.create(visited_at: 1.hour.ago)
|
2013-04-03 12:25:52 -05:00
|
|
|
user.user_visits.create(visited_at: 1.day.ago)
|
|
|
|
user.user_visits.create(visited_at: 2.days.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a report with data" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data).to be_present
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
2014-12-29 06:29:09 -06:00
|
|
|
|
2014-12-30 08:06:15 -06:00
|
|
|
it "returns today's visit" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data.select { |v| v[:x].today? }).to be_present
|
2014-12-29 06:29:09 -06:00
|
|
|
end
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[:signup, :topic, :post, :flag, :like, :email].each do |arg|
|
|
|
|
describe "#{arg} report" do
|
|
|
|
pluralized = arg.to_s.pluralize
|
|
|
|
|
|
|
|
let(:report) { Report.find(pluralized) }
|
|
|
|
|
|
|
|
context "no #{pluralized}" do
|
|
|
|
it 'returns an empty report' do
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(report.data).to be_blank
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with #{pluralized}" do
|
2014-12-30 08:06:15 -06:00
|
|
|
before(:each) do
|
|
|
|
Timecop.freeze
|
2013-04-03 12:25:52 -05:00
|
|
|
fabricator = case arg
|
|
|
|
when :signup
|
|
|
|
:user
|
|
|
|
when :email
|
|
|
|
:email_log
|
|
|
|
else
|
|
|
|
arg
|
|
|
|
end
|
2014-12-30 08:06:15 -06:00
|
|
|
Fabricate(fabricator)
|
2013-04-03 12:25:52 -05:00
|
|
|
Fabricate(fabricator, created_at: 1.hours.ago)
|
|
|
|
Fabricate(fabricator, created_at: 1.hours.ago)
|
2014-12-30 08:06:15 -06:00
|
|
|
Fabricate(fabricator, created_at: 1.day.ago)
|
|
|
|
Fabricate(fabricator, created_at: 2.days.ago)
|
|
|
|
Fabricate(fabricator, created_at: 30.days.ago)
|
|
|
|
Fabricate(fabricator, created_at: 35.days.ago)
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
2014-12-30 08:06:15 -06:00
|
|
|
after(:each) { Timecop.return }
|
2013-04-03 12:25:52 -05:00
|
|
|
|
2014-12-30 08:06:15 -06:00
|
|
|
context 'returns a report with data'
|
|
|
|
it 'with 30 days data' do
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(report.data.count).to eq(4)
|
2014-12-30 08:06:15 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has correct data sorted as asc' do
|
2015-01-08 19:03:08 -06:00
|
|
|
skip("Something is off with this spec @neil, it fails at some times of the day")
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(report.data[0][:y]).to eq(1) # 30.days.ago
|
|
|
|
expect(report.data[1][:y]).to eq(1) # 2.days.ago
|
|
|
|
expect(report.data[2][:y]).to eq(1) # 1.day.ago
|
|
|
|
expect(report.data[3][:y]).to eq(3) # today
|
2014-12-30 08:06:15 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns today's data" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data.select { |v| v[:x].today? }).to be_present
|
2014-12-30 08:06:15 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns total data' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.total).to eq 7
|
2014-12-30 08:06:15 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns previous 30 day's data" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.prev30Days).to eq 1
|
2014-12-30 08:06:15 -06:00
|
|
|
end
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'private messages' do
|
2013-04-16 15:56:18 -05:00
|
|
|
let(:report) { Report.find('user_to_user_private_messages') }
|
2013-04-03 12:25:52 -05:00
|
|
|
|
2015-01-05 10:04:23 -06:00
|
|
|
it 'topic report).to not include private messages' do
|
2013-04-03 12:25:52 -05:00
|
|
|
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
|
|
|
Fabricate(:topic, created_at: 1.hour.ago)
|
|
|
|
report = Report.find('topics')
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(report.data[0][:y]).to eq(1)
|
|
|
|
expect(report.total).to eq(1)
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
|
2015-01-05 10:04:23 -06:00
|
|
|
it 'post report).to not include private messages' do
|
2013-04-03 12:25:52 -05:00
|
|
|
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
|
|
|
Fabricate(:post)
|
|
|
|
report = Report.find('posts')
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data[0][:y]).to eq 1
|
|
|
|
expect(report.total).to eq 1
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no private messages' do
|
|
|
|
it 'returns an empty report' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data).to be_blank
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'some public posts' do
|
|
|
|
it 'returns an empty report' do
|
|
|
|
Fabricate(:post); Fabricate(:post)
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data).to be_blank
|
|
|
|
expect(report.total).to eq 0
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'some private messages' do
|
|
|
|
before do
|
|
|
|
Fabricate(:private_message_post, created_at: 25.hours.ago)
|
|
|
|
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
|
|
|
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct data' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data[0][:y]).to eq 1
|
|
|
|
expect(report.data[1][:y]).to eq 2
|
|
|
|
expect(report.total).to eq 3
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and some public posts' do
|
|
|
|
before do
|
|
|
|
Fabricate(:post); Fabricate(:post)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct data' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data[0][:y]).to eq 1
|
|
|
|
expect(report.data[1][:y]).to eq 2
|
|
|
|
expect(report.total).to eq 3
|
2013-04-03 12:25:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-20 12:54:32 -05:00
|
|
|
|
|
|
|
describe 'users by trust level report' do
|
2013-04-03 12:25:52 -05:00
|
|
|
let(:report) { Report.find('users_by_trust_level') }
|
2013-03-20 12:54:32 -05:00
|
|
|
|
|
|
|
context "no users" do
|
|
|
|
it "returns an empty report" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data).to be_blank
|
2013-03-20 12:54:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with users at different trust levels" do
|
|
|
|
before do
|
2014-09-05 00:20:39 -05:00
|
|
|
3.times { Fabricate(:user, trust_level: TrustLevel[0]) }
|
|
|
|
2.times { Fabricate(:user, trust_level: TrustLevel[2]) }
|
|
|
|
Fabricate(:user, trust_level: TrustLevel[4])
|
2013-03-20 12:54:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a report with data" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(report.data).to be_present
|
|
|
|
expect(report.data.find {|d| d[:x] == TrustLevel[0]}[:y]).to eq 3
|
|
|
|
expect(report.data.find {|d| d[:x] == TrustLevel[2]}[:y]).to eq 2
|
|
|
|
expect(report.data.find {|d| d[:x] == TrustLevel[4]}[:y]).to eq 1
|
2013-03-20 12:54:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-04-03 21:29:54 -05:00
|
|
|
end
|
2015-01-05 10:04:23 -06:00
|
|
|
|