Commit 4c123ee7 authored by Simon Knox's avatar Simon Knox

Merge branch '9-5-stable-patch-5-1' into '9-5-stable-patch-5'

Pick for 9.5: "Refactor how we fetch ref for merge requests"

See merge request !14213
parents 4a75aac0 eac5c565
...@@ -212,7 +212,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -212,7 +212,7 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def create_merge_request def create_merge_request
result = MergeRequests::CreateFromIssueService.new(project, current_user, issue_iid: issue.iid).execute result = ::MergeRequests::CreateFromIssueService.new(project, current_user, issue_iid: issue.iid).execute
if result[:status] == :success if result[:status] == :success
render json: MergeRequestCreateSerializer.new.represent(result[:merge_request]) render json: MergeRequestCreateSerializer.new.represent(result[:merge_request])
......
...@@ -443,7 +443,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -443,7 +443,8 @@ class MergeRequest < ActiveRecord::Base
end end
def reload_diff_if_branch_changed def reload_diff_if_branch_changed
if source_branch_changed? || target_branch_changed? if (source_branch_changed? || target_branch_changed?) &&
(source_branch_head && target_branch_head)
reload_diff reload_diff
end end
end end
...@@ -794,11 +795,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -794,11 +795,7 @@ class MergeRequest < ActiveRecord::Base
end end
def fetch_ref def fetch_ref
target_project.repository.fetch_ref( write_ref
source_project.repository.path_to_repo,
"refs/heads/#{source_branch}",
ref_path
)
update_column(:ref_fetched, true) update_column(:ref_fetched, true)
end end
......
...@@ -1061,13 +1061,16 @@ class Project < ActiveRecord::Base ...@@ -1061,13 +1061,16 @@ class Project < ActiveRecord::Base
end end
def change_head(branch) def change_head(branch)
repository.before_change_head if repository.branch_exists?(branch)
repository.rugged.references.create('HEAD', repository.before_change_head
"refs/heads/#{branch}", repository.write_ref('HEAD', "refs/heads/#{branch}")
force: true) repository.copy_gitattributes(branch)
repository.copy_gitattributes(branch) repository.after_change_head
repository.after_change_head reload_default_branch
reload_default_branch else
errors.add(:base, "Could not change HEAD: branch '#{branch}' does not exist")
false
end
end end
def forked_from?(project) def forked_from?(project)
......
...@@ -232,7 +232,7 @@ class Repository ...@@ -232,7 +232,7 @@ class Repository
# This will still fail if the file is corrupted (e.g. 0 bytes) # This will still fail if the file is corrupted (e.g. 0 bytes)
begin begin
rugged.references.create(keep_around_ref_name(sha), sha, force: true) write_ref(keep_around_ref_name(sha), sha)
rescue Rugged::ReferenceError => ex rescue Rugged::ReferenceError => ex
Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}" Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}"
rescue Rugged::OSError => ex rescue Rugged::OSError => ex
...@@ -245,6 +245,10 @@ class Repository ...@@ -245,6 +245,10 @@ class Repository
ref_exists?(keep_around_ref_name(sha)) ref_exists?(keep_around_ref_name(sha))
end end
def write_ref(ref_path, sha)
rugged.references.create(ref_path, sha, force: true)
end
def diverging_commit_counts(branch) def diverging_commit_counts(branch)
root_ref_hash = raw_repository.rev_parse_target(root_ref).oid root_ref_hash = raw_repository.rev_parse_target(root_ref).oid
cache.fetch(:"diverging_commit_counts_#{branch.name}") do cache.fetch(:"diverging_commit_counts_#{branch.name}") do
...@@ -1024,7 +1028,12 @@ class Repository ...@@ -1024,7 +1028,12 @@ class Repository
def fetch_ref(source_path, source_ref, target_ref) def fetch_ref(source_path, source_ref, target_ref)
args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref}) args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref})
run_git(args) message, status = run_git(args)
# Make sure ref was created, and raise Rugged::ReferenceError when not
raise Rugged::ReferenceError, message if status != 0
target_ref
end end
def create_ref(ref, ref_path) def create_ref(ref, ref_path)
......
...@@ -28,6 +28,8 @@ Gitlab::Seeder.quiet do ...@@ -28,6 +28,8 @@ Gitlab::Seeder.quiet do
project = Project.find_by_full_path('gitlab-org/gitlab-test') project = Project.find_by_full_path('gitlab-org/gitlab-test')
next if project.empty_repo? # We don't have repository on CI
params = { params = {
source_branch: 'feature', source_branch: 'feature',
target_branch: 'master', target_branch: 'master',
......
require('spec_helper') require('spec_helper')
describe Projects::IssuesController do describe Projects::IssuesController do
let(:project) { create(:project_empty_repo) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
...@@ -841,7 +841,7 @@ describe Projects::IssuesController do ...@@ -841,7 +841,7 @@ describe Projects::IssuesController do
describe 'POST #toggle_award_emoji' do describe 'POST #toggle_award_emoji' do
before do before do
sign_in(user) sign_in(user)
project.team << [user, :developer] project.add_developer(user)
end end
it "toggles the award emoji" do it "toggles the award emoji" do
...@@ -855,6 +855,8 @@ describe Projects::IssuesController do ...@@ -855,6 +855,8 @@ describe Projects::IssuesController do
end end
describe 'POST create_merge_request' do describe 'POST create_merge_request' do
let(:project) { create(:project, :repository) }
before do before do
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
......
...@@ -10,6 +10,10 @@ FactoryGirl.define do ...@@ -10,6 +10,10 @@ FactoryGirl.define do
after(:build) do |deployment, evaluator| after(:build) do |deployment, evaluator|
deployment.project ||= deployment.environment.project deployment.project ||= deployment.environment.project
unless deployment.project.repository_exists?
allow(deployment.project.repository).to receive(:fetch_ref)
end
end end
end end
end end
...@@ -68,6 +68,17 @@ FactoryGirl.define do ...@@ -68,6 +68,17 @@ FactoryGirl.define do
merge_user author merge_user author
end end
after(:build) do |merge_request|
target_project = merge_request.target_project
source_project = merge_request.source_project
# Fake `write_ref` if we don't have repository
# We have too many existing tests replying on this behaviour
unless [target_project, source_project].all?(&:repository_exists?)
allow(merge_request).to receive(:write_ref)
end
end
factory :merged_merge_request, traits: [:merged] factory :merged_merge_request, traits: [:merged]
factory :closed_merge_request, traits: [:closed] factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:opened] factory :reopened_merge_request, traits: [:opened]
......
require 'rails_helper' require 'rails_helper'
feature 'Merge Request filtering by Labels', js: true do feature 'Merge Request filtering by Labels', :js do
include FilteredSearchHelpers include FilteredSearchHelpers
include MergeRequestHelpers include MergeRequestHelpers
...@@ -12,9 +12,9 @@ feature 'Merge Request filtering by Labels', js: true do ...@@ -12,9 +12,9 @@ feature 'Merge Request filtering by Labels', js: true do
let!(:feature) { create(:label, project: project, title: 'feature') } let!(:feature) { create(:label, project: project, title: 'feature') }
let!(:enhancement) { create(:label, project: project, title: 'enhancement') } let!(:enhancement) { create(:label, project: project, title: 'enhancement') }
let!(:mr1) { create(:merge_request, title: "Bugfix1", source_project: project, target_project: project, source_branch: "bugfix1") } let!(:mr1) { create(:merge_request, title: "Bugfix1", source_project: project, target_project: project, source_branch: "fix") }
let!(:mr2) { create(:merge_request, title: "Bugfix2", source_project: project, target_project: project, source_branch: "bugfix2") } let!(:mr2) { create(:merge_request, title: "Bugfix2", source_project: project, target_project: project, source_branch: "wip") }
let!(:mr3) { create(:merge_request, title: "Feature1", source_project: project, target_project: project, source_branch: "feature1") } let!(:mr3) { create(:merge_request, title: "Feature1", source_project: project, target_project: project, source_branch: "improve/awesome") }
before do before do
mr1.labels << bug mr1.labels << bug
...@@ -25,7 +25,7 @@ feature 'Merge Request filtering by Labels', js: true do ...@@ -25,7 +25,7 @@ feature 'Merge Request filtering by Labels', js: true do
mr3.title = "Feature1" mr3.title = "Feature1"
mr3.labels << feature mr3.labels << feature
project.team << [user, :master] project.add_master(user)
sign_in(user) sign_in(user)
visit project_merge_requests_path(project) visit project_merge_requests_path(project)
......
...@@ -12,7 +12,7 @@ describe 'Filter merge requests' do ...@@ -12,7 +12,7 @@ describe 'Filter merge requests' do
let!(:wontfix) { create(:label, project: project, title: "Won't fix") } let!(:wontfix) { create(:label, project: project, title: "Won't fix") }
before do before do
project.team << [user, :master] project.add_master(user)
group.add_developer(user) group.add_developer(user)
sign_in(user) sign_in(user)
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
...@@ -170,7 +170,7 @@ describe 'Filter merge requests' do ...@@ -170,7 +170,7 @@ describe 'Filter merge requests' do
describe 'filter merge requests by text' do describe 'filter merge requests by text' do
before do before do
create(:merge_request, title: "Bug", source_project: project, target_project: project, source_branch: "bug") create(:merge_request, title: "Bug", source_project: project, target_project: project, source_branch: "wip")
bug_label = create(:label, project: project, title: 'bug') bug_label = create(:label, project: project, title: 'bug')
milestone = create(:milestone, title: "8", project: project) milestone = create(:milestone, title: "8", project: project)
...@@ -179,7 +179,7 @@ describe 'Filter merge requests' do ...@@ -179,7 +179,7 @@ describe 'Filter merge requests' do
title: "Bug 2", title: "Bug 2",
source_project: project, source_project: project,
target_project: project, target_project: project,
source_branch: "bug2", source_branch: "fix",
milestone: milestone, milestone: milestone,
author: user, author: user,
assignee: user) assignee: user)
...@@ -259,12 +259,12 @@ describe 'Filter merge requests' do ...@@ -259,12 +259,12 @@ describe 'Filter merge requests' do
end end
end end
describe 'filter merge requests and sort', js: true do describe 'filter merge requests and sort', :js do
before do before do
bug_label = create(:label, project: project, title: 'bug') bug_label = create(:label, project: project, title: 'bug')
mr1 = create(:merge_request, title: "Frontend", source_project: project, target_project: project, source_branch: "Frontend") mr1 = create(:merge_request, title: "Frontend", source_project: project, target_project: project, source_branch: "wip")
mr2 = create(:merge_request, title: "Bug 2", source_project: project, target_project: project, source_branch: "bug2") mr2 = create(:merge_request, title: "Bug 2", source_project: project, target_project: project, source_branch: "fix")
mr1.labels << bug_label mr1.labels << bug_label
mr2.labels << bug_label mr2.labels << bug_label
......
require 'rails_helper' require 'rails_helper'
feature 'Merge requests filter clear button', js: true do feature 'Merge requests filter clear button', :js do
include FilteredSearchHelpers include FilteredSearchHelpers
include MergeRequestHelpers include MergeRequestHelpers
include IssueHelpers include IssueHelpers
...@@ -9,8 +9,8 @@ feature 'Merge requests filter clear button', js: true do ...@@ -9,8 +9,8 @@ feature 'Merge requests filter clear button', js: true do
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:milestone) { create(:milestone, project: project) } let!(:milestone) { create(:milestone, project: project) }
let!(:bug) { create(:label, project: project, name: 'bug')} let!(:bug) { create(:label, project: project, name: 'bug')}
let!(:mr1) { create(:merge_request, title: "Feature", source_project: project, target_project: project, source_branch: "Feature", milestone: milestone, author: user, assignee: user) } let!(:mr1) { create(:merge_request, title: "Feature", source_project: project, target_project: project, source_branch: "improve/awesome", milestone: milestone, author: user, assignee: user) }
let!(:mr2) { create(:merge_request, title: "Bugfix1", source_project: project, target_project: project, source_branch: "Bugfix1") } let!(:mr2) { create(:merge_request, title: "Bugfix1", source_project: project, target_project: project, source_branch: "fix") }
let(:merge_request_css) { '.merge-request' } let(:merge_request_css) { '.merge-request' }
let(:clear_search_css) { '.filtered-search-box .clear-search' } let(:clear_search_css) { '.filtered-search-box .clear-search' }
......
...@@ -24,12 +24,10 @@ describe 'Projects > Merge requests > User lists merge requests' do ...@@ -24,12 +24,10 @@ describe 'Projects > Merge requests > User lists merge requests' do
milestone: create(:milestone, due_date: '2013-12-12'), milestone: create(:milestone, due_date: '2013-12-12'),
created_at: 2.minutes.ago, created_at: 2.minutes.ago,
updated_at: 2.minutes.ago) updated_at: 2.minutes.ago)
# lfs in itself is not a great choice for the title if one wants to match the whole body content later on
# just think about the scenario when faker generates 'Chester Runolfsson' as the user's name
create(:merge_request, create(:merge_request,
title: 'merge_lfs', title: 'merge-test',
source_project: project, source_project: project,
source_branch: 'merge_lfs', source_branch: 'merge-test',
created_at: 3.minutes.ago, created_at: 3.minutes.ago,
updated_at: 10.seconds.ago) updated_at: 10.seconds.ago)
end end
...@@ -38,7 +36,7 @@ describe 'Projects > Merge requests > User lists merge requests' do ...@@ -38,7 +36,7 @@ describe 'Projects > Merge requests > User lists merge requests' do
visit_merge_requests(project, assignee_id: IssuableFinder::NONE) visit_merge_requests(project, assignee_id: IssuableFinder::NONE)
expect(current_path).to eq(project_merge_requests_path(project)) expect(current_path).to eq(project_merge_requests_path(project))
expect(page).to have_content 'merge_lfs' expect(page).to have_content 'merge-test'
expect(page).not_to have_content 'fix' expect(page).not_to have_content 'fix'
expect(page).not_to have_content 'markdown' expect(page).not_to have_content 'markdown'
expect(count_merge_requests).to eq(1) expect(count_merge_requests).to eq(1)
...@@ -47,7 +45,7 @@ describe 'Projects > Merge requests > User lists merge requests' do ...@@ -47,7 +45,7 @@ describe 'Projects > Merge requests > User lists merge requests' do
it 'filters on a specific assignee' do it 'filters on a specific assignee' do
visit_merge_requests(project, assignee_id: user.id) visit_merge_requests(project, assignee_id: user.id)
expect(page).not_to have_content 'merge_lfs' expect(page).not_to have_content 'merge-test'
expect(page).to have_content 'fix' expect(page).to have_content 'fix'
expect(page).to have_content 'markdown' expect(page).to have_content 'markdown'
expect(count_merge_requests).to eq(2) expect(count_merge_requests).to eq(2)
...@@ -57,14 +55,14 @@ describe 'Projects > Merge requests > User lists merge requests' do ...@@ -57,14 +55,14 @@ describe 'Projects > Merge requests > User lists merge requests' do
visit_merge_requests(project, sort: sort_value_recently_created) visit_merge_requests(project, sort: sort_value_recently_created)
expect(first_merge_request).to include('fix') expect(first_merge_request).to include('fix')
expect(last_merge_request).to include('merge_lfs') expect(last_merge_request).to include('merge-test')
expect(count_merge_requests).to eq(3) expect(count_merge_requests).to eq(3)
end end
it 'sorts by oldest' do it 'sorts by oldest' do
visit_merge_requests(project, sort: sort_value_oldest_created) visit_merge_requests(project, sort: sort_value_oldest_created)
expect(first_merge_request).to include('merge_lfs') expect(first_merge_request).to include('merge-test')
expect(last_merge_request).to include('fix') expect(last_merge_request).to include('fix')
expect(count_merge_requests).to eq(3) expect(count_merge_requests).to eq(3)
end end
...@@ -72,7 +70,7 @@ describe 'Projects > Merge requests > User lists merge requests' do ...@@ -72,7 +70,7 @@ describe 'Projects > Merge requests > User lists merge requests' do
it 'sorts by last updated' do it 'sorts by last updated' do
visit_merge_requests(project, sort: sort_value_recently_updated) visit_merge_requests(project, sort: sort_value_recently_updated)
expect(first_merge_request).to include('merge_lfs') expect(first_merge_request).to include('merge-test')
expect(count_merge_requests).to eq(3) expect(count_merge_requests).to eq(3)
end end
......
...@@ -52,8 +52,8 @@ feature 'Task Lists' do ...@@ -52,8 +52,8 @@ feature 'Task Lists' do
before do before do
Warden.test_mode! Warden.test_mode!
project.team << [user, :master] project.add_master(user)
project.team << [user2, :guest] project.add_guest(user2)
login_as(user) login_as(user)
end end
......
...@@ -12,7 +12,7 @@ describe EnvironmentsFinder do ...@@ -12,7 +12,7 @@ describe EnvironmentsFinder do
context 'tagged deployment' do context 'tagged deployment' do
before do before do
create(:deployment, environment: environment, ref: '1.0', tag: true, sha: project.commit.id) create(:deployment, environment: environment, ref: 'v1.1.0', tag: true, sha: project.commit.id)
end end
it 'returns environment when with_tags is set' do it 'returns environment when with_tags is set' do
......
...@@ -995,6 +995,27 @@ describe Repository, models: true do ...@@ -995,6 +995,27 @@ describe Repository, models: true do
end end
end end
context 'when temporary ref failed to be created from other project' do
let(:target_project) { create(:project, :empty_repo) }
before do
expect(target_project.repository).to receive(:run_git)
end
it 'raises Rugged::ReferenceError' do
raise_reference_error = raise_error(Rugged::ReferenceError) do |err|
expect(err.cause).to be_nil
end
expect do
GitOperationService.new(user, target_project.repository)
.with_branch('feature',
start_project: project,
&:itself)
end.to raise_reference_error
end
end
context 'when the update adds more than one commit' do context 'when the update adds more than one commit' do
let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' } let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' }
......
...@@ -31,7 +31,7 @@ describe API::MergeRequests do ...@@ -31,7 +31,7 @@ describe API::MergeRequests do
it 'returns authentication error' do it 'returns authentication error' do
get api('/merge_requests') get api('/merge_requests')
expect(response).to have_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
end end
...@@ -43,7 +43,7 @@ describe API::MergeRequests do ...@@ -43,7 +43,7 @@ describe API::MergeRequests do
it 'returns an array of all merge requests' do it 'returns an array of all merge requests' do
get api('/merge_requests', user), scope: :all get api('/merge_requests', user), scope: :all
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |mr| mr['id'] }) expect(json_response.map { |mr| mr['id'] })
...@@ -56,7 +56,7 @@ describe API::MergeRequests do ...@@ -56,7 +56,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), scope: :all get api('/merge_requests', user), scope: :all
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |mr| mr['id'] }) expect(json_response.map { |mr| mr['id'] })
...@@ -68,7 +68,7 @@ describe API::MergeRequests do ...@@ -68,7 +68,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2) get api('/merge_requests', user2)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
...@@ -79,7 +79,7 @@ describe API::MergeRequests do ...@@ -79,7 +79,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), author_id: user2.id, scope: :all get api('/merge_requests', user), author_id: user2.id, scope: :all
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
...@@ -90,7 +90,7 @@ describe API::MergeRequests do ...@@ -90,7 +90,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), assignee_id: user2.id, scope: :all get api('/merge_requests', user), assignee_id: user2.id, scope: :all
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
...@@ -101,7 +101,7 @@ describe API::MergeRequests do ...@@ -101,7 +101,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), scope: 'assigned-to-me' get api('/merge_requests', user2), scope: 'assigned-to-me'
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
...@@ -112,7 +112,7 @@ describe API::MergeRequests do ...@@ -112,7 +112,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), scope: 'created-by-me' get api('/merge_requests', user2), scope: 'created-by-me'
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
...@@ -125,7 +125,7 @@ describe API::MergeRequests do ...@@ -125,7 +125,7 @@ describe API::MergeRequests do
it "returns authentication error" do it "returns authentication error" do
get api("/projects/#{project.id}/merge_requests") get api("/projects/#{project.id}/merge_requests")
expect(response).to have_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
end end
...@@ -145,7 +145,7 @@ describe API::MergeRequests do ...@@ -145,7 +145,7 @@ describe API::MergeRequests do
it "returns an array of all merge_requests" do it "returns an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests", user) get api("/projects/#{project.id}/merge_requests", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -166,7 +166,7 @@ describe API::MergeRequests do ...@@ -166,7 +166,7 @@ describe API::MergeRequests do
it "returns an array of all merge_requests using simple mode" do it "returns an array of all merge_requests using simple mode" do
get api("/projects/#{project.id}/merge_requests?view=simple", user) get api("/projects/#{project.id}/merge_requests?view=simple", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response.last.keys).to match_array(%w(id iid title web_url created_at description project_id state updated_at)) expect(json_response.last.keys).to match_array(%w(id iid title web_url created_at description project_id state updated_at))
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -182,7 +182,7 @@ describe API::MergeRequests do ...@@ -182,7 +182,7 @@ describe API::MergeRequests do
it "returns an array of all merge_requests" do it "returns an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests?state", user) get api("/projects/#{project.id}/merge_requests?state", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -192,7 +192,7 @@ describe API::MergeRequests do ...@@ -192,7 +192,7 @@ describe API::MergeRequests do
it "returns an array of open merge_requests" do it "returns an array of open merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=opened", user) get api("/projects/#{project.id}/merge_requests?state=opened", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -202,7 +202,7 @@ describe API::MergeRequests do ...@@ -202,7 +202,7 @@ describe API::MergeRequests do
it "returns an array of closed merge_requests" do it "returns an array of closed merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=closed", user) get api("/projects/#{project.id}/merge_requests?state=closed", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -212,7 +212,7 @@ describe API::MergeRequests do ...@@ -212,7 +212,7 @@ describe API::MergeRequests do
it "returns an array of merged merge_requests" do it "returns an array of merged merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=merged", user) get api("/projects/#{project.id}/merge_requests?state=merged", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -222,7 +222,7 @@ describe API::MergeRequests do ...@@ -222,7 +222,7 @@ describe API::MergeRequests do
it 'returns merge_request by "iids" array' do it 'returns merge_request by "iids" array' do
get api("/projects/#{project.id}/merge_requests", user), iids: [merge_request.iid, merge_request_closed.iid] get api("/projects/#{project.id}/merge_requests", user), iids: [merge_request.iid, merge_request_closed.iid]
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq merge_request_closed.title expect(json_response.first['title']).to eq merge_request_closed.title
...@@ -232,14 +232,14 @@ describe API::MergeRequests do ...@@ -232,14 +232,14 @@ describe API::MergeRequests do
it 'matches V4 response schema' do it 'matches V4 response schema' do
get api("/projects/#{project.id}/merge_requests", user) get api("/projects/#{project.id}/merge_requests", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/merge_requests') expect(response).to match_response_schema('public_api/v4/merge_requests')
end end
it 'returns an empty array if no issue matches milestone' do it 'returns an empty array if no issue matches milestone' do
get api("/projects/#{project.id}/merge_requests", user), milestone: '1.0.0' get api("/projects/#{project.id}/merge_requests", user), milestone: '1.0.0'
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -247,7 +247,7 @@ describe API::MergeRequests do ...@@ -247,7 +247,7 @@ describe API::MergeRequests do
it 'returns an empty array if milestone does not exist' do it 'returns an empty array if milestone does not exist' do
get api("/projects/#{project.id}/merge_requests", user), milestone: 'foo' get api("/projects/#{project.id}/merge_requests", user), milestone: 'foo'
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -262,7 +262,7 @@ describe API::MergeRequests do ...@@ -262,7 +262,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests matching state in milestone' do it 'returns an array of merge requests matching state in milestone' do
get api("/projects/#{project.id}/merge_requests", user), milestone: '0.9', state: 'closed' get api("/projects/#{project.id}/merge_requests", user), milestone: '0.9', state: 'closed'
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request_closed.id) expect(json_response.first['id']).to eq(merge_request_closed.id)
...@@ -271,7 +271,7 @@ describe API::MergeRequests do ...@@ -271,7 +271,7 @@ describe API::MergeRequests do
it 'returns an array of labeled merge requests' do it 'returns an array of labeled merge requests' do
get api("/projects/#{project.id}/merge_requests?labels=#{label.title}", user) get api("/projects/#{project.id}/merge_requests?labels=#{label.title}", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['labels']).to eq([label2.title, label.title])
...@@ -280,7 +280,7 @@ describe API::MergeRequests do ...@@ -280,7 +280,7 @@ describe API::MergeRequests do
it 'returns an array of labeled merge requests where all labels match' do it 'returns an array of labeled merge requests where all labels match' do
get api("/projects/#{project.id}/merge_requests?labels=#{label.title},foo,bar", user) get api("/projects/#{project.id}/merge_requests?labels=#{label.title},foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -288,7 +288,7 @@ describe API::MergeRequests do ...@@ -288,7 +288,7 @@ describe API::MergeRequests do
it 'returns an empty array if no merge request matches labels' do it 'returns an empty array if no merge request matches labels' do
get api("/projects/#{project.id}/merge_requests?labels=foo,bar", user) get api("/projects/#{project.id}/merge_requests?labels=foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -307,7 +307,7 @@ describe API::MergeRequests do ...@@ -307,7 +307,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests?labels=#{bug_label.title}&milestone=#{milestone1.title}&state=merged", user) get api("/projects/#{project.id}/merge_requests?labels=#{bug_label.title}&milestone=#{milestone1.title}&state=merged", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(mr2.id) expect(json_response.first['id']).to eq(mr2.id)
...@@ -322,7 +322,7 @@ describe API::MergeRequests do ...@@ -322,7 +322,7 @@ describe API::MergeRequests do
it "returns an array of merge_requests in ascending order" do it "returns an array of merge_requests in ascending order" do
get api("/projects/#{project.id}/merge_requests?sort=asc", user) get api("/projects/#{project.id}/merge_requests?sort=asc", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -333,7 +333,7 @@ describe API::MergeRequests do ...@@ -333,7 +333,7 @@ describe API::MergeRequests do
it "returns an array of merge_requests in descending order" do it "returns an array of merge_requests in descending order" do
get api("/projects/#{project.id}/merge_requests?sort=desc", user) get api("/projects/#{project.id}/merge_requests?sort=desc", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -344,7 +344,7 @@ describe API::MergeRequests do ...@@ -344,7 +344,7 @@ describe API::MergeRequests do
it "returns an array of merge_requests ordered by updated_at" do it "returns an array of merge_requests ordered by updated_at" do
get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user) get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -355,7 +355,7 @@ describe API::MergeRequests do ...@@ -355,7 +355,7 @@ describe API::MergeRequests do
it "returns an array of merge_requests ordered by created_at" do it "returns an array of merge_requests ordered by created_at" do
get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user) get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
...@@ -370,7 +370,7 @@ describe API::MergeRequests do ...@@ -370,7 +370,7 @@ describe API::MergeRequests do
it 'exposes known attributes' do it 'exposes known attributes' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['id']).to eq(merge_request.id) expect(json_response['id']).to eq(merge_request.id)
expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['iid']).to eq(merge_request.iid)
expect(json_response['project_id']).to eq(merge_request.project.id) expect(json_response['project_id']).to eq(merge_request.project.id)
...@@ -398,7 +398,7 @@ describe API::MergeRequests do ...@@ -398,7 +398,7 @@ describe API::MergeRequests do
it "returns merge_request" do it "returns merge_request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['title']).to eq(merge_request.title) expect(json_response['title']).to eq(merge_request.title)
expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['iid']).to eq(merge_request.iid)
expect(json_response['work_in_progress']).to eq(false) expect(json_response['work_in_progress']).to eq(false)
...@@ -409,13 +409,13 @@ describe API::MergeRequests do ...@@ -409,13 +409,13 @@ describe API::MergeRequests do
it "returns a 404 error if merge_request_iid not found" do it "returns a 404 error if merge_request_iid not found" do
get api("/projects/#{project.id}/merge_requests/999", user) get api("/projects/#{project.id}/merge_requests/999", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it "returns a 404 error if merge_request `id` is used instead of iid" do it "returns a 404 error if merge_request `id` is used instead of iid" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
context 'Work in Progress' do context 'Work in Progress' do
...@@ -423,7 +423,7 @@ describe API::MergeRequests do ...@@ -423,7 +423,7 @@ describe API::MergeRequests do
it "returns merge_request" do it "returns merge_request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.iid}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.iid}", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['work_in_progress']).to eq(true) expect(json_response['work_in_progress']).to eq(true)
end end
end end
...@@ -434,7 +434,7 @@ describe API::MergeRequests do ...@@ -434,7 +434,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user)
commit = merge_request.commits.first commit = merge_request.commits.first
expect(response.status).to eq 200 expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.commits.size) expect(json_response.size).to eq(merge_request.commits.size)
...@@ -444,13 +444,13 @@ describe API::MergeRequests do ...@@ -444,13 +444,13 @@ describe API::MergeRequests do
it 'returns a 404 when merge_request_iid not found' do it 'returns a 404 when merge_request_iid not found' do
get api("/projects/#{project.id}/merge_requests/999/commits", user) get api("/projects/#{project.id}/merge_requests/999/commits", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns a 404 when merge_request id is used instead of iid' do it 'returns a 404 when merge_request id is used instead of iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -458,19 +458,19 @@ describe API::MergeRequests do ...@@ -458,19 +458,19 @@ describe API::MergeRequests do
it 'returns the change information of the merge_request' do it 'returns the change information of the merge_request' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/changes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/changes", user)
expect(response.status).to eq 200 expect(response).to have_gitlab_http_status(200)
expect(json_response['changes'].size).to eq(merge_request.diffs.size) expect(json_response['changes'].size).to eq(merge_request.diffs.size)
end end
it 'returns a 404 when merge_request_iid not found' do it 'returns a 404 when merge_request_iid not found' do
get api("/projects/#{project.id}/merge_requests/999/changes", user) get api("/projects/#{project.id}/merge_requests/999/changes", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns a 404 when merge_request id is used instead of iid' do it 'returns a 404 when merge_request id is used instead of iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/changes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/changes", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -485,7 +485,7 @@ describe API::MergeRequests do ...@@ -485,7 +485,7 @@ describe API::MergeRequests do
labels: 'label, label2', labels: 'label, label2',
milestone_id: milestone.id milestone_id: milestone.id
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['labels']).to eq(%w(label label2)) expect(json_response['labels']).to eq(%w(label label2))
expect(json_response['milestone']['id']).to eq(milestone.id) expect(json_response['milestone']['id']).to eq(milestone.id)
...@@ -495,25 +495,25 @@ describe API::MergeRequests do ...@@ -495,25 +495,25 @@ describe API::MergeRequests do
it "returns 422 when source_branch equals target_branch" do it "returns 422 when source_branch equals target_branch" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", source_branch: "master", target_branch: "master", author: user title: "Test merge_request", source_branch: "master", target_branch: "master", author: user
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
it "returns 400 when source_branch is missing" do it "returns 400 when source_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", target_branch: "master", author: user title: "Test merge_request", target_branch: "master", author: user
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when target_branch is missing" do it "returns 400 when target_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", source_branch: "markdown", author: user title: "Test merge_request", source_branch: "markdown", author: user
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when title is missing" do it "returns 400 when title is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
target_branch: 'master', source_branch: 'markdown' target_branch: 'master', source_branch: 'markdown'
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it 'allows special label names' do it 'allows special label names' do
...@@ -523,7 +523,7 @@ describe API::MergeRequests do ...@@ -523,7 +523,7 @@ describe API::MergeRequests do
target_branch: 'master', target_branch: 'master',
author: user, author: user,
labels: 'label, label?, label&foo, ?, &' labels: 'label, label?, label&foo, ?, &'
expect(response.status).to eq(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['labels']).to include 'label' expect(json_response['labels']).to include 'label'
expect(json_response['labels']).to include 'label?' expect(json_response['labels']).to include 'label?'
expect(json_response['labels']).to include 'label&foo' expect(json_response['labels']).to include 'label&foo'
...@@ -549,7 +549,7 @@ describe API::MergeRequests do ...@@ -549,7 +549,7 @@ describe API::MergeRequests do
target_branch: 'master', target_branch: 'master',
author: user author: user
end.to change { MergeRequest.count }.by(0) end.to change { MergeRequest.count }.by(0)
expect(response).to have_http_status(409) expect(response).to have_gitlab_http_status(409)
end end
end end
...@@ -580,15 +580,17 @@ describe API::MergeRequests do ...@@ -580,15 +580,17 @@ describe API::MergeRequests do
let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) } let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) }
let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) } let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) }
before :each do |each| before do
fork_project.team << [user2, :reporter] fork_project.add_reporter(user2)
allow_any_instance_of(MergeRequest).to receive(:write_ref)
end end
it "returns merge_request" do it "returns merge_request" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['description']).to eq('Test description for Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request')
end end
...@@ -599,7 +601,7 @@ describe API::MergeRequests do ...@@ -599,7 +601,7 @@ describe API::MergeRequests do
expect(fork_project.forked_from_project).to eq(project) expect(fork_project.forked_from_project).to eq(project)
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
end end
...@@ -613,25 +615,25 @@ describe API::MergeRequests do ...@@ -613,25 +615,25 @@ describe API::MergeRequests do
author: user2, author: user2,
target_project_id: project.id target_project_id: project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
it "returns 400 when source_branch is missing" do it "returns 400 when source_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when target_branch is missing" do it "returns 400 when target_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when title is missing" do it "returns 400 when title is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
context 'when target_branch is specified' do context 'when target_branch is specified' do
...@@ -642,7 +644,7 @@ describe API::MergeRequests do ...@@ -642,7 +644,7 @@ describe API::MergeRequests do
source_branch: 'markdown', source_branch: 'markdown',
author: user, author: user,
target_project_id: fork_project.id target_project_id: fork_project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
it 'returns 422 if targeting a different fork' do it 'returns 422 if targeting a different fork' do
...@@ -652,14 +654,14 @@ describe API::MergeRequests do ...@@ -652,14 +654,14 @@ describe API::MergeRequests do
source_branch: 'markdown', source_branch: 'markdown',
author: user2, author: user2,
target_project_id: unrelated_project.id target_project_id: unrelated_project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
end end
it "returns 201 when target_branch is specified and for the same project" do it "returns 201 when target_branch is specified and for the same project" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
end end
end end
end end
...@@ -674,7 +676,7 @@ describe API::MergeRequests do ...@@ -674,7 +676,7 @@ describe API::MergeRequests do
it "denies the deletion of the merge request" do it "denies the deletion of the merge request" do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", developer) delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", developer)
expect(response).to have_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
end end
...@@ -682,19 +684,19 @@ describe API::MergeRequests do ...@@ -682,19 +684,19 @@ describe API::MergeRequests do
it "destroys the merge request owners can destroy" do it "destroys the merge request owners can destroy" do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user)
expect(response).to have_http_status(204) expect(response).to have_gitlab_http_status(204)
end end
it "returns 404 for an invalid merge request IID" do it "returns 404 for an invalid merge request IID" do
delete api("/projects/#{project.id}/merge_requests/12345", user) delete api("/projects/#{project.id}/merge_requests/12345", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it "returns 404 if the merge request id is used instead of iid" do it "returns 404 if the merge request id is used instead of iid" do
delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
end end
...@@ -705,7 +707,7 @@ describe API::MergeRequests do ...@@ -705,7 +707,7 @@ describe API::MergeRequests do
it "returns merge_request in case of success" do it "returns merge_request in case of success" do
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_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it "returns 406 if branch can't be merged" do it "returns 406 if branch can't be merged" do
...@@ -714,21 +716,21 @@ describe API::MergeRequests do ...@@ -714,21 +716,21 @@ describe API::MergeRequests do
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_http_status(406) expect(response).to have_gitlab_http_status(406)
expect(json_response['message']).to eq('Branch cannot be merged') expect(json_response['message']).to eq('Branch cannot be merged')
end end
it "returns 405 if merge_request is not open" do it "returns 405 if merge_request is not open" do
merge_request.close merge_request.close
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_http_status(405) expect(response).to have_gitlab_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
it "returns 405 if merge_request is a work in progress" do it "returns 405 if merge_request is a work in progress" do
merge_request.update_attribute(:title, "WIP: #{merge_request.title}") merge_request.update_attribute(:title, "WIP: #{merge_request.title}")
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_http_status(405) expect(response).to have_gitlab_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
...@@ -737,7 +739,7 @@ describe API::MergeRequests do ...@@ -737,7 +739,7 @@ describe API::MergeRequests do
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_http_status(405) expect(response).to have_gitlab_http_status(405)
expect(json_response['message']).to eq('405 Method Not Allowed') expect(json_response['message']).to eq('405 Method Not Allowed')
end end
...@@ -745,21 +747,21 @@ describe API::MergeRequests do ...@@ -745,21 +747,21 @@ describe API::MergeRequests do
user2 = create(:user) user2 = create(:user)
project.team << [user2, :reporter] project.team << [user2, :reporter]
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user2) put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user2)
expect(response).to have_http_status(401) expect(response).to have_gitlab_http_status(401)
expect(json_response['message']).to eq('401 Unauthorized') expect(json_response['message']).to eq('401 Unauthorized')
end end
it "returns 409 if the SHA parameter doesn't match" do it "returns 409 if the SHA parameter doesn't match" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), sha: merge_request.diff_head_sha.reverse put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), sha: merge_request.diff_head_sha.reverse
expect(response).to have_http_status(409) expect(response).to have_gitlab_http_status(409)
expect(json_response['message']).to start_with('SHA does not match HEAD of source branch') expect(json_response['message']).to start_with('SHA does not match HEAD of source branch')
end end
it "succeeds if the SHA parameter matches" do it "succeeds if the SHA parameter matches" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), sha: merge_request.diff_head_sha put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), sha: merge_request.diff_head_sha
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it "enables merge when pipeline succeeds if the pipeline is active" do it "enables merge when pipeline succeeds if the pipeline is active" do
...@@ -768,7 +770,7 @@ describe API::MergeRequests do ...@@ -768,7 +770,7 @@ describe API::MergeRequests do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), merge_when_pipeline_succeeds: true put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), merge_when_pipeline_succeeds: true
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['title']).to eq('Test') expect(json_response['title']).to eq('Test')
expect(json_response['merge_when_pipeline_succeeds']).to eq(true) expect(json_response['merge_when_pipeline_succeeds']).to eq(true)
end end
...@@ -780,7 +782,7 @@ describe API::MergeRequests do ...@@ -780,7 +782,7 @@ describe API::MergeRequests do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), merge_when_pipeline_succeeds: true put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), merge_when_pipeline_succeeds: true
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['title']).to eq('Test') expect(json_response['title']).to eq('Test')
expect(json_response['merge_when_pipeline_succeeds']).to eq(true) expect(json_response['merge_when_pipeline_succeeds']).to eq(true)
end end
...@@ -788,13 +790,13 @@ describe API::MergeRequests do ...@@ -788,13 +790,13 @@ describe API::MergeRequests do
it "returns 404 for an invalid merge request IID" do it "returns 404 for an invalid merge request IID" do
put api("/projects/#{project.id}/merge_requests/12345/merge", user) put api("/projects/#{project.id}/merge_requests/12345/merge", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it "returns 404 if the merge request id is used instead of iid" do it "returns 404 if the merge request id is used instead of iid" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -803,39 +805,39 @@ describe API::MergeRequests do ...@@ -803,39 +805,39 @@ describe API::MergeRequests do
it "returns merge_request" do it "returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: "close" put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: "close"
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['state']).to eq('closed') expect(json_response['state']).to eq('closed')
end end
end end
it "updates title and returns merge_request" do it "updates title and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), title: "New title" put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), title: "New title"
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['title']).to eq('New title') expect(json_response['title']).to eq('New title')
end end
it "updates description and returns merge_request" do it "updates description and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), description: "New description" put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), description: "New description"
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['description']).to eq('New description') expect(json_response['description']).to eq('New description')
end end
it "updates milestone_id and returns merge_request" do it "updates milestone_id and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), milestone_id: milestone.id put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), milestone_id: milestone.id
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['milestone']['id']).to eq(milestone.id) expect(json_response['milestone']['id']).to eq(milestone.id)
end end
it "returns merge_request with renamed target_branch" do it "returns merge_request with renamed target_branch" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), target_branch: "wiki" put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), target_branch: "wiki"
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['target_branch']).to eq('wiki') expect(json_response['target_branch']).to eq('wiki')
end end
it "returns merge_request that removes the source branch" do it "returns merge_request that removes the source branch" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), remove_source_branch: true put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), remove_source_branch: true
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['force_remove_source_branch']).to be_truthy expect(json_response['force_remove_source_branch']).to be_truthy
end end
...@@ -856,7 +858,7 @@ describe API::MergeRequests do ...@@ -856,7 +858,7 @@ describe API::MergeRequests do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: 'close', title: nil put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: 'close', title: nil
merge_request.reload merge_request.reload
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
expect(merge_request.state).to eq('opened') expect(merge_request.state).to eq('opened')
end end
...@@ -864,20 +866,20 @@ describe API::MergeRequests do ...@@ -864,20 +866,20 @@ describe API::MergeRequests do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: 'close', target_branch: nil put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), state_event: 'close', target_branch: nil
merge_request.reload merge_request.reload
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
expect(merge_request.state).to eq('opened') expect(merge_request.state).to eq('opened')
end end
it "returns 404 for an invalid merge request IID" do it "returns 404 for an invalid merge request IID" do
put api("/projects/#{project.id}/merge_requests/12345", user), state_event: "close" put api("/projects/#{project.id}/merge_requests/12345", user), state_event: "close"
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it "returns 404 if the merge request id is used instead of iid" do it "returns 404 if the merge request id is used instead of iid" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), state_event: "close" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), state_event: "close"
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -890,7 +892,7 @@ describe API::MergeRequests do ...@@ -890,7 +892,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{mr.iid}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{mr.iid}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
...@@ -900,7 +902,7 @@ describe API::MergeRequests do ...@@ -900,7 +902,7 @@ describe API::MergeRequests do
it 'returns an empty array when there are no issues to be closed' do it 'returns an empty array when there are no issues to be closed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
...@@ -916,7 +918,7 @@ describe API::MergeRequests do ...@@ -916,7 +918,7 @@ describe API::MergeRequests do
get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.iid}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
...@@ -936,19 +938,19 @@ describe API::MergeRequests do ...@@ -936,19 +938,19 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", guest) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", guest)
expect(response).to have_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
it "returns 404 for an invalid merge request IID" do it "returns 404 for an invalid merge request IID" do
get api("/projects/#{project.id}/merge_requests/12345/closes_issues", user) get api("/projects/#{project.id}/merge_requests/12345/closes_issues", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it "returns 404 if the merge request id is used instead of iid" do it "returns 404 if the merge request id is used instead of iid" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -956,26 +958,26 @@ describe API::MergeRequests do ...@@ -956,26 +958,26 @@ describe API::MergeRequests do
it 'subscribes to a merge request' do it 'subscribes to a merge request' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", admin) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", admin)
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['subscribed']).to eq(true) expect(json_response['subscribed']).to eq(true)
end end
it 'returns 304 if already subscribed' do it 'returns 304 if already subscribed' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", user)
expect(response).to have_http_status(304) expect(response).to have_gitlab_http_status(304)
end end
it 'returns 404 if the merge request is not found' do it 'returns 404 if the merge request is not found' do
post api("/projects/#{project.id}/merge_requests/123/subscribe", user) post api("/projects/#{project.id}/merge_requests/123/subscribe", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns 404 if the merge request id is used instead of iid' do it 'returns 404 if the merge request id is used instead of iid' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscribe", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscribe", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns 403 if user has no access to read code' do it 'returns 403 if user has no access to read code' do
...@@ -984,7 +986,7 @@ describe API::MergeRequests do ...@@ -984,7 +986,7 @@ describe API::MergeRequests do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", guest) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/subscribe", guest)
expect(response).to have_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
end end
...@@ -992,26 +994,26 @@ describe API::MergeRequests do ...@@ -992,26 +994,26 @@ describe API::MergeRequests do
it 'unsubscribes from a merge request' do it 'unsubscribes from a merge request' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", user)
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['subscribed']).to eq(false) expect(json_response['subscribed']).to eq(false)
end end
it 'returns 304 if not subscribed' do it 'returns 304 if not subscribed' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", admin) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", admin)
expect(response).to have_http_status(304) expect(response).to have_gitlab_http_status(304)
end end
it 'returns 404 if the merge request is not found' do it 'returns 404 if the merge request is not found' do
post api("/projects/#{project.id}/merge_requests/123/unsubscribe", user) post api("/projects/#{project.id}/merge_requests/123/unsubscribe", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns 404 if the merge request id is used instead of iid' do it 'returns 404 if the merge request id is used instead of iid' do
post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/unsubscribe", user) post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/unsubscribe", user)
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'returns 403 if user has no access to read code' do it 'returns 403 if user has no access to read code' do
...@@ -1020,7 +1022,7 @@ describe API::MergeRequests do ...@@ -1020,7 +1022,7 @@ describe API::MergeRequests do
post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", guest) post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/unsubscribe", guest)
expect(response).to have_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
end end
......
...@@ -315,15 +315,17 @@ describe API::MergeRequests do ...@@ -315,15 +315,17 @@ describe API::MergeRequests do
let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) } let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) }
let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) } let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) }
before :each do |each| before do
fork_project.team << [user2, :reporter] fork_project.add_reporter(user2)
allow_any_instance_of(MergeRequest).to receive(:write_ref)
end end
it "returns merge_request" do it "returns merge_request" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['description']).to eq('Test description for Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request')
end end
...@@ -334,7 +336,7 @@ describe API::MergeRequests do ...@@ -334,7 +336,7 @@ describe API::MergeRequests do
expect(fork_project.forked_from_project).to eq(project) expect(fork_project.forked_from_project).to eq(project)
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
end end
...@@ -348,25 +350,25 @@ describe API::MergeRequests do ...@@ -348,25 +350,25 @@ describe API::MergeRequests do
author: user2, author: user2,
target_project_id: project.id target_project_id: project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
it "returns 400 when source_branch is missing" do it "returns 400 when source_branch is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when target_branch is missing" do it "returns 400 when target_branch is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when title is missing" do it "returns 400 when title is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
context 'when target_branch is specified' do context 'when target_branch is specified' do
...@@ -377,7 +379,7 @@ describe API::MergeRequests do ...@@ -377,7 +379,7 @@ describe API::MergeRequests do
source_branch: 'markdown', source_branch: 'markdown',
author: user, author: user,
target_project_id: fork_project.id target_project_id: fork_project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
it 'returns 422 if targeting a different fork' do it 'returns 422 if targeting a different fork' do
...@@ -387,14 +389,14 @@ describe API::MergeRequests do ...@@ -387,14 +389,14 @@ describe API::MergeRequests do
source_branch: 'markdown', source_branch: 'markdown',
author: user2, author: user2,
target_project_id: unrelated_project.id target_project_id: unrelated_project.id
expect(response).to have_http_status(422) expect(response).to have_gitlab_http_status(422)
end end
end end
it "returns 201 when target_branch is specified and for the same project" do it "returns 201 when target_branch is specified and for the same project" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(201)
end end
end end
end end
......
...@@ -20,6 +20,10 @@ describe CreateDeploymentService do ...@@ -20,6 +20,10 @@ describe CreateDeploymentService do
let(:service) { described_class.new(job) } let(:service) { described_class.new(job) }
before do
allow_any_instance_of(Deployment).to receive(:create_ref)
end
describe '#execute' do describe '#execute' do
subject { service.execute } subject { service.execute }
......
...@@ -20,7 +20,7 @@ describe Issues::ResolveDiscussions do ...@@ -20,7 +20,7 @@ describe Issues::ResolveDiscussions do
describe "for resolving discussions" do describe "for resolving discussions" do
let(:discussion) { create(:diff_note_on_merge_request, project: project, note: "Almost done").to_discussion } let(:discussion) { create(:diff_note_on_merge_request, project: project, note: "Almost done").to_discussion }
let(:merge_request) { discussion.noteable } let(:merge_request) { discussion.noteable }
let(:other_merge_request) { create(:merge_request, source_project: project, source_branch: "other") } let(:other_merge_request) { create(:merge_request, source_project: project, source_branch: "fix") }
describe "#merge_request_for_resolving_discussion" do describe "#merge_request_for_resolving_discussion" do
let(:service) { DummyService.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid) } let(:service) { DummyService.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid) }
......
...@@ -3,7 +3,7 @@ require "spec_helper" ...@@ -3,7 +3,7 @@ require "spec_helper"
describe MergeRequests::GetUrlsService do describe MergeRequests::GetUrlsService do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:service) { described_class.new(project) } let(:service) { described_class.new(project) }
let(:source_branch) { "my_branch" } let(:source_branch) { "merge-test" }
let(:new_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=#{source_branch}" } let(:new_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=#{source_branch}" }
let(:show_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/#{merge_request.iid}" } let(:show_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/#{merge_request.iid}" }
let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" } let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
...@@ -111,9 +111,9 @@ describe MergeRequests::GetUrlsService do ...@@ -111,9 +111,9 @@ describe MergeRequests::GetUrlsService do
end end
context 'pushing new branch and existing branch (with merge request created) at once' do context 'pushing new branch and existing branch (with merge request created) at once' do
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: "existing_branch") } let!(:merge_request) { create(:merge_request, source_project: project, source_branch: "markdown") }
let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch" } let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch" }
let(:existing_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/existing_branch" } let(:existing_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/markdown" }
let(:changes) { "#{new_branch_changes}\n#{existing_branch_changes}" } let(:changes) { "#{new_branch_changes}\n#{existing_branch_changes}" }
let(:new_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch" } let(:new_merge_request_url) { "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch" }
...@@ -124,7 +124,7 @@ describe MergeRequests::GetUrlsService do ...@@ -124,7 +124,7 @@ describe MergeRequests::GetUrlsService do
url: new_merge_request_url, url: new_merge_request_url,
new_merge_request: true new_merge_request: true
}, { }, {
branch_name: "existing_branch", branch_name: "markdown",
url: show_merge_request_url, url: show_merge_request_url,
new_merge_request: false new_merge_request: false
}]) }])
......
...@@ -2,12 +2,12 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil| ...@@ -2,12 +2,12 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
before do before do
@issuable_ids = [] @issuable_ids = []
2.times do |n| %w[fix improve/awesome].each do |source_branch|
issuable = issuable =
if issuable_type == :issue if issuable_type == :issue
create(issuable_type, project: project) create(issuable_type, project: project)
else else
create(issuable_type, source_project: project, source_branch: "#{n}-feature") create(issuable_type, source_project: project, source_branch: source_branch)
end end
@issuable_ids << issuable.id @issuable_ids << issuable.id
......
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