2017-06-26 10:23:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Groups > Members > Leave group' do
|
2017-06-26 10:23:46 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:other_user) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2017-06-26 10:23:46 -04:00
|
|
|
gitlab_sign_in(user)
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'guest leaves the group' do
|
2017-06-26 10:23:46 -04:00
|
|
|
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)
|
2017-06-26 10:51:05 -04:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 10:23:46 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'guest leaves the group as last member' do
|
2017-06-26 10:23:46 -04:00
|
|
|
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)
|
2017-06-26 10:51:05 -04:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 10:23:46 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'owner leaves the group if they is not the last owner' do
|
2017-06-26 10:23:46 -04:00
|
|
|
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)
|
2017-06-26 10:51:05 -04:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 10:23:46 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'owner can not leave the group if they is a last owner' do
|
2017-06-26 10:23:46 -04:00
|
|
|
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
|