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,27 +13,18 @@ describe Groups::GroupMembersController do ...@@ -13,27 +13,18 @@ describe Groups::GroupMembersController do
end end
end end
describe '#create' do describe 'POST create' do
let(:group) { create(:group, :public) }
context 'when users are added' do
let(:user) { create(:user) }
let(:group_user) { create(:user) } let(:group_user) { create(:user) }
let(:member) do
group.add_developer(group_user) before { sign_in(user) }
group.members.find_by(user_id: group_user)
end
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before do before { group.add_developer(user) }
group.members.delete(member)
group.add_developer(user)
sign_in(user)
end
it 'returns 403' do it 'returns 403' 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 have_http_status(403) expect(response).to have_http_status(403)
expect(group.users).not_to include group_user expect(group.users).not_to include group_user
...@@ -41,14 +32,12 @@ describe Groups::GroupMembersController do ...@@ -41,14 +32,12 @@ describe Groups::GroupMembersController do
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))
...@@ -57,7 +46,8 @@ describe Groups::GroupMembersController do ...@@ -57,7 +46,8 @@ describe Groups::GroupMembersController do
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))
...@@ -65,7 +55,6 @@ describe Groups::GroupMembersController do ...@@ -65,7 +55,6 @@ describe Groups::GroupMembersController do
end end
end end
end end
end
describe 'DELETE destroy' do describe 'DELETE destroy' do
let(:member) { create(:group_member, :developer, group: group) } let(:member) { create(:group_member, :developer, group: group) }
......
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