about summary refs log tree commit diff
path: root/spec/presenters/familiar_followers_presenter_spec.rb
blob: 17be4b9715068686d9caf04196042aa8229f653d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe FamiliarFollowersPresenter do
  describe '#accounts' do
    let(:account) { Fabricate(:account) }
    let(:familiar_follower) { Fabricate(:account) }
    let(:requested_accounts) { Fabricate.times(2, :account) }

    subject { described_class.new(requested_accounts, account.id) }

    before do
      familiar_follower.follow!(requested_accounts.first)
      account.follow!(familiar_follower)
    end

    it 'returns a result for each requested account' do
      expect(subject.accounts.map(&:id)).to eq requested_accounts.map(&:id)
    end

    it 'returns followers you follow' do
      result = subject.accounts.first

      expect(result).to_not be_nil
      expect(result.id).to eq requested_accounts.first.id
      expect(result.accounts).to match_array([familiar_follower])
    end

    context 'when requested account hides followers' do
      before do
        requested_accounts.first.update(hide_collections: true)
      end

      it 'does not return followers you follow' do
        result = subject.accounts.first

        expect(result).to_not be_nil
        expect(result.id).to eq requested_accounts.first.id
        expect(result.accounts).to be_empty
      end
    end

    context 'when familiar follower hides follows' do
      before do
        familiar_follower.update(hide_collections: true)
      end

      it 'does not return followers you follow' do
        result = subject.accounts.first

        expect(result).to_not be_nil
        expect(result.id).to eq requested_accounts.first.id
        expect(result.accounts).to be_empty
      end
    end
  end
end