user_requests_access_spec.rb 2.4 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Projects > Members > User requests access', :js do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project, :public, :access_requestable, :repository) }
6
  let(:maintainer) { project.owner }
7

8
  before do
9
    sign_in(user)
10
    visit project_path(project)
11 12
  end

13
  it 'request access feature is disabled' do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
14
    project.update(request_access_enabled: false)
15
    visit project_path(project)
Rémy Coutable's avatar
Rémy Coutable committed
16

17
    expect(page).not_to have_content 'Request Access'
18 19
  end

20
  it 'user can request access to a project' do
21
    perform_enqueued_jobs { click_link 'Request Access' }
22

23
    expect(ActionMailer::Base.deliveries.last.to).to eq [maintainer.notification_email]
24
    expect(ActionMailer::Base.deliveries.last.subject).to eq "Request to join the #{project.full_name} project"
25

26
    expect(project.requesters.exists?(user_id: user)).to be_truthy
27
    expect(page).to have_content 'Your request for access has been queued for review.'
28 29

    expect(page).to have_content 'Withdraw Access Request'
30
    expect(page).not_to have_content 'Leave Project'
31 32
  end

33
  context 'code access is restricted' do
34
    it 'user can request access' do
35 36 37
      project.project_feature.update!(repository_access_level: ProjectFeature::PRIVATE,
                                      builds_access_level: ProjectFeature::PRIVATE,
                                      merge_requests_access_level: ProjectFeature::PRIVATE)
38
      visit project_path(project)
39 40 41 42 43

      expect(page).to have_content 'Request Access'
    end
  end

44
  it 'user is not listed in the project members page' do
45 46
    click_link 'Request Access'

47
    expect(project.requesters.exists?(user_id: user)).to be_truthy
48

Phil Hughes's avatar
Phil Hughes committed
49
    page.within('.nav-sidebar') do
50 51
      click_link('Members')
    end
52 53 54 55 56 57

    page.within('.content') do
      expect(page).not_to have_content(user.name)
    end
  end

58
  it 'user can withdraw its request for access' do
59 60
    click_link 'Request Access'

61
    expect(project.requesters.exists?(user_id: user)).to be_truthy
62

63
    accept_confirm { click_link 'Withdraw Access Request' }
64 65

    expect(page).to have_content 'Your access request to the project has been withdrawn.'
66 67
    expect(page).not_to have_content 'Withdraw Access Request'
    expect(page).to have_content 'Request Access'
68
  end
69

70
  def open_project_settings_menu
71 72 73 74
    page.within('.layout-nav .nav-links') do
      click_link('Settings')
    end

75
    page.within('.sub-nav') do
76 77
      click_link('Members')
    end
78 79
  end
end