follow_request_spec.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true) do
  19. account.active_relationships.create!(target_account: target_account)
  20. end
  21. expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
  22. expect(follow_request).to receive(:destroy!)
  23. follow_request.authorize!
  24. end
  25. it 'correctly passes show_reblogs when true' do
  26. follow_request = Fabricate.create(:follow_request, show_reblogs: true)
  27. follow_request.authorize!
  28. target = follow_request.target_account
  29. expect(follow_request.account.muting_reblogs?(target)).to be false
  30. end
  31. it 'correctly passes show_reblogs when false' do
  32. follow_request = Fabricate.create(:follow_request, show_reblogs: false)
  33. follow_request.authorize!
  34. target = follow_request.target_account
  35. expect(follow_request.account.muting_reblogs?(target)).to be true
  36. end
  37. end
  38. describe '#reject!' do
  39. let!(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
  40. let(:account) { Fabricate(:account) }
  41. let(:target_account) { Fabricate(:account) }
  42. context 'when the to-be-followed person has been added to a list' do
  43. let!(:list) { Fabricate(:list, account: account) }
  44. before do
  45. list.accounts << target_account
  46. end
  47. it 'deletes the ListAccount record' do
  48. expect { follow_request.reject! }.to change { list.accounts.count }.from(1).to(0)
  49. end
  50. end
  51. end
  52. end