2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :controller do
|
|
|
|
include JavaScriptFixturesHelpers
|
|
|
|
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :repository, namespace: namespace, path: 'merge-requests-project') }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project, target_project: project, description: '- [ ] Task List Item') }
|
|
|
|
let(:merged_merge_request) { create(:merge_request, :merged, source_project: project, target_project: project) }
|
|
|
|
let(:pipeline) do
|
|
|
|
create(
|
|
|
|
:ci_pipeline,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha
|
|
|
|
)
|
|
|
|
end
|
|
|
|
let(:path) { "files/ruby/popen.rb" }
|
|
|
|
let(:position) do
|
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: path,
|
|
|
|
new_path: path,
|
|
|
|
old_line: nil,
|
|
|
|
new_line: 14,
|
|
|
|
diff_refs: merge_request.diff_refs
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
clean_frontend_fixtures('merge_requests/')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
after do
|
|
|
|
remove_repository(project)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'merge_requests/merge_request_of_current_user.html.raw' do |example|
|
2018-03-17 18:26:18 +05:30
|
|
|
merge_request.update(author: admin)
|
|
|
|
|
|
|
|
render_merge_request(example.description, merge_request)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'merge_requests/merge_request_with_task_list.html.raw' do |example|
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:ci_build, :pending, pipeline: pipeline)
|
|
|
|
|
|
|
|
render_merge_request(example.description, merge_request)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'merge_requests/merged_merge_request.html.raw' do |example|
|
|
|
|
allow_any_instance_of(MergeRequest).to receive(:source_branch_exists?).and_return(true)
|
|
|
|
allow_any_instance_of(MergeRequest).to receive(:can_remove_source_branch?).and_return(true)
|
2017-08-17 22:00:37 +05:30
|
|
|
render_merge_request(example.description, merged_merge_request)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'merge_requests/diff_comment.html.raw' do |example|
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
|
|
|
|
create(:note_on_merge_request, author: admin, project: project, noteable: merge_request)
|
|
|
|
render_merge_request(example.description, merge_request)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'merge_requests/merge_request_with_comment.html.raw' do |example|
|
2018-03-17 18:26:18 +05:30
|
|
|
create(:note_on_merge_request, author: admin, project: project, noteable: merge_request, note: '- [ ] Task List Item')
|
|
|
|
render_merge_request(example.description, merge_request)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'merge_requests/discussions.json' do |example|
|
|
|
|
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
|
|
|
|
render_discussions_json(merge_request, example.description)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'merge_requests/diff_discussion.json' do |example|
|
|
|
|
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
|
|
|
|
render_discussions_json(merge_request, example.description)
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'merge_requests/resolved_diff_discussion.json' do |example|
|
|
|
|
note = create(:discussion_note_on_merge_request, :resolved, project: project, author: admin, position: position, noteable: merge_request)
|
|
|
|
create(:system_note, project: project, author: admin, noteable: merge_request, discussion_id: note.discussion.id)
|
|
|
|
|
|
|
|
render_discussions_json(merge_request, example.description)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'with image diff' do
|
|
|
|
let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images") }
|
|
|
|
let(:image_path) { "files/images/ee_repo_logo.png" }
|
|
|
|
let(:image_position) do
|
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: image_path,
|
|
|
|
new_path: image_path,
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
position_type: "image",
|
|
|
|
diff_refs: merge_request2.diff_refs
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'merge_requests/image_diff_discussion.json' do |example|
|
|
|
|
create(:diff_note_on_merge_request, project: project, noteable: merge_request2, position: image_position)
|
|
|
|
render_discussions_json(merge_request2, example.description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def render_discussions_json(merge_request, fixture_file_name)
|
2019-02-15 15:39:39 +05:30
|
|
|
get :discussions, params: {
|
2018-03-27 19:54:05 +05:30
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
2019-02-15 15:39:39 +05:30
|
|
|
id: merge_request.to_param
|
|
|
|
}, format: :json
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
store_frontend_fixture(response, fixture_file_name)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def render_merge_request(fixture_file_name, merge_request)
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: {
|
2017-08-17 22:00:37 +05:30
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
2019-02-15 15:39:39 +05:30
|
|
|
id: merge_request.to_param
|
|
|
|
}, format: :html
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
store_frontend_fixture(response, fixture_file_name)
|
|
|
|
end
|
|
|
|
end
|