2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::MergeRequests::CreationsController do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { project.owner }
|
|
|
|
let(:fork_project) { create(:forked_project_with_submodules) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:get_diff_params) do
|
|
|
|
{
|
|
|
|
namespace_id: fork_project.namespace.to_param,
|
|
|
|
project_id: fork_project,
|
|
|
|
merge_request: {
|
|
|
|
source_branch: 'remove-submodule',
|
|
|
|
target_branch: 'master'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
fork_project.add_maintainer(user)
|
2018-03-27 19:54:05 +05:30
|
|
|
Projects::ForkService.new(project, user).execute(fork_project)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET new' do
|
|
|
|
context 'merge request that removes a submodule' do
|
|
|
|
it 'renders new merge request widget template' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :new, params: get_diff_params
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
context 'merge request with some commits' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:large_diff_params) do
|
|
|
|
{
|
|
|
|
namespace_id: fork_project.namespace.to_param,
|
|
|
|
project_id: fork_project,
|
|
|
|
merge_request: {
|
|
|
|
source_branch: 'master',
|
|
|
|
target_branch: 'fix'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with artificial limits' do
|
|
|
|
before do
|
|
|
|
# Load MergeRequestdiff so stub_const won't override it with its own definition
|
|
|
|
# See https://github.com/rspec/rspec-mocks/issues/1079
|
|
|
|
stub_const("#{MergeRequestDiff}::COMMITS_SAFE_SIZE", 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'limits total commits' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :new, params: large_diff_params
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
total = assigns(:total_commit_count)
|
|
|
|
expect(assigns(:commits)).to be_an Array
|
|
|
|
expect(total).to be > 0
|
|
|
|
expect(assigns(:hidden_commit_count)).to be > 0
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.body).to match %r(<span class="commits-count">2 commits</span>)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows total commits' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :new, params: large_diff_params
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
total = assigns(:total_commit_count)
|
|
|
|
expect(assigns(:commits)).to be_an Array
|
|
|
|
expect(total).to be > 0
|
|
|
|
expect(assigns(:hidden_commit_count)).to eq(0)
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.body).to match %r(<span class="commits-count">#{total} commits</span>)
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET diffs' do
|
|
|
|
context 'when merge request cannot be created' do
|
|
|
|
it 'does not assign diffs var' do
|
|
|
|
allow_any_instance_of(MergeRequest).to receive(:can_be_created).and_return(false)
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
get :diffs, params: get_diff_params.merge(format: 'json')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(response).to be_success
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(assigns[:diffs]).to be_nil
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET pipelines' do
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, sha: fork_project.commit('remove-submodule').id,
|
|
|
|
ref: 'remove-submodule',
|
|
|
|
project: fork_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders JSON including serialized pipelines' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :pipelines, params: get_diff_params.merge(format: 'json')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
expect(json_response).to have_key 'pipelines'
|
|
|
|
expect(json_response['pipelines']).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET diff_for_path' do
|
|
|
|
def diff_for_path(extra_params = {})
|
|
|
|
params = {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
format: 'json'
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
get :diff_for_path, params: params.merge(extra_params)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:existing_path) { 'files/ruby/feature.rb' }
|
|
|
|
|
|
|
|
context 'when both branches are in the same project' do
|
|
|
|
it 'disables diff notes' do
|
|
|
|
diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' })
|
|
|
|
|
|
|
|
expect(assigns(:diff_notes_disabled)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only renders the diffs for the path given' do
|
|
|
|
expect(controller).to receive(:render_diff_for_path).and_wrap_original do |meth, diffs|
|
|
|
|
expect(diffs.diff_files.map(&:new_path)).to contain_exactly(existing_path)
|
|
|
|
meth.call(diffs)
|
|
|
|
end
|
|
|
|
|
|
|
|
diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source branch is in a different project to the target' do
|
|
|
|
let(:other_project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
other_project.add_maintainer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the path exists in the diff' do
|
|
|
|
it 'disables diff notes' do
|
|
|
|
diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' })
|
|
|
|
|
|
|
|
expect(assigns(:diff_notes_disabled)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only renders the diffs for the path given' do
|
|
|
|
expect(controller).to receive(:render_diff_for_path).and_wrap_original do |meth, diffs|
|
|
|
|
expect(diffs.diff_files.map(&:new_path)).to contain_exactly(existing_path)
|
|
|
|
meth.call(diffs)
|
|
|
|
end
|
|
|
|
|
|
|
|
diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the path does not exist in the diff' do
|
|
|
|
before do
|
|
|
|
diff_for_path(old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb', merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
describe 'GET #branch_to' do
|
|
|
|
before do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches the commit if a user has access' do
|
|
|
|
expect(Ability).to receive(:allowed?).with(user, :read_project, project) { true }
|
|
|
|
|
|
|
|
get :branch_to,
|
2019-02-13 22:33:31 +05:30
|
|
|
params: {
|
|
|
|
namespace_id: fork_project.namespace,
|
|
|
|
project_id: fork_project,
|
|
|
|
target_project_id: project.id,
|
|
|
|
ref: 'master'
|
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
expect(assigns(:commit)).not_to be_nil
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not load the commit when the user cannot read the project' do
|
|
|
|
expect(Ability).to receive(:allowed?).with(user, :read_project, project) { false }
|
|
|
|
|
|
|
|
get :branch_to,
|
2019-02-13 22:33:31 +05:30
|
|
|
params: {
|
|
|
|
namespace_id: fork_project.namespace,
|
|
|
|
project_id: fork_project,
|
|
|
|
target_project_id: project.id,
|
|
|
|
ref: 'master'
|
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
expect(assigns(:commit)).to be_nil
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|