diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
commit | 419c53ec62de6e97a517abd5fdd4cbde3a942a34 (patch) | |
tree | 1f43a548b46bca8a5fb8fe0c31cef1883d49c5b6 /spec/lib/api/entities/diff_spec.rb | |
parent | 1da20d9135b3ad9e75e65b028bffc921aaf8deb7 (diff) |
Add latest changes from gitlab-org/gitlab@16-5-stable-eev16.5.0-rc42
Diffstat (limited to 'spec/lib/api/entities/diff_spec.rb')
-rw-r--r-- | spec/lib/api/entities/diff_spec.rb | 46 |
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 |