Update rubocop-rspec to version 2.22.0, fix RSpec/IndexedLet
cop (#24698)
This commit is contained in:
parent
24015ef0cc
commit
4c5aa0e470
25 changed files with 334 additions and 322 deletions
|
@ -266,10 +266,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
let!(:self_bookmarked) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:status_with_poll) { Fabricate(:status, created_at: 1.year.ago, account: account, poll_attributes: { account: account, voters_count: 0, options: %w(a b), expires_in: 2.days }) }
|
||||
let!(:status_with_media) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:faved4) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:faved5) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:reblogged4) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:reblogged5) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:faved_primary) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:faved_secondary) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:reblogged_primary) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:reblogged_secondary) { Fabricate(:status, created_at: 1.year.ago, account: account) }
|
||||
let!(:recent_status) { Fabricate(:status, created_at: 2.days.ago, account: account) }
|
||||
|
||||
let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: status_with_media) }
|
||||
|
@ -280,10 +280,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
let(:account_statuses_cleanup_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) }
|
||||
|
||||
before do
|
||||
4.times { faved4.increment_count!(:favourites_count) }
|
||||
5.times { faved5.increment_count!(:favourites_count) }
|
||||
4.times { reblogged4.increment_count!(:reblogs_count) }
|
||||
5.times { reblogged5.increment_count!(:reblogs_count) }
|
||||
4.times { faved_primary.increment_count!(:favourites_count) }
|
||||
5.times { faved_secondary.increment_count!(:favourites_count) }
|
||||
4.times { reblogged_primary.increment_count!(:reblogs_count) }
|
||||
5.times { reblogged_secondary.increment_count!(:reblogs_count) }
|
||||
end
|
||||
|
||||
context 'when passed a max_id' do
|
||||
|
@ -359,7 +359,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -378,7 +378,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, status_with_poll.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -397,7 +397,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -416,7 +416,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -435,7 +435,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -454,7 +454,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -477,7 +477,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns every other old status for deletion' do
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -496,7 +496,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns only normal statuses for deletion' do
|
||||
expect(subject.pluck(:id)).to contain_exactly(very_old_status.id, faved4.id, faved5.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to contain_exactly(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -510,7 +510,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'does not return the toot reblogged 5 times' do
|
||||
expect(subject.pluck(:id)).to_not include(reblogged5.id)
|
||||
expect(subject.pluck(:id)).to_not include(reblogged_secondary.id)
|
||||
end
|
||||
|
||||
it 'does not return the unrelated toot' do
|
||||
|
@ -518,7 +518,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns old statuses not reblogged as much' do
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, faved4.id, faved5.id, reblogged4.id)
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -532,7 +532,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'does not return the toot faved 5 times' do
|
||||
expect(subject.pluck(:id)).to_not include(faved5.id)
|
||||
expect(subject.pluck(:id)).to_not include(faved_secondary.id)
|
||||
end
|
||||
|
||||
it 'does not return the unrelated toot' do
|
||||
|
@ -540,7 +540,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
it 'returns old statuses not faved as much' do
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, faved4.id, reblogged4.id, reblogged5.id)
|
||||
expect(subject.pluck(:id)).to include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -560,17 +560,17 @@ describe AccountInteractions do
|
|||
|
||||
describe '#remote_followers_hash' do
|
||||
let(:me) { Fabricate(:account, username: 'Me') }
|
||||
let(:remote_1) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
let(:remote_2) { Fabricate(:account, username: 'bob', domain: 'example.org', uri: 'https://example.org/users/bob') }
|
||||
let(:remote_3) { Fabricate(:account, username: 'instance-actor', domain: 'example.org', uri: 'https://example.org') }
|
||||
let(:remote_4) { Fabricate(:account, username: 'eve', domain: 'foo.org', uri: 'https://foo.org/users/eve') }
|
||||
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
let(:remote_bob) { Fabricate(:account, username: 'bob', domain: 'example.org', uri: 'https://example.org/users/bob') }
|
||||
let(:remote_instance_actor) { Fabricate(:account, username: 'instance-actor', domain: 'example.org', uri: 'https://example.org') }
|
||||
let(:remote_eve) { Fabricate(:account, username: 'eve', domain: 'foo.org', uri: 'https://foo.org/users/eve') }
|
||||
|
||||
before do
|
||||
remote_1.follow!(me)
|
||||
remote_2.follow!(me)
|
||||
remote_3.follow!(me)
|
||||
remote_4.follow!(me)
|
||||
me.follow!(remote_1)
|
||||
remote_alice.follow!(me)
|
||||
remote_bob.follow!(me)
|
||||
remote_instance_actor.follow!(me)
|
||||
remote_eve.follow!(me)
|
||||
me.follow!(remote_alice)
|
||||
end
|
||||
|
||||
it 'returns correct hash for remote domains' do
|
||||
|
@ -582,33 +582,33 @@ describe AccountInteractions do
|
|||
|
||||
it 'invalidates cache as needed when removing or adding followers' do
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
||||
remote_3.unfollow!(me)
|
||||
remote_instance_actor.unfollow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
||||
remote_1.unfollow!(me)
|
||||
remote_alice.unfollow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '241b00794ce9b46aa864f3220afadef128318da2659782985bac5ed5bd436bff'
|
||||
remote_1.follow!(me)
|
||||
remote_alice.follow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#local_followers_hash' do
|
||||
let(:me) { Fabricate(:account, username: 'Me') }
|
||||
let(:remote_1) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
|
||||
before do
|
||||
me.follow!(remote_1)
|
||||
me.follow!(remote_alice)
|
||||
end
|
||||
|
||||
it 'returns correct hash for local users' do
|
||||
expect(remote_1.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
end
|
||||
|
||||
it 'invalidates cache as needed when removing or adding followers' do
|
||||
expect(remote_1.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
me.unfollow!(remote_1)
|
||||
expect(remote_1.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
me.follow!(remote_1)
|
||||
expect(remote_1.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
me.unfollow!(remote_alice)
|
||||
expect(remote_alice.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
me.follow!(remote_alice)
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,40 +8,40 @@ describe StatusThreadingConcern do
|
|||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
||||
let!(:jeff) { Fabricate(:account, username: 'jeff') }
|
||||
let!(:status) { Fabricate(:status, account: alice) }
|
||||
let!(:reply1) { Fabricate(:status, thread: status, account: jeff) }
|
||||
let!(:reply2) { Fabricate(:status, thread: reply1, account: bob) }
|
||||
let!(:reply3) { Fabricate(:status, thread: reply2, account: alice) }
|
||||
let!(:reply_to_status) { Fabricate(:status, thread: status, account: jeff) }
|
||||
let!(:reply_to_first_reply) { Fabricate(:status, thread: reply_to_status, account: bob) }
|
||||
let!(:reply_to_second_reply) { Fabricate(:status, thread: reply_to_first_reply, account: alice) }
|
||||
let!(:viewer) { Fabricate(:account, username: 'viewer') }
|
||||
|
||||
it 'returns conversation history' do
|
||||
expect(reply3.ancestors(4)).to include(status, reply1, reply2)
|
||||
expect(reply_to_second_reply.ancestors(4)).to include(status, reply_to_status, reply_to_first_reply)
|
||||
end
|
||||
|
||||
it 'does not return conversation history user is not allowed to see' do
|
||||
reply1.update(visibility: :private)
|
||||
reply_to_status.update(visibility: :private)
|
||||
status.update(visibility: :direct)
|
||||
|
||||
expect(reply3.ancestors(4, viewer)).to_not include(reply1, status)
|
||||
expect(reply_to_second_reply.ancestors(4, viewer)).to_not include(reply_to_status, status)
|
||||
end
|
||||
|
||||
it 'does not return conversation history from blocked users' do
|
||||
viewer.block!(jeff)
|
||||
expect(reply3.ancestors(4, viewer)).to_not include(reply1)
|
||||
expect(reply_to_second_reply.ancestors(4, viewer)).to_not include(reply_to_status)
|
||||
end
|
||||
|
||||
it 'does not return conversation history from muted users' do
|
||||
viewer.mute!(jeff)
|
||||
expect(reply3.ancestors(4, viewer)).to_not include(reply1)
|
||||
expect(reply_to_second_reply.ancestors(4, viewer)).to_not include(reply_to_status)
|
||||
end
|
||||
|
||||
it 'does not return conversation history from silenced and not followed users' do
|
||||
jeff.silence!
|
||||
expect(reply3.ancestors(4, viewer)).to_not include(reply1)
|
||||
expect(reply_to_second_reply.ancestors(4, viewer)).to_not include(reply_to_status)
|
||||
end
|
||||
|
||||
it 'does not return conversation history from blocked domains' do
|
||||
viewer.block_domain!('example.com')
|
||||
expect(reply3.ancestors(4, viewer)).to_not include(reply2)
|
||||
expect(reply_to_second_reply.ancestors(4, viewer)).to_not include(reply_to_first_reply)
|
||||
end
|
||||
|
||||
it 'ignores deleted records' do
|
||||
|
@ -83,40 +83,40 @@ describe StatusThreadingConcern do
|
|||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
||||
let!(:jeff) { Fabricate(:account, username: 'jeff') }
|
||||
let!(:status) { Fabricate(:status, account: alice) }
|
||||
let!(:reply1) { Fabricate(:status, thread: status, account: alice) }
|
||||
let!(:reply2) { Fabricate(:status, thread: status, account: bob) }
|
||||
let!(:reply3) { Fabricate(:status, thread: reply1, account: jeff) }
|
||||
let!(:reply_to_status_from_alice) { Fabricate(:status, thread: status, account: alice) }
|
||||
let!(:reply_to_status_from_bob) { Fabricate(:status, thread: status, account: bob) }
|
||||
let!(:reply_to_alice_reply_from_jeff) { Fabricate(:status, thread: reply_to_status_from_alice, account: jeff) }
|
||||
let!(:viewer) { Fabricate(:account, username: 'viewer') }
|
||||
|
||||
it 'returns replies' do
|
||||
expect(status.descendants(4)).to include(reply1, reply2, reply3)
|
||||
expect(status.descendants(4)).to include(reply_to_status_from_alice, reply_to_status_from_bob, reply_to_alice_reply_from_jeff)
|
||||
end
|
||||
|
||||
it 'does not return replies user is not allowed to see' do
|
||||
reply1.update(visibility: :private)
|
||||
reply3.update(visibility: :direct)
|
||||
reply_to_status_from_alice.update(visibility: :private)
|
||||
reply_to_alice_reply_from_jeff.update(visibility: :direct)
|
||||
|
||||
expect(status.descendants(4, viewer)).to_not include(reply1, reply3)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply_to_status_from_alice, reply_to_alice_reply_from_jeff)
|
||||
end
|
||||
|
||||
it 'does not return replies from blocked users' do
|
||||
viewer.block!(jeff)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply3)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply_to_alice_reply_from_jeff)
|
||||
end
|
||||
|
||||
it 'does not return replies from muted users' do
|
||||
viewer.mute!(jeff)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply3)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply_to_alice_reply_from_jeff)
|
||||
end
|
||||
|
||||
it 'does not return replies from silenced and not followed users' do
|
||||
jeff.silence!
|
||||
expect(status.descendants(4, viewer)).to_not include(reply3)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply_to_alice_reply_from_jeff)
|
||||
end
|
||||
|
||||
it 'does not return replies from blocked domains' do
|
||||
viewer.block_domain!('example.com')
|
||||
expect(status.descendants(4, viewer)).to_not include(reply2)
|
||||
expect(status.descendants(4, viewer)).to_not include(reply_to_status_from_bob)
|
||||
end
|
||||
|
||||
it 'promotes self-replies to the top while leaving the rest in order' do
|
||||
|
|
|
@ -6,9 +6,9 @@ RSpec.describe CustomEmojiFilter do
|
|||
describe '#results' do
|
||||
subject { described_class.new(params).results }
|
||||
|
||||
let!(:custom_emoji_0) { Fabricate(:custom_emoji, domain: 'a') }
|
||||
let!(:custom_emoji_1) { Fabricate(:custom_emoji, domain: 'b') }
|
||||
let!(:custom_emoji_2) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') }
|
||||
let!(:custom_emoji_domain_a) { Fabricate(:custom_emoji, domain: 'a') }
|
||||
let!(:custom_emoji_domain_b) { Fabricate(:custom_emoji, domain: 'b') }
|
||||
let!(:custom_emoji_domain_nil) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') }
|
||||
|
||||
context 'when params have values' do
|
||||
context 'when local' do
|
||||
|
@ -16,7 +16,7 @@ RSpec.describe CustomEmojiFilter do
|
|||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_2)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ RSpec.describe CustomEmojiFilter do
|
|||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_0, custom_emoji_1)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_a, custom_emoji_domain_b)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ RSpec.describe CustomEmojiFilter do
|
|||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_0)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_a)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ RSpec.describe CustomEmojiFilter do
|
|||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_2)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,7 +63,7 @@ RSpec.describe CustomEmojiFilter do
|
|||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_0, custom_emoji_1, custom_emoji_2)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_a, custom_emoji_domain_b, custom_emoji_domain_nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -254,82 +254,82 @@ RSpec.describe Status do
|
|||
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]) }
|
||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
||||
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
||||
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
||||
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
||||
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
||||
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
||||
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs, tag_zebras]) }
|
||||
|
||||
context 'when given one tag' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id)
|
||||
expect(described_class.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id)
|
||||
expect(described_class.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status5.id)
|
||||
expect(described_class.tagged_with([tag_cats.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with([tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_dogs.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with([tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_tagged_with_zebras.id, status_with_all_tags.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given multiple tags' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status5.id)
|
||||
expect(described_class.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status5.id)
|
||||
expect(described_class.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status5.id)
|
||||
expect(described_class.tagged_with([tag_cats.id, tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_with_tag_dogs.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with([tag_cats.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_tagged_with_zebras.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with([tag_dogs.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_dogs.id, status_tagged_with_zebras.id, status_with_all_tags.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]) }
|
||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
||||
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
||||
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
||||
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
||||
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
||||
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
||||
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs]) }
|
||||
|
||||
context 'when given one tag' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id)
|
||||
expect(described_class.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id)
|
||||
expect(described_class.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id)
|
||||
expect(described_class.tagged_with_all([tag_cats.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with_all([tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_dogs.id, status_with_all_tags.id)
|
||||
expect(described_class.tagged_with_all([tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_tagged_with_zebras.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given multiple tags' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status5.id)
|
||||
expect(described_class.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq []
|
||||
expect(described_class.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq []
|
||||
expect(described_class.tagged_with_all([tag_cats.id, tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_all_tags.id)
|
||||
expect(described_class.tagged_with_all([tag_cats.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to eq []
|
||||
expect(described_class.tagged_with_all([tag_dogs.id, tag_zebras.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]) }
|
||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
||||
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
||||
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
||||
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
||||
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
||||
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
||||
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs, tag_zebras]) }
|
||||
|
||||
context 'when given one tag' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag_cats.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_dogs.id, status_tagged_with_zebras.id, status_without_tags.id)
|
||||
expect(described_class.tagged_with_none([tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_tagged_with_zebras.id, status_without_tags.id)
|
||||
expect(described_class.tagged_with_none([tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_with_tag_dogs.id, status_without_tags.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given multiple tags' do
|
||||
it 'returns the expected statuses' do
|
||||
expect(described_class.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status4.id)
|
||||
expect(described_class.tagged_with_none([tag_cats.id, tag_dogs.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_tagged_with_zebras.id, status_without_tags.id)
|
||||
expect(described_class.tagged_with_none([tag_cats.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_dogs.id, status_without_tags.id)
|
||||
expect(described_class.tagged_with_none([tag_dogs.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_with_tag_cats.id, status_without_tags.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,65 +5,65 @@ require 'rails_helper'
|
|||
describe TagFeed, type: :service do
|
||||
describe '#get' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:tag1) { Fabricate(:tag) }
|
||||
let(:tag2) { Fabricate(:tag) }
|
||||
let!(:status1) { Fabricate(:status, tags: [tag1]) }
|
||||
let!(:status2) { Fabricate(:status, tags: [tag2]) }
|
||||
let!(:both) { Fabricate(:status, tags: [tag1, tag2]) }
|
||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
||||
let!(:status_tagged_with_cats) { Fabricate(:status, tags: [tag_cats]) }
|
||||
let!(:status_tagged_with_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
||||
let!(:both) { Fabricate(:status, tags: [tag_cats, tag_dogs]) }
|
||||
|
||||
it 'can add tags in "any" mode' do
|
||||
results = described_class.new(tag1, nil, any: [tag2.name]).get(20)
|
||||
expect(results).to include status1
|
||||
expect(results).to include status2
|
||||
results = described_class.new(tag_cats, nil, any: [tag_dogs.name]).get(20)
|
||||
expect(results).to include status_tagged_with_cats
|
||||
expect(results).to include status_tagged_with_dogs
|
||||
expect(results).to include both
|
||||
end
|
||||
|
||||
it 'can remove tags in "all" mode' do
|
||||
results = described_class.new(tag1, nil, all: [tag2.name]).get(20)
|
||||
expect(results).to_not include status1
|
||||
expect(results).to_not include status2
|
||||
results = described_class.new(tag_cats, nil, all: [tag_dogs.name]).get(20)
|
||||
expect(results).to_not include status_tagged_with_cats
|
||||
expect(results).to_not include status_tagged_with_dogs
|
||||
expect(results).to include both
|
||||
end
|
||||
|
||||
it 'can remove tags in "none" mode' do
|
||||
results = described_class.new(tag1, nil, none: [tag2.name]).get(20)
|
||||
expect(results).to include status1
|
||||
expect(results).to_not include status2
|
||||
results = described_class.new(tag_cats, nil, none: [tag_dogs.name]).get(20)
|
||||
expect(results).to include status_tagged_with_cats
|
||||
expect(results).to_not include status_tagged_with_dogs
|
||||
expect(results).to_not include both
|
||||
end
|
||||
|
||||
it 'ignores an invalid mode' do
|
||||
results = described_class.new(tag1, nil, wark: [tag2.name]).get(20)
|
||||
expect(results).to include status1
|
||||
expect(results).to_not include status2
|
||||
results = described_class.new(tag_cats, nil, wark: [tag_dogs.name]).get(20)
|
||||
expect(results).to include status_tagged_with_cats
|
||||
expect(results).to_not include status_tagged_with_dogs
|
||||
expect(results).to include both
|
||||
end
|
||||
|
||||
it 'handles being passed non existent tag names' do
|
||||
results = described_class.new(tag1, nil, any: ['wark']).get(20)
|
||||
expect(results).to include status1
|
||||
expect(results).to_not include status2
|
||||
results = described_class.new(tag_cats, nil, any: ['wark']).get(20)
|
||||
expect(results).to include status_tagged_with_cats
|
||||
expect(results).to_not include status_tagged_with_dogs
|
||||
expect(results).to include both
|
||||
end
|
||||
|
||||
it 'can restrict to an account' do
|
||||
BlockService.new.call(account, status1.account)
|
||||
results = described_class.new(tag1, account, none: [tag2.name]).get(20)
|
||||
expect(results).to_not include status1
|
||||
BlockService.new.call(account, status_tagged_with_cats.account)
|
||||
results = described_class.new(tag_cats, account, none: [tag_dogs.name]).get(20)
|
||||
expect(results).to_not include status_tagged_with_cats
|
||||
end
|
||||
|
||||
it 'can restrict to local' do
|
||||
status1.account.update(domain: 'example.com')
|
||||
status1.update(local: false, uri: 'example.com/toot')
|
||||
results = described_class.new(tag1, nil, any: [tag2.name], local: true).get(20)
|
||||
expect(results).to_not include status1
|
||||
status_tagged_with_cats.account.update(domain: 'example.com')
|
||||
status_tagged_with_cats.update(local: false, uri: 'example.com/toot')
|
||||
results = described_class.new(tag_cats, nil, any: [tag_dogs.name], local: true).get(20)
|
||||
expect(results).to_not include status_tagged_with_cats
|
||||
end
|
||||
|
||||
it 'allows replies to be included' do
|
||||
original = Fabricate(:status)
|
||||
status = Fabricate(:status, tags: [tag1], in_reply_to_id: original.id)
|
||||
status = Fabricate(:status, tags: [tag_cats], in_reply_to_id: original.id)
|
||||
|
||||
results = described_class.new(tag1, nil).get(20)
|
||||
results = described_class.new(tag_cats, nil).get(20)
|
||||
expect(results).to include(status)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,12 +11,12 @@ RSpec.describe Trends::Statuses do
|
|||
let!(:query) { subject.query }
|
||||
let!(:today) { at_time }
|
||||
|
||||
let!(:status1) { Fabricate(:status, text: 'Foo', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status2) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status_foo) { Fabricate(:status, text: 'Foo', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status_bar) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) }
|
||||
|
||||
before do
|
||||
default_threshold_value.times { reblog(status1, today) }
|
||||
default_threshold_value.times { reblog(status2, today) }
|
||||
default_threshold_value.times { reblog(status_foo, today) }
|
||||
default_threshold_value.times { reblog(status_bar, today) }
|
||||
|
||||
subject.refresh(today)
|
||||
end
|
||||
|
@ -29,18 +29,18 @@ RSpec.describe Trends::Statuses do
|
|||
end
|
||||
|
||||
it 'filters out blocked accounts' do
|
||||
account.block!(status1.account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status2]
|
||||
account.block!(status_foo.account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status_bar]
|
||||
end
|
||||
|
||||
it 'filters out muted accounts' do
|
||||
account.mute!(status2.account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status1]
|
||||
account.mute!(status_bar.account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status_foo]
|
||||
end
|
||||
|
||||
it 'filters out blocked-by accounts' do
|
||||
status1.account.block!(account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status2]
|
||||
status_foo.account.block!(account)
|
||||
expect(query.filtered_for(account).to_a).to eq [status_bar]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,14 +71,14 @@ RSpec.describe Trends::Statuses do
|
|||
let!(:today) { at_time }
|
||||
let!(:yesterday) { today - 1.day }
|
||||
|
||||
let!(:status1) { Fabricate(:status, text: 'Foo', language: 'en', trendable: true, created_at: yesterday) }
|
||||
let!(:status2) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status3) { Fabricate(:status, text: 'Baz', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status_foo) { Fabricate(:status, text: 'Foo', language: 'en', trendable: true, created_at: yesterday) }
|
||||
let!(:status_bar) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) }
|
||||
let!(:status_baz) { Fabricate(:status, text: 'Baz', language: 'en', trendable: true, created_at: today) }
|
||||
|
||||
before do
|
||||
default_threshold_value.times { reblog(status1, today) }
|
||||
default_threshold_value.times { reblog(status2, today) }
|
||||
(default_threshold_value - 1).times { reblog(status3, today) }
|
||||
default_threshold_value.times { reblog(status_foo, today) }
|
||||
default_threshold_value.times { reblog(status_bar, today) }
|
||||
(default_threshold_value - 1).times { reblog(status_baz, today) }
|
||||
end
|
||||
|
||||
context 'when status trends are refreshed' do
|
||||
|
@ -89,17 +89,17 @@ RSpec.describe Trends::Statuses do
|
|||
it 'returns correct statuses from query' do
|
||||
results = subject.query.limit(10).to_a
|
||||
|
||||
expect(results).to eq [status2, status1]
|
||||
expect(results).to_not include(status3)
|
||||
expect(results).to eq [status_bar, status_foo]
|
||||
expect(results).to_not include(status_baz)
|
||||
end
|
||||
end
|
||||
|
||||
it 'decays scores' do
|
||||
subject.refresh(today)
|
||||
original_score = status2.trend.score
|
||||
original_score = status_bar.trend.score
|
||||
expect(original_score).to be_a Float
|
||||
subject.refresh(today + subject.options[:score_halflife])
|
||||
decayed_score = status2.trend.reload.score
|
||||
decayed_score = status_bar.trend.reload.score
|
||||
expect(decayed_score).to be <= original_score / 2
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,15 +33,15 @@ RSpec.describe Trends::Tags do
|
|||
let!(:today) { at_time }
|
||||
let!(:yesterday) { today - 1.day }
|
||||
|
||||
let!(:tag1) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
|
||||
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
|
||||
let!(:tag3) { Fabricate(:tag, name: 'OCs', trendable: true) }
|
||||
let!(:tag_cats) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
|
||||
let!(:tag_dogs) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
|
||||
let!(:tag_ocs) { Fabricate(:tag, name: 'OCs', trendable: true) }
|
||||
|
||||
before do
|
||||
2.times { |i| subject.add(tag1, i, yesterday) }
|
||||
13.times { |i| subject.add(tag3, i, yesterday) }
|
||||
16.times { |i| subject.add(tag1, i, today) }
|
||||
4.times { |i| subject.add(tag2, i, today) }
|
||||
2.times { |i| subject.add(tag_cats, i, yesterday) }
|
||||
13.times { |i| subject.add(tag_ocs, i, yesterday) }
|
||||
16.times { |i| subject.add(tag_cats, i, today) }
|
||||
4.times { |i| subject.add(tag_dogs, i, today) }
|
||||
end
|
||||
|
||||
context 'when tag trends are refreshed' do
|
||||
|
@ -51,20 +51,20 @@ RSpec.describe Trends::Tags do
|
|||
end
|
||||
|
||||
it 'calculates and re-calculates scores' do
|
||||
expect(subject.query.limit(10).to_a).to eq [tag1, tag3]
|
||||
expect(subject.query.limit(10).to_a).to eq [tag_cats, tag_ocs]
|
||||
end
|
||||
|
||||
it 'omits hashtags below threshold' do
|
||||
expect(subject.query.limit(10).to_a).to_not include(tag2)
|
||||
expect(subject.query.limit(10).to_a).to_not include(tag_dogs)
|
||||
end
|
||||
end
|
||||
|
||||
it 'decays scores' do
|
||||
subject.refresh(yesterday + 12.hours)
|
||||
original_score = subject.score(tag3.id)
|
||||
original_score = subject.score(tag_ocs.id)
|
||||
expect(original_score).to eq 144.0
|
||||
subject.refresh(yesterday + 12.hours + subject.options[:max_score_halflife])
|
||||
decayed_score = subject.score(tag3.id)
|
||||
decayed_score = subject.score(tag_ocs.id)
|
||||
expect(decayed_score).to be <= original_score / 2
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue