diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-13 21:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-13 21:09:11 +0300 |
commit | feb61d56e7ce9ab2cd994486bbad9887c3c023f5 (patch) | |
tree | 716c5af8f027f560e66123a90f848e7a9c8f80c4 /spec/serializers/diffs_entity_spec.rb | |
parent | 37699393e9d68181a04f54ded5ae1b08b6272291 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers/diffs_entity_spec.rb')
-rw-r--r-- | spec/serializers/diffs_entity_spec.rb | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb index 5928a1c24b3..7569493573b 100644 --- a/spec/serializers/diffs_entity_spec.rb +++ b/spec/serializers/diffs_entity_spec.rb @@ -8,9 +8,12 @@ RSpec.describe DiffsEntity do let(:request) { EntityRequest.new(project: project, current_user: user) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request_diffs) { merge_request.merge_request_diffs } + let(:options) do + { request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs } + end let(:entity) do - described_class.new(merge_request_diffs.first.diffs, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs) + described_class.new(merge_request_diffs.first.diffs, options) end context 'as json' do @@ -68,5 +71,50 @@ RSpec.describe DiffsEntity do end end end + + context 'when there are conflicts' do + let(:diff_files) { merge_request_diffs.first.diffs.diff_files } + let(:diff_file_with_conflict) { diff_files.to_a.last } + let(:diff_file_without_conflict) { diff_files.to_a[-2] } + + let(:resolvable_conflicts) { true } + let(:conflict_file) { double(our_path: diff_file_with_conflict.new_path) } + let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) } + + let(:merge_ref_head_diff) { true } + let(:options) { super().merge(merge_ref_head_diff: merge_ref_head_diff) } + + before do + allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts) + end + + it 'conflicts are highlighted' do + expect(conflict_file).to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).not_to receive(:diff_lines_for_serializer) + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + + context 'merge ref head diff is not chosen to be displayed' do + let(:merge_ref_head_diff) { false } + + it 'conflicts are not calculated' do + expect(MergeRequests::Conflicts::ListService).not_to receive(:new) + end + end + + context 'when conflicts cannot be resolved' do + let(:resolvable_conflicts) { false } + + it 'conflicts are not highlighted' do + expect(conflict_file).not_to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + end + end end end |