master_manages_access_requests_shared_example.rb 1.45 KB
Newer Older
1
RSpec.shared_examples 'Maintainer manages access requests' do
2
  let(:user) { create(:user) }
3
  let(:maintainer) { create(:user) }
4
5
6

  before do
    entity.request_access(user)
7
8
    entity.respond_to?(:add_owner) ? entity.add_owner(maintainer) : entity.add_maintainer(maintainer)
    sign_in(maintainer)
9
10
  end

11
  it 'maintainer can see access requests' do
12
13
14
15
16
    visit members_page_path

    expect_visible_access_request(entity, user)
  end

17
  it 'maintainer can grant access', :js do
18
19
20
21
22
23
24
25
26
27
28
29
30
    visit members_page_path

    expect_visible_access_request(entity, user)

    accept_confirm { click_on 'Grant access' }

    expect_no_visible_access_request(entity, user)

    page.within('.members-list') do
      expect(page).to have_content user.name
    end
  end

31
  it 'maintainer can deny access', :js do
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    visit members_page_path

    expect_visible_access_request(entity, user)

    accept_confirm { click_on 'Deny access' }

    expect_no_visible_access_request(entity, user)
    expect(page).not_to have_content user.name
  end

  def expect_visible_access_request(entity, user)
    expect(entity.requesters.exists?(user_id: user)).to be_truthy
    expect(page).to have_content "Users requesting access to #{entity.name} 1"
    expect(page).to have_content user.name
  end

  def expect_no_visible_access_request(entity, user)
    expect(entity.requesters.exists?(user_id: user)).to be_falsy
    expect(page).not_to have_content "Users requesting access to #{entity.name}"
  end
end