diff options
author | Matt Jankowski <matt@jankowski.online> | 2023-06-14 10:44:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 16:44:37 +0200 |
commit | 4c5aa0e470fb92f8f9a5521357f2cf59263a49b5 (patch) | |
tree | dda7aedf6aefdbec4d71e1756a472e26f9157634 /spec/models | |
parent | 24015ef0cc84e7caffc4c02b9b7d5cdbdeb80002 (diff) |
Update rubocop-rspec to version 2.22.0, fix `RSpec/IndexedLet` cop (#24698)
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/account_statuses_cleanup_policy_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/concerns/account_interactions_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/concerns/status_threading_concern_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/custom_emoji_filter_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/status_spec.rb | 84 | ||||
-rw-r--r-- | spec/models/tag_feed_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/trends/statuses_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/trends/tags_spec.rb | 22 |
8 files changed, 171 insertions, 171 deletions
diff --git a/spec/models/account_statuses_cleanup_policy_spec.rb b/spec/models/account_statuses_cleanup_policy_spec.rb index 391b99ff47a..7405bdfa2d7 100644 --- a/spec/models/account_statuses_cleanup_policy_spec.rb +++ b/spec/models/account_statuses_cleanup_policy_spec.rb @@ -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 diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb index dc03aad7d4a..84e2c91a85d 100644 --- a/spec/models/concerns/account_interactions_spec.rb +++ b/spec/models/concerns/account_interactions_spec.rb @@ -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 diff --git a/spec/models/concerns/status_threading_concern_spec.rb b/spec/models/concerns/status_threading_concern_spec.rb index 50286ef77b9..2eac1ca6e5c 100644 --- a/spec/models/concerns/status_threading_concern_spec.rb +++ b/spec/models/concerns/status_threading_concern_spec.rb @@ -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 diff --git a/spec/models/custom_emoji_filter_spec.rb b/spec/models/custom_emoji_filter_spec.rb index d8a2bea6b8a..c36fecd60d4 100644 --- a/spec/models/custom_emoji_filter_spec.rb +++ b/spec/models/custom_emoji_filter_spec.rb @@ -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 diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 3141c52c057..8c37b1accc3 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -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 descr |