user_requests_access_spec.rb 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
require 'spec_helper'

feature 'Projects > Members > User requests access', feature: true do
  let(:user) { create(:user) }
  let(:master) { create(:user) }
  let(:project) { create(:project, :public) }

  background do
    project.team << [master, :master]
    login_as(user)
  end

  scenario 'user can request access to a project' do
    visit namespace_project_path(project.namespace, project)

    perform_enqueued_jobs do
      click_link 'Request Access'
    end

    expect(ActionMailer::Base.deliveries.last.to).to eq [master.notification_email]
    expect(ActionMailer::Base.deliveries.last.subject).to match /Request to join #{project.name_with_namespace} project/

    expect(project.access_requested?(user)).to be_truthy
    expect(page).to have_content 'Your request for access has been queued for review.'
    expect(page).to have_content 'Withdraw Request'
  end

  scenario 'user is not listed in the project members page' do
    visit namespace_project_path(project.namespace, project)

    click_link 'Request Access'

    expect(project.access_requested?(user)).to be_truthy

    click_link 'Members'

    visit namespace_project_project_members_path(project.namespace, project)
    page.within('.content') do
      expect(page).not_to have_content(user.name)
    end
  end

  scenario 'user can withdraw its request for access' do
    visit namespace_project_path(project.namespace, project)
    click_link 'Request Access'

    expect(project.access_requested?(user)).to be_truthy

    click_link 'Withdraw Request'

    expect(project.access_requested?(user)).to be_falsey
    expect(page).to have_content 'You withdrawn your access request to the project.'
  end
end