2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-26 14:23:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Groups > Members > Leave group' do
|
2020-11-02 06:08:53 +00:00
|
|
|
include Spec::Support::Helpers::Features::MembersHelpers
|
|
|
|
|
2017-06-26 14:23:46 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:other_user) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2021-11-11 12:10:41 +00:00
|
|
|
stub_feature_flags(bootstrap_confirmation_modals: false)
|
2020-11-02 06:08:53 +00:00
|
|
|
sign_in(user)
|
2017-06-26 14:23:46 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'guest leaves the group' do
|
2017-06-26 14:23:46 +00: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 14:51:05 +00:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 14:23:46 +00:00
|
|
|
end
|
|
|
|
|
2019-04-29 11:22:25 +00:00
|
|
|
it 'guest leaves the group by url param', :js do
|
|
|
|
group.add_guest(user)
|
|
|
|
group.add_owner(other_user)
|
|
|
|
|
|
|
|
visit group_path(group, leave: 1)
|
|
|
|
|
|
|
|
page.accept_confirm
|
|
|
|
|
2020-06-15 12:08:44 +00:00
|
|
|
wait_for_all_requests
|
2019-04-29 11:22:25 +00:00
|
|
|
expect(current_path).to eq(dashboard_groups_path)
|
|
|
|
expect(group.users).not_to include(user)
|
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'guest leaves the group as last member' do
|
2017-06-26 14:23:46 +00: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 14:51:05 +00:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 14:23:46 +00:00
|
|
|
end
|
|
|
|
|
2019-04-29 11:22:25 +00:00
|
|
|
it 'owner leaves the group if they are not the last owner' do
|
2017-06-26 14:23:46 +00: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 14:51:05 +00:00
|
|
|
expect(group.users).not_to include(user)
|
2017-06-26 14:23:46 +00:00
|
|
|
end
|
|
|
|
|
2020-11-02 06:08:53 +00:00
|
|
|
it 'owner can not leave the group if they are the last owner', :js do
|
2017-06-26 14:23:46 +00:00
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
visit group_path(group)
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'Leave group'
|
|
|
|
|
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2020-11-02 06:08:53 +00:00
|
|
|
expect(members_table).not_to have_selector 'button[title="Leave"]'
|
2017-06-26 14:23:46 +00:00
|
|
|
end
|
|
|
|
|
2019-04-29 11:22:25 +00:00
|
|
|
it 'owner can not leave the group by url param if they are the last owner', :js do
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
visit group_path(group, leave: 1)
|
|
|
|
|
|
|
|
expect(find('.flash-alert')).to have_content 'You do not have permission to leave this group'
|
|
|
|
end
|
|
|
|
|
2017-06-26 14:23:46 +00:00
|
|
|
def left_group_message(group)
|
|
|
|
"You left the \"#{group.name}\""
|
|
|
|
end
|
|
|
|
end
|