diff options
author | Eugen <eugen@zeonfederated.com> | 2017-04-24 22:37:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-24 22:37:24 +0200 |
commit | 338df98ddf14493d655a72f38f2bde482becab54 (patch) | |
tree | 0fef5299ed353ed11c3a39781fec941a6311f7cf /spec/lib | |
parent | da022e1e4f8f46a00e43f122adf4792a8f57608d (diff) |
Add more FeedManager#filter? tests (#2413)
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/feed_manager_spec.rb | 115 |
1 files changed, 109 insertions, 6 deletions
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 14553221f..16b1e7377 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -10,14 +10,117 @@ RSpec.describe FeedManager do end describe '#filter?' do - let(:followee) { Fabricate(:account, username: 'alice') } - let(:status) { Fabricate(:status, text: 'Hello world', account: followee) } - let(:follower) { Fabricate(:account, username: 'bob') } + let(:alice) { Fabricate(:account, username: 'alice') } + let(:bob) { Fabricate(:account, username: 'bob') } + let(:jeff) { Fabricate(:account, username: 'jeff') } - subject { FeedManager.instance.filter?(:home, status, follower) } + context 'for home feed' do + it 'returns false for followee\'s status' do + status = Fabricate(:status, text: 'Hello world', account: alice) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false + end - it 'returns a boolean value' do - expect(subject).to be false + it 'returns false for reblog by followee' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reblog = Fabricate(:status, reblog: status, account: alice) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be false + end + + it 'returns true for reblog by followee of blocked account' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reblog = Fabricate(:status, reblog: status, account: alice) + bob.follow!(alice) + bob.block!(jeff) + expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true + end + + it 'returns true for reblog by followee of muted account' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reblog = Fabricate(:status, reblog: status, account: alice) + bob.follow!(alice) + bob.mute!(jeff) + expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true + end + + it 'returns true for reblog by followee of someone who is blocking recipient' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reblog = Fabricate(:status, reblog: status, account: alice) + bob.follow!(alice) + jeff.block!(bob) + expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true + end + + it 'returns false for reply by followee to another followee' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) + bob.follow!(alice) + bob.follow!(jeff) + expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false + end + + it 'returns false for reply by followee to recipient' do + status = Fabricate(:status, text: 'Hello world', account: bob) + reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false + end + + it 'returns false for reply by followee to self' do + status = Fabricate(:status, text: 'Hello world', account: alice) + reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false + end + + it 'returns true for reply by followee to non-followed account' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be true + end + + it 'returns false for status by followee mentioning another account' do + bob.follow!(alice) + status = PostStatusService.new.call(alice, 'Hey @jeff') + expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false + end + + it 'returns true for status by followee mentioning blocked account' do + bob.block!(jeff) + bob.follow!(alice) + status = PostStatusService.new.call(alice, 'Hey @jeff') + expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true + end + end + + context 'for mentions feed' do + it 'returns true for status that mentions blocked account' do + bob.block!(jeff) + status = PostStatusService.new.call(alice, 'Hey @jeff') + expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true + end + + it 'returns true for status that replies to a blocked account' do + status = Fabricate(:status, text: 'Hello world', account: jeff) + reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) + bob.block!(jeff) + expect(FeedManager.instance.filter?(:mentions, reply, bob.id)).to be true + end + + it 'returns true for status by silenced account who recipient is not following' do + status = Fabricate(:status, text: 'Hello world', account: alice) + alice.update(silenced: true) + expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true + end + + it 'returns false for status by followed silenced account' do + status = Fabricate(:status, text: 'Hello world', account: alice) + alice.update(silenced: true) + bob.follow!(alice) + expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be false + end end end end |