diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-30 03:06:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-30 03:06:03 +0300 |
commit | 7ddd5846999029916b2b6d8560b5b0f02ec0f6ea (patch) | |
tree | 0b570f83b5aacc9d79de9f1fbff9b8f9dca67482 /spec | |
parent | 839c080dd0976f19c274eee1331c47985490cd41 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/autocomplete_controller_spec.rb | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index 6cdd61e7abd..56c27b4e5eb 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -365,35 +365,67 @@ describe AutocompleteController do expect(json_response[3]).to match('name' => 'thumbsdown') end end + end - context 'Get merge_request_target_branches' do - let(:user2) { create(:user) } - let!(:merge_request1) { create(:merge_request, source_project: project, target_branch: 'feature') } + context 'Get merge_request_target_branches' do + let!(:merge_request) { create(:merge_request, source_project: project, target_branch: 'feature') } - context 'unauthorized user' do - it 'returns empty json' do - get :merge_request_target_branches + context 'anonymous user' do + it 'returns empty json' do + get :merge_request_target_branches, params: { project_id: project.id } - expect(json_response).to be_empty - end + expect(response).to have_gitlab_http_status(200) + expect(json_response).to be_empty end + end - context 'sign in as user without any accesible merge requests' do - it 'returns empty json' do - sign_in(user2) - get :merge_request_target_branches + context 'user without any accessible merge requests' do + it 'returns empty json' do + sign_in(create(:user)) - expect(json_response).to be_empty - end + get :merge_request_target_branches, params: { project_id: project.id } + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to be_empty end + end - context 'sign in as user with a accesible merge request' do - it 'returns json' do - sign_in(user) - get :merge_request_target_branches + context 'user with an accessible merge request but no scope' do + it 'returns an error' do + sign_in(user) - expect(json_response).to contain_exactly({ 'title' => 'feature' }) - end + get :merge_request_target_branches + + expect(response).to have_gitlab_http_status(400) + expect(json_response).to eq({ 'error' => 'At least one of group_id or project_id must be specified' }) + end + end + + context 'user with an accessible merge request by project' do + it 'returns json' do + sign_in(user) + + get :merge_request_target_branches, params: { project_id: project.id } + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to contain_exactly({ 'title' => 'feature' }) + end + end + + context 'user with an accessible merge request by group' do + let(:group) { create(:group) } + let(:project) { create(:project, namespace: group) } + let(:user) { create(:user) } + + it 'returns json' do + group.add_owner(user) + + sign_in(user) + + get :merge_request_target_branches, params: { group_id: group.id } + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to contain_exactly({ 'title' => 'feature' }) end end end |