diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/serializers/base_discussion_entity_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/serializers/base_discussion_entity_spec.rb')
-rw-r--r-- | spec/serializers/base_discussion_entity_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/serializers/base_discussion_entity_spec.rb b/spec/serializers/base_discussion_entity_spec.rb new file mode 100644 index 00000000000..5f483da4113 --- /dev/null +++ b/spec/serializers/base_discussion_entity_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BaseDiscussionEntity do + let_it_be(:user) { create(:user) } + let_it_be(:note) { create(:discussion_note_on_merge_request) } + + let(:request) { double('request', note_entity: ProjectNoteEntity) } + let(:controller) { double('controller') } + let(:entity) { described_class.new(discussion, request: request, context: controller) } + let(:discussion) { note.discussion } + + subject { entity.as_json } + + before do + allow(controller).to receive(:render_to_string) + allow(request).to receive(:current_user).and_return(user) + allow(request).to receive(:noteable).and_return(note.noteable) + end + + it 'exposes correct attributes' do + expect(subject.keys.sort).to include( + :commit_id, + :confidential, + :diff_discussion, + :discussion_path, + :expanded, + :for_commit, + :id, + :individual_note, + :resolvable, + :resolve_path, + :resolve_with_issue_path + ) + end + + context 'when is LegacyDiffDiscussion' do + let(:project) { create(:project) } + let(:merge_request) { create(:merge_request, source_project: project) } + let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } + + it 'exposes correct attributes' do + expect(subject.keys.sort).to include( + :commit_id, + :diff_discussion, + :discussion_path, + :expanded, + :for_commit, + :id, + :individual_note + ) + end + end + + context 'when diff file is present' do + let(:note) { create(:diff_note_on_merge_request) } + + it 'exposes diff file attributes' do + expect(subject.keys.sort).to include( + :active, + :diff_file, + :line_code, + :position, + :truncated_diff_lines + ) + end + end +end |