BigW Consortium Gitlab

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

Phil Hughes committed
3
feature 'Projects > Members > User requests access', :js 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 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

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

    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'

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

63 64
    click_link 'Withdraw Access Request'

65
    expect(project.requesters.exists?(user_id: user)).to be_falsey
66 67
    expect(page).to have_content 'Your access request to the project has been withdrawn.'
  end
68

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

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