summaryrefslogtreecommitdiff
path: root/spec/requests/api/merge_requests_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
commit0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch)
tree7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/requests/api/merge_requests_spec.rb
parent72123183a20411a36d607d70b12d57c484394c8e (diff)
downloadgitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/requests/api/merge_requests_spec.rb')
-rw-r--r--spec/requests/api/merge_requests_spec.rb83
1 files changed, 29 insertions, 54 deletions
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index a7ede7f4150..695c0ed1749 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -2134,54 +2134,6 @@ RSpec.describe API::MergeRequests do
expect(response).to have_gitlab_http_status(:created)
end
end
-
- describe 'SSE counter' do
- let(:headers) { {} }
- let(:params) do
- {
- title: 'Test merge_request',
- source_branch: 'feature_conflict',
- target_branch: 'master',
- author_id: user.id,
- milestone_id: milestone.id,
- squash: true
- }
- end
-
- subject { post api("/projects/#{project.id}/merge_requests", user), params: params, headers: headers }
-
- it 'does not increase the SSE counter by default' do
- expect(Gitlab::UsageDataCounters::EditorUniqueCounter).not_to receive(:track_sse_edit_action)
-
- subject
-
- expect(response).to have_gitlab_http_status(:created)
- end
-
- context 'when referer is not the SSE' do
- let(:headers) { { 'HTTP_REFERER' => 'https://gitlab.com' } }
-
- it 'does not increase the SSE counter by default' do
- expect(Gitlab::UsageDataCounters::EditorUniqueCounter).not_to receive(:track_sse_edit_action)
-
- subject
-
- expect(response).to have_gitlab_http_status(:created)
- end
- end
-
- context 'when referer is the SSE' do
- let(:headers) { { 'HTTP_REFERER' => project_show_sse_url(project, 'master/README.md') } }
-
- it 'increases the SSE counter by default' do
- expect(Gitlab::UsageDataCounters::EditorUniqueCounter).to receive(:track_sse_edit_action).with(author: user)
-
- subject
-
- expect(response).to have_gitlab_http_status(:created)
- end
- end
- end
end
describe 'PUT /projects/:id/merge_requests/:merge_request_iid' do
@@ -2535,14 +2487,34 @@ RSpec.describe API::MergeRequests do
expect(response).to have_gitlab_http_status(:ok)
end
- it "returns 406 if branch can't be merged" do
- allow_any_instance_of(MergeRequest)
- .to receive(:can_be_merged?).and_return(false)
+ context 'when change_response_code_merge_status is enabled' do
+ it "returns 422 if branch can't be merged" do
+ allow_next_found_instance_of(MergeRequest) do |merge_request|
+ allow(merge_request).to receive(:can_be_merged?).and_return(false)
+ end
- put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user)
+ put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user)
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ expect(json_response['message']).to eq('Branch cannot be merged')
+ end
+ end
+
+ context 'when change_response_code_merge_status is disabled' do
+ before do
+ stub_feature_flags(change_response_code_merge_status: false)
+ end
- expect(response).to have_gitlab_http_status(:not_acceptable)
- expect(json_response['message']).to eq('Branch cannot be merged')
+ it "returns 406 if branch can't be merged" do
+ allow_next_found_instance_of(MergeRequest) do |merge_request|
+ allow(merge_request).to receive(:can_be_merged?).and_return(false)
+ end
+
+ put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user)
+
+ expect(response).to have_gitlab_http_status(:not_acceptable)
+ expect(json_response['message']).to eq('Branch cannot be merged')
+ end
end
it "returns 405 if merge_request is not open" do
@@ -2693,6 +2665,7 @@ RSpec.describe API::MergeRequests do
expect(response).to have_gitlab_http_status(:ok)
expect(source_repository.branch_exists?(source_branch)).to be false
+ expect(merge_request.reload.should_remove_source_branch?).to be true
end
end
@@ -2711,6 +2684,7 @@ RSpec.describe API::MergeRequests do
expect(response).to have_gitlab_http_status(:ok)
expect(source_repository.branch_exists?(source_branch)).to be false
+ expect(merge_request.reload.should_remove_source_branch?).to be nil
end
it 'does not remove the source branch' do
@@ -2721,6 +2695,7 @@ RSpec.describe API::MergeRequests do
expect(response).to have_gitlab_http_status(:ok)
expect(source_repository.branch_exists?(source_branch)).to be_truthy
+ expect(merge_request.reload.should_remove_source_branch?).to be false
end
end