end
end
+ describe '.as_direct_timeline' do
+ let(:account) { Fabricate(:account) }
+ let(:followed) { Fabricate(:account) }
+ let(:not_followed) { Fabricate(:account) }
+
+ before do
+ Fabricate(:follow, account: account, target_account: followed)
+
+ @self_public_status = Fabricate(:status, account: account, visibility: :public)
+ @self_direct_status = Fabricate(:status, account: account, visibility: :direct)
+ @followed_public_status = Fabricate(:status, account: followed, visibility: :public)
+ @followed_direct_status = Fabricate(:status, account: followed, visibility: :direct)
+ @not_followed_direct_status = Fabricate(:status, account: not_followed, visibility: :direct)
+
+ @results = Status.as_direct_timeline(account)
+ end
+
+ it 'does not include public statuses from self' do
+ expect(@results).to_not include(@self_public_status)
+ end
+
+ it 'includes direct statuses from self' do
+ expect(@results).to include(@self_direct_status)
+ end
+
+ it 'does not include public statuses from followed' do
+ expect(@results).to_not include(@followed_public_status)
+ end
+
+ it 'does not include direct statuses not mentioning recipient from followed' do
+ expect(@results).to_not include(@followed_direct_status)
+ end
+
+ it 'does not include direct statuses not mentioning recipient from non-followed' do
+ expect(@results).to_not include(@not_followed_direct_status)
+ end
+
+ it 'includes direct statuses mentioning recipient from followed' do
+ Fabricate(:mention, account: account, status: @followed_direct_status)
+ results2 = Status.as_direct_timeline(account)
+ expect(results2).to include(@followed_direct_status)
+ end
+
+ it 'includes direct statuses mentioning recipient from non-followed' do
+ Fabricate(:mention, account: account, status: @not_followed_direct_status)
+ results2 = Status.as_direct_timeline(account)
+ expect(results2).to include(@not_followed_direct_status)
+ end
+ end
+
+ describe '.tagged_with' do
+ let(:tag1) { Fabricate(:tag) }
+ let(:tag2) { Fabricate(:tag) }
+ let(:tag3) { Fabricate(:tag) }
+ let!(:status1) { Fabricate(:status, tags: [tag1]) }
+ let!(:status2) { Fabricate(:status, tags: [tag2]) }
+ let!(:status3) { Fabricate(:status, tags: [tag3]) }
+ let!(:status4) { Fabricate(:status, tags: []) }
+ let!(:status5) { Fabricate(:status, tags: [tag1, tag2, tag3]) }
+
+ context 'when given one tag' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status5.id]
+ expect(Status.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status2.id, status5.id]
+ expect(Status.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status3.id, status5.id]
+ end
+ end
+
+ context 'when given multiple tags' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status2.id, status5.id]
+ expect(Status.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status3.id, status5.id]
+ expect(Status.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status2.id, status3.id, status5.id]
+ end
+ end
+ end
+
+ describe '.tagged_with_all' do
+ let(:tag1) { Fabricate(:tag) }
+ let(:tag2) { Fabricate(:tag) }
+ let(:tag3) { Fabricate(:tag) }
+ let!(:status1) { Fabricate(:status, tags: [tag1]) }
+ let!(:status2) { Fabricate(:status, tags: [tag2]) }
+ let!(:status3) { Fabricate(:status, tags: [tag3]) }
+ let!(:status4) { Fabricate(:status, tags: []) }
+ let!(:status5) { Fabricate(:status, tags: [tag1, tag2]) }
+
+ context 'when given one tag' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status5.id]
+ expect(Status.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status2.id, status5.id]
+ expect(Status.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status3.id]
+ end
+ end
+
+ context 'when given multiple tags' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status5.id]
+ expect(Status.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq []
+ expect(Status.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq []
+ end
+ end
+ end
+
+ describe '.tagged_with_none' do
+ let(:tag1) { Fabricate(:tag) }
+ let(:tag2) { Fabricate(:tag) }
+ let(:tag3) { Fabricate(:tag) }
+ let!(:status1) { Fabricate(:status, tags: [tag1]) }
+ let!(:status2) { Fabricate(:status, tags: [tag2]) }
+ let!(:status3) { Fabricate(:status, tags: [tag3]) }
+ let!(:status4) { Fabricate(:status, tags: []) }
+ let!(:status5) { Fabricate(:status, tags: [tag1, tag2, tag3]) }
+
+ context 'when given one tag' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to eq [status2.id, status3.id, status4.id]
+ expect(Status.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status3.id, status4.id]
+ expect(Status.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status2.id, status4.id]
+ end
+ end
+
+ context 'when given multiple tags' do
+ it 'returns the expected statuses' do
+ expect(Status.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to eq [status3.id, status4.id]
+ expect(Status.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status2.id, status4.id]
+ expect(Status.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [status1.id, status4.id]
+ end
+ end
+ end
+
describe '.permitted_for' do
subject { described_class.permitted_for(target_account, account).pluck(:visibility) }