follow_request_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FollowRequest do
  4. describe '#authorize!' do
  5. let!(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
  6. let(:account) { Fabricate(:account) }
  7. let(:target_account) { Fabricate(:account) }
  8. context 'when the to-be-followed person has been added to a list' do
  9. let!(:list) { Fabricate(:list, account: account) }
  10. before do
  11. list.accounts << target_account
  12. end
  13. it 'updates the ListAccount' do
  14. expect { follow_request.authorize! }.to change { [list.list_accounts.first.follow_request_id, list.list_accounts.first.follow_id] }.from([follow_request.id, nil]).to([nil, anything])
  15. end
  16. end
  17. it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
  18. allow(account).to receive(:follow!) do
  19. account.active_relationships.create!(target_account: target_account)
  20. end
  21. allow(MergeWorker).to receive(:perform_async)
  22. allow(follow_request).to receive(:destroy!)
  23. follow_request.authorize!
  24. expect(account).to have_received(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
  25. expect(MergeWorker).to have_received(:perform_async).with(target_account.id, account.id)
  26. expect(follow_request).to have_received(:destroy!)
  27. end
  28. it 'correctly passes show_reblogs when true' do
  29. follow_request = Fabricate.create(:follow_request, show_reblogs: true)
  30. follow_request.authorize!
  31. target = follow_request.target_account
  32. expect(follow_request.account.muting_reblogs?(target)).to be false
  33. end
  34. it 'correctly passes show_reblogs when false' do
  35. follow_request = Fabricate.create(:follow_request, show_reblogs: false)
  36. follow_request.authorize!
  37. target = follow_request.target_account
  38. expect(follow_request.account.muting_reblogs?(target)).to be true
  39. end
  40. end
  41. describe '#reject!' do
  42. let!(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
  43. let(:account) { Fabricate(:account) }
  44. let(:target_account) { Fabricate(:account) }
  45. context 'when the to-be-followed person has been added to a list' do
  46. let!(:list) { Fabricate(:list, account: account) }
  47. before do
  48. list.accounts << target_account
  49. end
  50. it 'deletes the ListAccount record' do
  51. expect { follow_request.reject! }.to change { list.accounts.count }.from(1).to(0)
  52. end
  53. end
  54. end
  55. end