BigW Consortium Gitlab

user_requests_access_spec.rb 2.13 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

feature 'Groups > Members > User requests access', feature: true do
  let(:user) { create(:user) }
  let(:owner) { create(:user) }
6
  let(:group) { create(:group, :public, :access_requestable) }
7
  let!(:project) { create(:project, :private, namespace: group) }
8 9 10 11

  background do
    group.add_owner(owner)
    login_as(user)
Rémy Coutable committed
12
    visit group_path(group)
13 14 15 16 17 18 19
  end

  scenario 'request access feature is disabled' do
    group.update_attributes(request_access_enabled: false)
    visit group_path(group)

    expect(page).not_to have_content 'Request Access'
20 21 22
  end

  scenario 'user can request access to a group' do
23
    perform_enqueued_jobs { click_link 'Request Access' }
24 25

    expect(ActionMailer::Base.deliveries.last.to).to eq [owner.notification_email]
26
    expect(ActionMailer::Base.deliveries.last.subject).to match "Request to join the #{group.name} group"
27

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

    expect(page).to have_content 'Withdraw Access Request'
32
    expect(page).not_to have_content 'Leave Group'
33 34
  end

35 36 37 38 39 40 41 42 43 44 45 46 47 48
  scenario 'user does not see private projects' do
    perform_enqueued_jobs { click_link 'Request Access' }

    expect(page).not_to have_content project.name
  end

  scenario 'user does not see group in the Dashboard > Groups page' do
    perform_enqueued_jobs { click_link 'Request Access' }

    visit dashboard_groups_path

    expect(page).not_to have_content group.name
  end

49 50 51
  scenario 'user is not listed in the group members page' do
    click_link 'Request Access'

52
    expect(group.requesters.exists?(user_id: user)).to be_truthy
53 54 55 56 57 58 59 60 61 62 63

    click_link 'Members'

    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'

64
    expect(group.requesters.exists?(user_id: user)).to be_truthy
65

66
    click_link 'Withdraw Access Request'
67

68
    expect(group.requesters.exists?(user_id: user)).to be_falsey
69
    expect(page).to have_content 'Your access request to the group has been withdrawn.'
70 71
  end
end