diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/requests/concerns/membership_actions_shared_examples.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/requests/concerns/membership_actions_shared_examples.rb')
-rw-r--r-- | spec/requests/concerns/membership_actions_shared_examples.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/requests/concerns/membership_actions_shared_examples.rb b/spec/requests/concerns/membership_actions_shared_examples.rb new file mode 100644 index 00000000000..6e0b0d5c0a3 --- /dev/null +++ b/spec/requests/concerns/membership_actions_shared_examples.rb @@ -0,0 +1,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 |