Commit 1eba14ae authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor create member tests from group_members_controller_spec

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c8227889
...@@ -13,56 +13,45 @@ describe Groups::GroupMembersController do ...@@ -13,56 +13,45 @@ describe Groups::GroupMembersController do
end end
end end
describe '#create' do describe 'POST create' do
let(:group) { create(:group, :public) } let(:group_user) { create(:user) }
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 { sign_in(user) }
before do
group.members.delete(member)
group.add_developer(user)
sign_in(user)
end
it 'returns 403' do context 'when user does not have enough rights' do
post :create, group_id: group, before { group.add_developer(user) }
user_ids: member
expect(response).to have_http_status(403) it 'returns 403' do
expect(group.users).not_to include group_user post :create, group_id: group,
end user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to have_http_status(403)
expect(group.users).not_to include group_user
end end
end
context 'when user has enough rights' do context 'when user has enough rights' do
before do before { group.add_owner(user) }
group.add_owner(user)
sign_in(user)
end
it 'adds user to members' do it 'adds user to members' do
post :create, group_id: group, post :create, group_id: group,
user_ids: member user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'Users were successfully added.' expect(response).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(group_group_members_path(group)) expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user expect(group.users).to include group_user
end end
it 'adds no user to members' do it 'adds no user to members' do
post :create, group_id: group, post :create, group_id: group,
user_ids: '' user_ids: '',
access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'No users specified.' expect(response).to set_flash.to 'No users specified.'
expect(response).to redirect_to(group_group_members_path(group)) expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).not_to include group_user expect(group.users).not_to include group_user
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment