You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe UnfollowFollowWorker do
  4. let(:local_follower) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  5. let(:source_account) { Fabricate(:account) }
  6. let(:target_account) { Fabricate(:account) }
  7. let(:show_reblogs) { true }
  8. subject { described_class.new }
  9. before do
  10. local_follower.follow!(source_account, reblogs: show_reblogs)
  11. end
  12. context 'when show_reblogs is true' do
  13. let(:show_reblogs) { true }
  14. describe 'perform' do
  15. it 'unfollows source account and follows target account' do
  16. subject.perform(local_follower.id, source_account.id, target_account.id)
  17. expect(local_follower.following?(source_account)).to be false
  18. expect(local_follower.following?(target_account)).to be true
  19. end
  20. it 'preserves show_reblogs' do
  21. subject.perform(local_follower.id, source_account.id, target_account.id)
  22. expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
  23. end
  24. end
  25. end
  26. context 'when show_reblogs is false' do
  27. let(:show_reblogs) { false }
  28. describe 'perform' do
  29. it 'unfollows source account and follows target account' do
  30. subject.perform(local_follower.id, source_account.id, target_account.id)
  31. expect(local_follower.following?(source_account)).to be false
  32. expect(local_follower.following?(target_account)).to be true
  33. end
  34. it 'preserves show_reblogs' do
  35. subject.perform(local_follower.id, source_account.id, target_account.id)
  36. expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
  37. end
  38. end
  39. end
  40. end