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
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/api/schemas/entities/diff_line.json14
-rw-r--r--spec/fixtures/api/schemas/entities/diff_line_parallel.json11
-rw-r--r--spec/serializers/diff_file_entity_spec.rb17
-rw-r--r--spec/serializers/diff_line_serializer_spec.rb25
4 files changed, 67 insertions, 0 deletions
diff --git a/spec/fixtures/api/schemas/entities/diff_line.json b/spec/fixtures/api/schemas/entities/diff_line.json
new file mode 100644
index 00000000000..66e8b443e1b
--- /dev/null
+++ b/spec/fixtures/api/schemas/entities/diff_line.json
@@ -0,0 +1,14 @@
+{
+ "type": "object",
+ "required": ["type"],
+ "properties": {
+ "line_code": { "type": ["string", "null"] },
+ "type": { "type": ["string", "null"] },
+ "old_line": { "type": ["integer", "null"] },
+ "new_line": { "type": ["integer", "null"] },
+ "text": { "type": ["string"] },
+ "rich_text": { "type": ["string"] },
+ "meta_data": { "type": ["object", "null"] }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/entities/diff_line_parallel.json b/spec/fixtures/api/schemas/entities/diff_line_parallel.json
new file mode 100644
index 00000000000..f924eb0c601
--- /dev/null
+++ b/spec/fixtures/api/schemas/entities/diff_line_parallel.json
@@ -0,0 +1,11 @@
+{
+ "required" : [
+ "left",
+ "right"
+ ],
+ "properties" : {
+ "left": { "$ref": "diff_line.json" },
+ "right": { "$ref": "diff_line.json" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb
index 00b2146dc86..3d90ce44dfb 100644
--- a/spec/serializers/diff_file_entity_spec.rb
+++ b/spec/serializers/diff_file_entity_spec.rb
@@ -67,4 +67,21 @@ describe DiffFileEntity do
end
end
end
+
+ context '#parallel_diff_lines' do
+ it 'exposes parallel diff lines correctly' do
+ response = subject
+
+ lines = response[:parallel_diff_lines]
+
+ # make sure at least one line is present for each side
+ expect(lines.map { |line| line[:right] }.compact).to be_present
+ expect(lines.map { |line| line[:left] }.compact).to be_present
+ # make sure all lines are in correct format
+ lines.each do |parallel_line|
+ expect(parallel_line[:left].as_json).to match_schema('entities/diff_line') if parallel_line[:left]
+ expect(parallel_line[:right].as_json).to match_schema('entities/diff_line') if parallel_line[:right]
+ end
+ end
+ end
end
diff --git a/spec/serializers/diff_line_serializer_spec.rb b/spec/serializers/diff_line_serializer_spec.rb
new file mode 100644
index 00000000000..6dd8abd0579
--- /dev/null
+++ b/spec/serializers/diff_line_serializer_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe DiffLineSerializer do
+ let(:line) { Gitlab::Diff::Line.new('hello world', 'new', 1, nil, 1) }
+ let(:serializer) { described_class.new.represent(line) }
+
+ describe '#to_json' do
+ subject { serializer.to_json }
+
+ it 'matches the schema' do
+ expect(subject).to match_schema('entities/diff_line')
+ end
+
+ context 'when lines are parallel' do
+ let(:right_line) { Gitlab::Diff::Line.new('right line', 'new', 1, nil, 1) }
+ let(:left_line) { Gitlab::Diff::Line.new('left line', 'match', 1, nil, 1) }
+ let(:parallel_line) { [{ right: right_line, left: left_line }] }
+ let(:serializer) { described_class.new.represent(parallel_line, {}, DiffLineParallelEntity) }
+
+ it 'matches the schema' do
+ expect(subject).to match_schema('entities/diff_line_parallel')
+ end
+ end
+ end
+end