diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-04-17 04:26:49 +0300 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-04-16 12:26:49 +0300 |
commit | 199337103ba4db2af303bcdd481f97e7611aafe9 (patch) | |
tree | daf0f851941e08350b4cf72a346e9d8806febca9 /spec/models/notification_recipient_spec.rb | |
parent | dc8848794bfd2f06345d4dbba8a918aa09ee07a8 (diff) |
Stop sending emails to users who can't read commit
This is to ensure that only users will be able receive
an email if they can read a commit from the repository
even if they are watching the activity of it.
Diffstat (limited to 'spec/models/notification_recipient_spec.rb')
-rw-r--r-- | spec/models/notification_recipient_spec.rb | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb index 3710f2be287..1b1ede6b14c 100644 --- a/spec/models/notification_recipient_spec.rb +++ b/spec/models/notification_recipient_spec.rb @@ -9,11 +9,43 @@ describe NotificationRecipient do subject(:recipient) { described_class.new(user, :watch, target: target, project: project) } - it 'denies access to a target when cross project access is denied' do - allow(Ability).to receive(:allowed?).and_call_original - expect(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(false) + describe '#has_access?' do + before do + allow(user).to receive(:can?).and_call_original + end + + context 'user cannot read cross project' do + it 'returns false' do + expect(user).to receive(:can?).with(:read_cross_project).and_return(false) + expect(recipient.has_access?).to eq false + end + end + + context 'user cannot read build' do + let(:target) { build(:ci_pipeline) } + + it 'returns false' do + expect(user).to receive(:can?).with(:read_build, target).and_return(false) + expect(recipient.has_access?).to eq false + end + end - expect(recipient.has_access?).to be_falsy + context 'user cannot read commit' do + let(:target) { build(:commit) } + + it 'returns false' do + expect(user).to receive(:can?).with(:read_commit, target).and_return(false) + expect(recipient.has_access?).to eq false + end + end + + context 'target has no policy' do + let(:target) { double.as_null_object } + + it 'returns true' do + expect(recipient.has_access?).to eq true + end + end end context '#notification_setting' do |