diff options
author | Jack Jennings <jack@standard-library.com> | 2017-05-11 02:25:10 -0700 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-11 11:25:10 +0200 |
commit | 2d000e9c4e082bf7ca8b180e90a061486d199381 (patch) | |
tree | 36e344b0fca224c2bbdba16e7288388e434e6cbf /spec/models | |
parent | b913746752b86062a951635758bfd13a5b0f5dcc (diff) |
Add specs for current Status#permitted? implementation (#2982)
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/status_spec.rb | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 721951030..f5c65f5c9 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -120,7 +120,63 @@ RSpec.describe Status, type: :model do end describe '#permitted?' do - pending + it 'returns true when direct and account is viewer' do + subject.visibility = :direct + expect(subject.permitted?(subject.account)).to be true + end + + it 'returns true when direct and viewer is mentioned' do + subject.visibility = :direct + subject.mentions = [Fabricate(:mention, account: alice)] + + expect(subject.permitted?(alice)).to be true + end + + it 'returns false when direct and viewer is not mentioned' do + viewer = Fabricate(:account) + subject.visibility = :direct + + expect(subject.permitted?(viewer)).to be false + end + + it 'returns true when private and account is viewer' do + subject.visibility = :direct + expect(subject.permitted?(subject.account)).to be true + end + + it 'returns true when private and account is following viewer' do + follow = Fabricate(:follow) + subject.visibility = :private + subject.account = follow.target_account + + expect(subject.permitted?(follow.account)).to be true + end + + it 'returns true when private and viewer is mentioned' do + subject.visibility = :private + subject.mentions = [Fabricate(:mention, account: alice)] + + expect(subject.permitted?(alice)).to be true + end + + it 'returns false when private and viewer is not mentioned or followed' do + viewer = Fabricate(:account) + subject.visibility = :private + + expect(subject.permitted?(viewer)).to be false + end + + it 'returns true when no viewer' do + expect(subject.permitted?).to be true + end + + it 'returns false when viewer is blocked' do + block = Fabricate(:block) + subject.visibility = :private + subject.account = block.target_account + + expect(subject.permitted?(block.account)).to be false + end end describe '#filter_from_context?' do |