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/lib/api/entities/diff_spec.rb')
-rw-r--r--spec/lib/api/entities/diff_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/lib/api/entities/diff_spec.rb b/spec/lib/api/entities/diff_spec.rb
new file mode 100644
index 00000000000..27d9ed44c98
--- /dev/null
+++ b/spec/lib/api/entities/diff_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ::API::Entities::Diff, feature_category: :source_code_management do
+ subject(:json) { entity.as_json }
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository }
+ let_it_be(:diff) { repository.diff('HEAD~1', 'HEAD').first }
+
+ let(:entity) { described_class.new(diff, options) }
+ let(:options) { {} }
+
+ it 'returns expected data' do
+ expect(entity.as_json).to eq(
+ {
+ diff: diff.diff,
+ new_path: diff.new_path,
+ old_path: diff.old_path,
+ a_mode: diff.a_mode,
+ b_mode: diff.b_mode,
+ new_file: diff.new_file?,
+ renamed_file: diff.renamed_file?,
+ deleted_file: diff.deleted_file?
+ }
+ )
+ end
+
+ context 'when enable_unidiff option is set' do
+ let(:options) { { enable_unidiff: true } }
+
+ it 'returns expected data' do
+ expect(entity.as_json).to include(diff: diff.unidiff)
+ end
+ end
+
+ context 'when enable_unidiff option is false' do
+ let(:options) { { enable_unidiff: false } }
+
+ it 'returns expected data' do
+ expect(entity.as_json).to include(diff: diff.diff)
+ end
+ end
+end