Welcome to mirror list, hosted at ThFree Co, Russian Federation.

membership_actions_shared_examples.rb « concerns « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e0b0d5c0a38e8ab4276eff117290360bb08f52a (plain)
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
65
66
67
# frozen_string_literal: true

RSpec.shared_examples 'request_accessable' do
  context 'when not signed in' do
    it 'redirects to sign in page' do
      request

      expect(response).to redirect_to(new_user_session_path)
    end
  end

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

    it 'redirects back to group members page and displays the relevant notice' do
      request

      expect(response).to redirect_to(membershipable_path)
      expect(flash[:notice]).to eq(_('Your request for access has been queued for review.'))
    end

    context 'when something goes wrong' do
      before do
        group_member = build(:group_member)
        request_access_service = instance_double(Members::RequestAccessService)
        allow(Members::RequestAccessService).to receive(:new).and_return(request_access_service)
        allow(request_access_service).to receive(:execute).and_return(group_member)
        allow(group_member).to receive_message_chain(:errors, :full_messages, :to_sentence).and_return('Error')
      end

      it 'redirects back to group members page and displays the relevant notice' do
        request

        expect(response).to redirect_to(membershipable_path)
        expect(flash[:alert]).to eq(_('Your request for access could not be processed: Error'))
      end
    end

    context 'when already a member' do
      before do
        membershipable.add_developer(user)
      end

      it 'redirects back to group members page and displays the relevant notice' do
        request

        expect(response).to redirect_to(membershipable_path)
        expect(flash[:notice]).to eq(_('You already have access.'))
      end
    end

    context 'when a pending access request exists' do
      before do
        membershipable.request_access(user)
      end

      it 'redirects back to group members page and displays the relevant notice' do
        request

        expect(response).to redirect_to(membershipable_path)
        expect(flash[:notice]).to eq(_('You have already requested access.'))
      end
    end
  end
end