diff options
Diffstat (limited to 'spec/support/shared_examples/serializers/note_entity_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/serializers/note_entity_shared_examples.rb | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/spec/support/shared_examples/serializers/note_entity_shared_examples.rb b/spec/support/shared_examples/serializers/note_entity_shared_examples.rb index a90a2dc3667..9af6ec45e49 100644 --- a/spec/support/shared_examples/serializers/note_entity_shared_examples.rb +++ b/spec/support/shared_examples/serializers/note_entity_shared_examples.rb @@ -5,8 +5,21 @@ RSpec.shared_examples 'note entity' do context 'basic note' do it 'exposes correct elements' do - expect(subject).to include(:type, :author, :note, :note_html, :current_user, :discussion_id, - :emoji_awardable, :award_emoji, :report_abuse_path, :attachment, :noteable_note_url, :resolvable) + expect(subject).to include( + :attachment, + :author, + :award_emoji, + :base_discussion, + :current_user, + :discussion_id, + :emoji_awardable, + :note, + :note_html, + :noteable_note_url, + :report_abuse_path, + :resolvable, + :type + ) end it 'does not expose elements for specific notes cases' do @@ -20,6 +33,39 @@ RSpec.shared_examples 'note entity' do it 'does not expose web_url for author' do expect(subject[:author]).not_to include(:web_url) end + + it 'exposes permission fields on current_user' do + expect(subject[:current_user]).to include(:can_edit, :can_award_emoji, :can_resolve, :can_resolve_discussion) + end + + describe ':can_resolve_discussion' do + context 'discussion is resolvable' do + before do + expect(note.discussion).to receive(:resolvable?).and_return(true) + end + + context 'user can resolve' do + it 'is true' do + expect(note.discussion).to receive(:can_resolve?).with(user).and_return(true) + expect(subject[:current_user][:can_resolve_discussion]).to be_truthy + end + end + + context 'user cannot resolve' do + it 'is false' do + expect(note.discussion).to receive(:can_resolve?).with(user).and_return(false) + expect(subject[:current_user][:can_resolve_discussion]).to be_falsey + end + end + end + + context 'discussion is not resolvable' do + it 'is false' do + expect(note.discussion).to receive(:resolvable?).and_return(false) + expect(subject[:current_user][:can_resolve_discussion]).to be_falsey + end + end + end end context 'when note was edited' do |