follow_recommendations_scheduler_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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. end
  28. end
  29. context 'when there are no accounts to recommend' do
  30. it 'does not create follow recommendations' do
  31. expect { scheduled_run }.to_not change(FollowRecommendation, :count)
  32. end
  33. end
  34. end
  35. end