debian-mirror-gitlab/spec/frontend/fixtures/merge_requests.rb

141 lines
4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :controller do
2017-08-17 22:00:37 +05:30
include JavaScriptFixturesHelpers
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') }
2021-02-22 17:27:13 +05:30
let(:user) { project.owner }
2019-12-26 22:10:19 +05:30
# rubocop: disable Layout/TrailingWhitespace
2020-03-13 15:44:24 +05:30
let(:description) do
<<~MARKDOWN.strip_heredoc
- [ ] Task List Item
2021-02-22 17:27:13 +05:30
- [ ]
2020-03-13 15:44:24 +05:30
- [ ] Task List Item 2
MARKDOWN
end
# rubocop: enable Layout/TrailingWhitespace
2019-12-26 22:10:19 +05:30
let(:merge_request) do
create(
:merge_request,
:with_diffs,
source_project: project,
target_project: project,
2020-03-13 15:44:24 +05:30
description: description
2019-12-26 22:10:19 +05:30
)
end
2017-08-17 22:00:37 +05:30
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
2020-10-24 23:57:45 +05:30
2017-08-17 22:00:37 +05:30
let(:path) { "files/ruby/popen.rb" }
let(:position) do
2020-03-13 15:44:24 +05:30
build(:text_diff_position, :added,
file: path,
2017-08-17 22:00:37 +05:30
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
2021-02-22 17:27:13 +05:30
sign_in(user)
2019-07-07 11:18:12 +05:30
allow(Discussion).to receive(:build_discussion_id).and_return(['discussionid:ceterumcenseo'])
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
after do
remove_repository(project)
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/merge_request_of_current_user.html' do
2021-02-22 17:27:13 +05:30
merge_request.update(author: user)
2018-03-17 18:26:18 +05:30
2019-09-04 21:01:54 +05:30
render_merge_request(merge_request)
2018-03-17 18:26:18 +05:30
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/merge_request_with_task_list.html' do
2017-08-17 22:00:37 +05:30
create(:ci_build, :pending, pipeline: pipeline)
2019-09-04 21:01:54 +05:30
render_merge_request(merge_request)
2017-08-17 22:00:37 +05:30
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/diff_comment.html' do
2021-02-22 17:27:13 +05:30
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
create(:note_on_merge_request, author: user, project: project, noteable: merge_request)
2019-09-04 21:01:54 +05:30
render_merge_request(merge_request)
2017-08-17 22:00:37 +05:30
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/diff_discussion.json' do
2021-02-22 17:27:13 +05:30
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
2019-09-04 21:01:54 +05:30
render_discussions_json(merge_request)
2018-03-27 19:54:05 +05:30
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/resolved_diff_discussion.json' do
2021-02-22 17:27:13 +05:30
note = create(:discussion_note_on_merge_request, :resolved, project: project, author: user, position: position, noteable: merge_request)
create(:system_note, project: project, author: user, noteable: merge_request, discussion_id: note.discussion.id)
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
render_discussions_json(merge_request)
2018-11-08 19:23:39 +05:30
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
2020-03-13 15:44:24 +05:30
build(:image_diff_position,
file: image_path,
2018-03-27 19:54:05 +05:30
diff_refs: merge_request2.diff_refs
)
end
2019-09-04 21:01:54 +05:30
it 'merge_requests/image_diff_discussion.json' do
2018-03-27 19:54:05 +05:30
create(:diff_note_on_merge_request, project: project, noteable: merge_request2, position: image_position)
2019-09-04 21:01:54 +05:30
render_discussions_json(merge_request2)
2018-03-27 19:54:05 +05:30
end
end
2020-03-13 15:44:24 +05:30
context 'with mentions' do
let(:group) { create(:group) }
2021-02-22 17:27:13 +05:30
let(:description) { "@#{group.full_path} @all @#{user.username}" }
2020-03-13 15:44:24 +05:30
it 'merge_requests/merge_request_with_mentions.html' do
render_merge_request(merge_request)
end
end
2017-08-17 22:00:37 +05:30
private
2019-09-04 21:01:54 +05:30
def render_discussions_json(merge_request)
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
end
2019-09-04 21:01:54 +05:30
def render_merge_request(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
2019-10-12 21:52:04 +05:30
expect(response).to be_successful
2017-08-17 22:00:37 +05:30
end
end