about summary refs log tree commit diff
path: root/spec/controllers/account_unfollow_controller_spec.rb
blob: a11f7aa6846b6cb77904c73b01e59dd97d0a2087 (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
59
60
61
62
63
64
require 'rails_helper'

describe AccountUnfollowController do
  render_views

  let(:user) { Fabricate(:user) }
  let(:alice) { Fabricate(:account, username: 'alice') }

  describe 'POST #create' do
    let(:service) { double }

    subject { post :create, params: { account_username: alice.username } }

    before do
      allow(UnfollowService).to receive(:new).and_return(service)
      allow(service).to receive(:call)
    end

    context 'when account is permanently suspended' do
      before do
        alice.suspend!
        alice.deletion_request.destroy
        subject
      end

      it 'returns http gone' do
        expect(response).to have_http_status(410)
      end
    end

    context 'when account is temporarily suspended' do
      before do
        alice.suspend!
        subject
      end

      it 'returns http forbidden' do
        expect(response).to have_http_status(403)
      end
    end

    context 'when signed out' do
      before do
        subject
      end

      it 'does not unfollow' do
        expect(UnfollowService).not_to receive(:new)
      end
    end

    context 'when signed in' do
      before do
        sign_in(user)
        subject
      end

      it 'redirects to account path' do
        expect(service).to have_received(:call).with(user.account, alice)
        expect(response).to redirect_to(account_path(alice))
      end
    end
  end
end