FIX: user directory didn't update stats of users with no recent activity

This commit is contained in:
Neil Lalonde
2017-08-09 15:57:35 -04:00
parent 53e6ccf17b
commit ca1609c821
2 changed files with 31 additions and 4 deletions

View File

@ -23,14 +23,39 @@ describe DirectoryItem do
UserActionCreator.enable
end
let!(:post) { create_post }
it "creates the record for the user" do
post = create_post
DirectoryItem.refresh!
expect(DirectoryItem.where(period_type: DirectoryItem.period_types[:all])
.where(user_id: post.user.id)
.where(topic_count: 1).count).to eq(1)
end
it "handles users with no activity" do
post = nil
freeze_time(2.years.ago) do
post = create_post
# Create records for that activity
DirectoryItem.refresh!
end
DirectoryItem.refresh!
[:yearly, :monthly, :weekly, :daily, :quarterly].each do |period|
directory_item = DirectoryItem
.where(period_type: DirectoryItem.period_types[period])
.where(user_id: post.user.id)
.first
expect(directory_item.topic_count).to eq(0)
expect(directory_item.post_count).to eq(0)
end
directory_item = DirectoryItem
.where(period_type: DirectoryItem.period_types[:all])
.where(user_id: post.user.id)
.first
expect(directory_item.topic_count).to eq(1)
end
end
end