summaryrefslogtreecommitdiff
path: root/spec/controllers/groups
diff options
context:
space:
mode:
authorLinus G Thiel <linus@yesbabyyes.se>2016-10-05 21:58:34 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-24 13:14:00 +0300
commit036fac06d18e82f0d0696bd1b350548bb47125e8 (patch)
tree039a3699aaa03d00f68795586e4fece71bb937fe /spec/controllers/groups
parent9dbd5b3cfad10b214ae5ef27c39246bbb74a5077 (diff)
downloadgitlab-ce-036fac06d18e82f0d0696bd1b350548bb47125e8.tar.gz
Gracefully handle adding of no users to projects and groups
- Disable {project, group} members submit button if no users If no users are selected, the submit button should be disabled. - Alert user when no users were added to {project, group}. When no users were selected for adding, an alert message is flashed that no users were added. - Also, this commit adds a feedback when users were actually added to a project, in symmetry with how group members are handled. Closes #22967, #23270.
Diffstat (limited to 'spec/controllers/groups')
-rw-r--r--spec/controllers/groups/group_members_controller_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb
index ad15b3f8f40..82eebe6f2d4 100644
--- a/spec/controllers/groups/group_members_controller_spec.rb
+++ b/spec/controllers/groups/group_members_controller_spec.rb
@@ -13,6 +13,60 @@ describe Groups::GroupMembersController do
end
end
+ describe '#create' do
+ let(:group) { create(:group, :public) }
+
+ context 'when users are added' do
+ let(:user) { create(:user) }
+ let(:group_user) { create(:user) }
+ let(:member) do
+ group.add_developer(group_user)
+ group.members.find_by(user_id: group_user)
+ end
+
+ context 'when user does not have enough rights' do
+ before do
+ group.members.delete(member)
+ group.add_developer(user)
+ sign_in(user)
+ end
+
+ it 'returns 403' do
+ post :create, group_id: group,
+ user_ids: member
+
+ expect(response).to have_http_status(403)
+ expect(group.users).not_to include group_user
+ end
+ end
+
+ context 'when user has enough rights' do
+ before do
+ group.add_owner(user)
+ sign_in(user)
+ end
+
+ it 'adds user to members' do
+ post :create, group_id: group,
+ user_ids: member
+
+ expect(response).to set_flash.to 'Users were successfully added.'
+ expect(response).to redirect_to(group_group_members_path(group))
+ expect(group.users).to include group_user
+ end
+
+ it 'adds no user to members' do
+ post :create, group_id: group,
+ user_ids: ''
+
+ expect(response).to set_flash.to 'No users specified.'
+ expect(response).to redirect_to(group_group_members_path(group))
+ expect(group.users).not_to include group_user
+ end
+ end
+ end
+ end
+
describe 'DELETE destroy' do
let(:member) { create(:group_member, :developer, group: group) }