Change lists to be able to include accounts with pending follow requests (#19727)
This commit is contained in:
		@@ -29,17 +29,48 @@ describe Api::V1::Lists::AccountsController do
 | 
			
		||||
    let(:scopes) { 'write:lists' }
 | 
			
		||||
    let(:bob) { Fabricate(:account, username: 'bob') }
 | 
			
		||||
 | 
			
		||||
    before do
 | 
			
		||||
      user.account.follow!(bob)
 | 
			
		||||
      post :create, params: { list_id: list.id, account_ids: [bob.id] }
 | 
			
		||||
    context 'when the added account is followed' do
 | 
			
		||||
      before do
 | 
			
		||||
        user.account.follow!(bob)
 | 
			
		||||
        post :create, params: { list_id: list.id, account_ids: [bob.id] }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'returns http success' do
 | 
			
		||||
        expect(response).to have_http_status(200)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'adds account to the list' do
 | 
			
		||||
        expect(list.accounts.include?(bob)).to be true
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'returns http success' do
 | 
			
		||||
      expect(response).to have_http_status(200)
 | 
			
		||||
    context 'when the added account has been sent a follow request' do
 | 
			
		||||
      before do
 | 
			
		||||
        user.account.follow_requests.create!(target_account: bob)
 | 
			
		||||
        post :create, params: { list_id: list.id, account_ids: [bob.id] }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'returns http success' do
 | 
			
		||||
        expect(response).to have_http_status(200)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'adds account to the list' do
 | 
			
		||||
        expect(list.accounts.include?(bob)).to be true
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'adds account to the list' do
 | 
			
		||||
      expect(list.accounts.include?(bob)).to be true
 | 
			
		||||
    context 'when the added account is not followed' do
 | 
			
		||||
      before do
 | 
			
		||||
        post :create, params: { list_id: list.id, account_ids: [bob.id] }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'returns http not found' do
 | 
			
		||||
        expect(response).to have_http_status(404)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'does not add the account to the list' do
 | 
			
		||||
        expect(list.accounts.include?(bob)).to be false
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -683,4 +683,28 @@ describe AccountInteractions do
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe '#lists_for_local_distribution' do
 | 
			
		||||
    let!(:inactive_follower_user) { Fabricate(:user, current_sign_in_at: 5.years.ago) }
 | 
			
		||||
    let!(:follower_user)          { Fabricate(:user, current_sign_in_at: Time.now.utc) }
 | 
			
		||||
    let!(:follow_request_user)    { Fabricate(:user, current_sign_in_at: Time.now.utc) }
 | 
			
		||||
 | 
			
		||||
    let!(:inactive_follower_list) { Fabricate(:list, account: inactive_follower_user.account) }
 | 
			
		||||
    let!(:follower_list)          { Fabricate(:list, account: follower_user.account) }
 | 
			
		||||
    let!(:follow_request_list)    { Fabricate(:list, account: follow_request_user.account) }
 | 
			
		||||
 | 
			
		||||
    before do
 | 
			
		||||
      inactive_follower_user.account.follow!(account)
 | 
			
		||||
      follower_user.account.follow!(account)
 | 
			
		||||
      follow_request_user.account.follow_requests.create!(target_account: account)
 | 
			
		||||
 | 
			
		||||
      inactive_follower_list.accounts << account
 | 
			
		||||
      follower_list.accounts << account
 | 
			
		||||
      follow_request_list.accounts << account
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'includes only the list from the active follower' do
 | 
			
		||||
      expect(account.lists_for_local_distribution.to_a).to eq [follower_list]
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -4,13 +4,27 @@ require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe FollowRequest, type: :model do
 | 
			
		||||
  describe '#authorize!' do
 | 
			
		||||
    let(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
 | 
			
		||||
    let(:account)        { Fabricate(:account) }
 | 
			
		||||
    let(:target_account) { Fabricate(:account) }
 | 
			
		||||
    let!(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
 | 
			
		||||
    let(:account)         { Fabricate(:account) }
 | 
			
		||||
    let(:target_account)  { Fabricate(:account) }
 | 
			
		||||
 | 
			
		||||
    context 'when the to-be-followed person has been added to a list' do
 | 
			
		||||
      let!(:list) { Fabricate(:list, account: account) }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        list.accounts << target_account
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'updates the ListAccount' do
 | 
			
		||||
        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])
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
 | 
			
		||||
      expect(account).to        receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
 | 
			
		||||
      expect(MergeWorker).to    receive(:perform_async).with(target_account.id, account.id)
 | 
			
		||||
      expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true) do
 | 
			
		||||
        account.active_relationships.create!(target_account: target_account)
 | 
			
		||||
      end
 | 
			
		||||
      expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
 | 
			
		||||
      expect(follow_request).to receive(:destroy!)
 | 
			
		||||
      follow_request.authorize!
 | 
			
		||||
    end
 | 
			
		||||
@@ -29,4 +43,22 @@ RSpec.describe FollowRequest, type: :model do
 | 
			
		||||
      expect(follow_request.account.muting_reblogs?(target)).to be true
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe '#reject!' do
 | 
			
		||||
    let!(:follow_request) { Fabricate(:follow_request, account: account, target_account: target_account) }
 | 
			
		||||
    let(:account)         { Fabricate(:account) }
 | 
			
		||||
    let(:target_account)  { Fabricate(:account) }
 | 
			
		||||
 | 
			
		||||
    context 'when the to-be-followed person has been added to a list' do
 | 
			
		||||
      let!(:list) { Fabricate(:list, account: account) }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        list.accounts << target_account
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'deletes the ListAccount record' do
 | 
			
		||||
        expect { follow_request.reject! }.to change { list.accounts.count }.from(1).to(0)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user