2013-03-20 13:54:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Report do
|
|
|
|
|
2013-04-03 13:25:52 -04:00
|
|
|
describe 'visits report' do
|
|
|
|
let(:report) { Report.find('visits') }
|
|
|
|
|
|
|
|
context "no visits" do
|
|
|
|
it "returns an empty report" do
|
|
|
|
report.data.should be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with visits" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
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
|
|
|
|
report.data.should be_present
|
|
|
|
end
|
|
|
|
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
|
|
|
|
report.data.should be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with #{pluralized}" do
|
|
|
|
before do
|
|
|
|
fabricator = case arg
|
|
|
|
when :signup
|
|
|
|
:user
|
|
|
|
when :email
|
|
|
|
:email_log
|
|
|
|
else
|
|
|
|
arg
|
|
|
|
end
|
|
|
|
Fabricate(fabricator, created_at: 25.hours.ago)
|
|
|
|
Fabricate(fabricator, created_at: 1.hours.ago)
|
|
|
|
Fabricate(fabricator, created_at: 1.hours.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct data' do
|
|
|
|
report.data[0][:y].should == 1
|
|
|
|
report.data[1][:y].should == 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'private messages' do
|
2013-04-16 16:56:18 -04:00
|
|
|
let(:report) { Report.find('user_to_user_private_messages') }
|
2013-04-03 13:25:52 -04:00
|
|
|
|
|
|
|
it 'topic report should not include private messages' do
|
|
|
|
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
|
|
|
Fabricate(:topic, created_at: 1.hour.ago)
|
|
|
|
report = Report.find('topics')
|
|
|
|
report.data[0][:y].should == 1
|
2013-04-05 14:09:16 -04:00
|
|
|
report.total.should == 1
|
2013-04-03 13:25:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'post report should not include private messages' do
|
|
|
|
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
|
|
|
Fabricate(:post)
|
|
|
|
report = Report.find('posts')
|
|
|
|
report.data[0][:y].should == 1
|
2013-04-05 14:09:16 -04:00
|
|
|
report.total.should == 1
|
2013-04-03 13:25:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no private messages' do
|
|
|
|
it 'returns an empty report' do
|
|
|
|
report.data.should be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'some public posts' do
|
|
|
|
it 'returns an empty report' do
|
|
|
|
Fabricate(:post); Fabricate(:post)
|
|
|
|
report.data.should be_blank
|
2013-04-05 14:09:16 -04:00
|
|
|
report.total.should == 0
|
2013-04-03 13:25:52 -04: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
|
|
|
|
report.data[0][:y].should == 1
|
|
|
|
report.data[1][:y].should == 2
|
2013-04-05 14:09:16 -04:00
|
|
|
report.total.should == 3
|
2013-04-03 13:25:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and some public posts' do
|
|
|
|
before do
|
|
|
|
Fabricate(:post); Fabricate(:post)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct data' do
|
|
|
|
report.data[0][:y].should == 1
|
|
|
|
report.data[1][:y].should == 2
|
2013-04-05 14:09:16 -04:00
|
|
|
report.total.should == 3
|
2013-04-03 13:25:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-20 13:54:32 -04:00
|
|
|
|
|
|
|
describe 'users by trust level report' do
|
2013-04-03 13:25:52 -04:00
|
|
|
let(:report) { Report.find('users_by_trust_level') }
|
2013-03-20 13:54:32 -04:00
|
|
|
|
|
|
|
context "no users" do
|
|
|
|
it "returns an empty report" do
|
|
|
|
report.data.should be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with users at different trust levels" do
|
|
|
|
before do
|
2013-04-17 19:11:13 -04:00
|
|
|
3.times { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
2013-03-20 13:54:32 -04:00
|
|
|
2.times { Fabricate(:user, trust_level: TrustLevel.levels[:regular]) }
|
|
|
|
Fabricate(:user, trust_level: TrustLevel.levels[:elder])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a report with data" do
|
|
|
|
report.data.should be_present
|
2013-06-25 10:15:41 -04:00
|
|
|
report.data.find {|d| d[:x] == TrustLevel.levels[:newuser]}[:y].should == 3
|
2013-03-20 13:54:32 -04:00
|
|
|
report.data.find {|d| d[:x] == TrustLevel.levels[:regular]}[:y].should == 2
|
|
|
|
report.data.find {|d| d[:x] == TrustLevel.levels[:elder]}[:y].should == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-03 22:29:54 -04:00
|
|
|
end
|