diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-04-03 16:03:00 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2018-04-03 16:03:00 +0000 |
commit | 65664c2eaeed853396c97a9b46e404c05209c42e (patch) | |
tree | e903e3afa6fe5c0f3492dc443776ebd1ce8ade57 /spec/serializers | |
parent | 67ca10f33ec41e7cecac152e016aa2c0956a7586 (diff) | |
download | gitlab-ce-65664c2eaeed853396c97a9b46e404c05209c42e.tar.gz |
Refactor discussions/notes code
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/discussion_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/note_entity_spec.rb | 50 | ||||
-rw-r--r-- | spec/serializers/project_note_entity_spec.rb | 29 |
3 files changed, 31 insertions, 50 deletions
diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb index 7ee8e38af1c..7e19e74ca00 100644 --- a/spec/serializers/discussion_entity_spec.rb +++ b/spec/serializers/discussion_entity_spec.rb @@ -6,7 +6,7 @@ describe DiscussionEntity do let(:user) { create(:user) } let(:note) { create(:discussion_note_on_merge_request) } let(:discussion) { note.discussion } - let(:request) { double('request') } + let(:request) { double('request', note_entity: ProjectNoteEntity) } let(:controller) { double('controller') } let(:entity) { described_class.new(discussion, request: request, context: controller) } diff --git a/spec/serializers/note_entity_spec.rb b/spec/serializers/note_entity_spec.rb index 51a8587ace9..13cda781cda 100644 --- a/spec/serializers/note_entity_spec.rb +++ b/spec/serializers/note_entity_spec.rb @@ -10,53 +10,5 @@ describe NoteEntity do let(:user) { create(:user) } subject { entity.as_json } - context 'basic note' do - it 'exposes correct elements' do - expect(subject).to include(:type, :author, :human_access, :note, :note_html, :current_user, - :discussion_id, :emoji_awardable, :award_emoji, :toggle_award_path, :report_abuse_path, :path, :attachment) - end - - it 'does not expose elements for specific notes cases' do - expect(subject).not_to include(:last_edited_by, :last_edited_at, :system_note_icon_name) - end - - it 'exposes author correctly' do - expect(subject[:author]).to include(:id, :name, :username, :state, :avatar_url, :path) - end - - it 'does not expose web_url for author' do - expect(subject[:author]).not_to include(:web_url) - end - end - - context 'when note was edited' do - before do - note.update(updated_at: 1.minute.from_now, updated_by: user) - end - - it 'exposes last_edited_at and last_edited_by elements' do - expect(subject).to include(:last_edited_at, :last_edited_by) - end - end - - context 'when note is a system note' do - before do - note.update(system: true) - end - - it 'exposes system_note_icon_name element' do - expect(subject).to include(:system_note_icon_name) - end - end - - context 'when note is part of resolvable discussion' do - before do - allow(note).to receive(:part_of_discussion?).and_return(true) - allow(note).to receive(:resolvable?).and_return(true) - end - - it 'exposes paths to resolve note' do - expect(subject).to include(:resolve_path, :resolve_with_issue_path) - end - end + it_behaves_like 'note entity' end diff --git a/spec/serializers/project_note_entity_spec.rb b/spec/serializers/project_note_entity_spec.rb new file mode 100644 index 00000000000..dafd1cf603e --- /dev/null +++ b/spec/serializers/project_note_entity_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe ProjectNoteEntity do + include Gitlab::Routing + + let(:request) { double('request', current_user: user, noteable: note.noteable) } + + let(:entity) { described_class.new(note, request: request) } + let(:note) { create(:note) } + let(:user) { create(:user) } + subject { entity.as_json } + + it_behaves_like 'note entity' + + it 'exposes project-specific elements' do + expect(subject).to include(:human_access, :toggle_award_path, :path) + end + + context 'when note is part of resolvable discussion' do + before do + allow(note).to receive(:part_of_discussion?).and_return(true) + allow(note).to receive(:resolvable?).and_return(true) + end + + it 'exposes paths to resolve note' do + expect(subject).to include(:resolve_path, :resolve_with_issue_path) + end + end +end |