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

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

  background do
9
    sign_in(user)
10
    visit project_path(project)
11 12 13 14
  end

  scenario 'request access feature is disabled' do
    project.update_attributes(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 20
  end

  scenario '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 [master.notification_email]
24
    expect(ActionMailer::Base.deliveries.last.subject).to eq "Request to join the #{project.name_with_namespace} 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 34 35 36 37
  context 'code access is restricted' do
    scenario 'user can request access' do
      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 45 46
  scenario 'user is not listed in the project members page' do
    click_link 'Request Access'

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

49 50 51
    page.within('.layout-nav .nav-links') do
      click_link('Members')
    end
52

53
    visit project_project_members_path(project)
54 55 56 57 58 59 60 61
    page.within('.content') do
      expect(page).not_to have_content(user.name)
    end
  end

  scenario 'user can withdraw its request for access' do
    click_link 'Request Access'

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

64 65
    click_link 'Withdraw Access Request'

66
    expect(project.requesters.exists?(user_id: user)).to be_falsey
67 68
    expect(page).to have_content 'Your access request to the project has been withdrawn.'
  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