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
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
describe 'POST create' do
let(:group_user) { create(:user) }
context 'when user does not have enough rights' do
before do
group.members.delete(member)
group.add_developer(user)
sign_in(user)
end
before { sign_in(user) }
it 'returns 403' do
post :create, group_id: group,
user_ids: member
context 'when user does not have enough rights' do
before { group.add_developer(user) }
expect(response).to have_http_status(403)
expect(group.users).not_to include group_user
end
it 'returns 403' do
post :create, group_id: group,
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
context 'when user has enough rights' do
before do
group.add_owner(user)
sign_in(user)
end
context 'when user has enough rights' do
before { group.add_owner(user) }
it 'adds user to members' do
post :create, group_id: group,
user_ids: member
it 'adds user to members' do
post :create, group_id: group,
user_ids: group_user.id,
access_level: Gitlab::Access::GUEST
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
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: ''
it 'adds no user to members' do
post :create, group_id: group,
user_ids: '',
access_level: Gitlab::Access::GUEST
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
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
......
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