follow_recommendations_scheduler_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Scheduler::FollowRecommendationsScheduler do
  4. let!(:target_accounts) do
  5. Fabricate.times(3, :account) do
  6. statuses(count: 6)
  7. end
  8. end
  9. let!(:follower_accounts) do
  10. Fabricate.times(5, :account) do
  11. statuses(count: 6)
  12. end
  13. end
  14. describe '#perform' do
  15. subject(:scheduled_run) { described_class.new.perform }
  16. context 'when there are accounts to recommend' do
  17. before do
  18. # Follow the target accounts by follow accounts to make them recommendable
  19. follower_accounts.each do |follower_account|
  20. target_accounts.each do |target_account|
  21. Fabricate(:follow, account: follower_account, target_account: target_account)
  22. end
  23. end
  24. end
  25. it 'creates recommendations' do
  26. expect { scheduled_run }.to change(FollowRecommendation, :count).from(0).to(target_accounts.size)
  27. expect(redis.zrange('follow_recommendations:en', 0, -1)).to match_array(target_accounts.pluck(:id).map(&:to_s))
  28. end
  29. end
  30. context 'when there are no accounts to recommend' do
  31. it 'does not create follow recommendations' do
  32. expect { scheduled_run }.to_not change(FollowRecommendation, :count)
  33. expect(redis.zrange('follow_recommendations:en', 0, -1)).to be_empty
  34. end
  35. end
  36. end
  37. end