Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/serializers/diffs_entity_spec.rb')
-rw-r--r--spec/serializers/diffs_entity_spec.rb73
1 files changed, 26 insertions, 47 deletions
diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb
index 72777bde30c..ba40d538ccb 100644
--- a/spec/serializers/diffs_entity_spec.rb
+++ b/spec/serializers/diffs_entity_spec.rb
@@ -9,13 +9,13 @@ RSpec.describe DiffsEntity do
let(:request) { EntityRequest.new(project: project, current_user: user) }
let(:merge_request_diffs) { merge_request.merge_request_diffs }
- let(:allow_tree_conflicts) { false }
+ let(:merge_conflicts_in_diff) { false }
let(:options) do
{
request: request,
merge_request: merge_request,
merge_request_diffs: merge_request_diffs,
- allow_tree_conflicts: allow_tree_conflicts
+ merge_conflicts_in_diff: merge_conflicts_in_diff
}
end
@@ -87,60 +87,39 @@ RSpec.describe DiffsEntity do
end
end
- context 'when there are conflicts' do
+ describe 'diff_files' 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(path: diff_file_with_conflict.new_path, conflict_type: :both_modified) }
- let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) }
+ it 'serializes diff files using DiffFileEntity' do
+ expect(DiffFileEntity)
+ .to receive(:represent)
+ .with(
+ diff_files,
+ hash_including(options.merge(conflicts: nil))
+ )
- let(:merge_ref_head_diff) { true }
- let(:options) { super().merge(merge_ref_head_diff: merge_ref_head_diff) }
-
- before do
- allow(merge_request).to receive(:cannot_be_merged?).and_return(true)
- 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
+ subject[:diff_files]
end
- context 'when conflicts cannot be resolved' do
- let(:resolvable_conflicts) { false }
+ context 'when merge_conflicts_in_diff is true' do
+ let(:conflict_file) { double(path: diff_files.first.new_path, conflict_type: :both_modified) }
+ let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: false) }
+ let(:merge_conflicts_in_diff) { true }
- 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
+ before do
+ allow(merge_request).to receive(:cannot_be_merged?).and_return(true)
+ allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts)
end
- context 'when allow_tree_conflicts is set to true' do
- let(:allow_tree_conflicts) { true }
-
- it 'conflicts are still 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
+ it 'serializes diff files with conflicts' do
+ expect(DiffFileEntity)
+ .to receive(:represent)
+ .with(
+ diff_files,
+ hash_including(options.merge(conflicts: { conflict_file.path => conflict_file }))
+ )
- subject
- end
+ subject[:diff_files]
end
end
end