Add specs for inactive users report
This commit is contained in:
parent
741898a106
commit
41cd8c169c
|
@ -857,7 +857,7 @@ class User < ActiveRecord::Base
|
|||
FROM incoming_emails e
|
||||
WHERE e.user_id = u.id AND
|
||||
e.post_id IS NOT NULL AND
|
||||
e.created_at BETWEEN (d.generated_date - INTERVAL '89 days') :: DATE AND d.generated_date
|
||||
e.created_at :: DATE BETWEEN (d.generated_date - INTERVAL '89 days') :: DATE AND d.generated_date
|
||||
)
|
||||
GROUP BY date_trunc('day', d.generated_date) :: DATE
|
||||
ORDER BY date_trunc('day', d.generated_date) :: DATE
|
||||
|
|
|
@ -423,4 +423,55 @@ describe Report do
|
|||
expect(r.data[0][:y]).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "inactive users" do
|
||||
context "no activity" do
|
||||
it "returns an empty report" do
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "with different users/visits" do
|
||||
before do
|
||||
freeze_time
|
||||
|
||||
@arpit = Fabricate(:user, created_at: 200.days.ago)
|
||||
@sam = Fabricate(:user, created_at: 200.days.ago)
|
||||
@robin = Fabricate(:user, created_at: 200.days.ago)
|
||||
@michael = Fabricate(:user, created_at: 200.days.ago)
|
||||
@gerhard = Fabricate(:user, created_at: 200.days.ago)
|
||||
end
|
||||
|
||||
it "returns all users as inactive" do
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data.first[:y]).to eq(5)
|
||||
expect(report.data.last[:y]).to eq(5)
|
||||
end
|
||||
|
||||
it "correctly returns inactive users" do
|
||||
@arpit.user_visits.create(visited_at: 100.days.ago)
|
||||
@sam.user_visits.create(visited_at: 100.days.ago)
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data.first[:y]).to eq(3)
|
||||
expect(report.data.last[:y]).to eq(5)
|
||||
|
||||
@arpit.user_visits.create(visited_at: 80.days.ago)
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data.first[:y]).to eq(3)
|
||||
expect(report.data.last[:y]).to eq(4)
|
||||
|
||||
@sam.user_visits.create(visited_at: 55.days.ago)
|
||||
@robin.user_visits.create(visited_at: 50.days.ago)
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data.first[:y]).to eq(2)
|
||||
expect(report.data.last[:y]).to eq(2)
|
||||
|
||||
Fabricate(:incoming_email, user: @michael, created_at: 20.days.ago, post: Fabricate(:post, user: @michael))
|
||||
report = Report.find('inactive_users')
|
||||
expect(report.data.first[:y]).to eq(2)
|
||||
expect(report.data.last[:y]).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue