leave_group_spec.rb 1.55 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Groups > Members > Leave group' do
4 5 6 7
  let(:user) { create(:user) }
  let(:other_user) { create(:user) }
  let(:group) { create(:group) }

8
  before do
9 10 11
    gitlab_sign_in(user)
  end

12
  it 'guest leaves the group' do
13 14 15 16 17 18 19 20
    group.add_guest(user)
    group.add_owner(other_user)

    visit group_path(group)
    click_link 'Leave group'

    expect(current_path).to eq(dashboard_groups_path)
    expect(page).to have_content left_group_message(group)
21
    expect(group.users).not_to include(user)
22 23
  end

24
  it 'guest leaves the group as last member' do
25 26 27 28 29 30 31
    group.add_guest(user)

    visit group_path(group)
    click_link 'Leave group'

    expect(current_path).to eq(dashboard_groups_path)
    expect(page).to have_content left_group_message(group)
32
    expect(group.users).not_to include(user)
33 34
  end

35
  it 'owner leaves the group if they is not the last owner' do
36 37 38 39 40 41 42 43
    group.add_owner(user)
    group.add_owner(other_user)

    visit group_path(group)
    click_link 'Leave group'

    expect(current_path).to eq(dashboard_groups_path)
    expect(page).to have_content left_group_message(group)
44
    expect(group.users).not_to include(user)
45 46
  end

47
  it 'owner can not leave the group if they is a last owner' do
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    group.add_owner(user)

    visit group_path(group)

    expect(page).not_to have_content 'Leave group'

    visit group_group_members_path(group)

    expect(find(:css, '.project-members-page li', text: user.name)).not_to have_selector(:css, 'a.btn-remove')
  end

  def left_group_message(group)
    "You left the \"#{group.name}\""
  end
end