Commit 3608f928 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve create project member test at project_members_controller_spec

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 52707acf
...@@ -13,58 +13,49 @@ describe Projects::ProjectMembersController do ...@@ -13,58 +13,49 @@ describe Projects::ProjectMembersController do
end end
end end
describe '#create' do describe 'POST create' do
let(:project) { create(:project, :public) }
context 'when users are added' do context 'when users are added' do
let(:user) { create(:user) } let(:project_user) { create(:user) }
let(:team_user) { create(:user) }
let(:member) do before { sign_in(user) }
project.team << [team_user, :developer]
project.members.find_by(user_id: team_user.id)
end
context 'when user does not have enough rights' do context 'when user does not have enough rights' do
before do before { project.team << [user, :developer] }
project.members.delete(member)
project.team << [user, :developer]
sign_in(user)
end
it 'returns 404' do it 'returns 404' do
post :create, namespace_id: project.namespace, post :create, namespace_id: project.namespace,
project_id: project, project_id: project,
user_ids: member user_ids: project_user.id,
access_level: Gitlab::Access::GUEST
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(project.users).not_to include team_user expect(project.users).not_to include project_user
end end
end end
context 'when user has enough rights' do context 'when user has enough rights' do
before do before { project.team << [user, :master] }
project.team << [user, :master]
sign_in(user)
end
it 'adds user to members' do it 'adds user to members' do
post :create, namespace_id: project.namespace, post :create, namespace_id: project.namespace,
project_id: project, project_id: project,
user_ids: member user_ids: project_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(namespace_project_project_members_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_project_members_path(project.namespace, project))
expect(project.users).to include team_user expect(project.users).to include project_user
end end
it 'adds no user to members' do it 'adds no user to members' do
post :create, namespace_id: project.namespace, post :create, namespace_id: project.namespace,
project_id: project, project_id: project,
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 or groups specified.'
expect(response).to redirect_to(namespace_project_project_members_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_project_members_path(project.namespace, project))
expect(project.users).not_to include team_user expect(project.users).not_to include project_user
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