Clean up `tagged_with_*` Status specs, fix `RSpec/LetSetup` cop (#28462)

main
Matt Jankowski 2023-12-22 03:32:27 -05:00 committed by GitHub
parent 513d35969e
commit e6e217fedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 19 deletions

View File

@ -48,7 +48,6 @@ RSpec/ExampleLength:
RSpec/LetSetup: RSpec/LetSetup:
Exclude: Exclude:
- 'spec/models/account_statuses_cleanup_policy_spec.rb' - 'spec/models/account_statuses_cleanup_policy_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/services/activitypub/fetch_featured_collection_service_spec.rb' - 'spec/services/activitypub/fetch_featured_collection_service_spec.rb'
RSpec/MultipleExpectations: RSpec/MultipleExpectations:

View File

@ -265,17 +265,29 @@ RSpec.describe Status do
context 'when given one tag' do context 'when given one tag' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_cats.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) .to include(status_with_tag_cats, status_with_all_tags)
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) .and not_include(status_without_tags)
expect(described_class.tagged_with([tag_dogs.id]))
.to include(status_with_tag_dogs, status_with_all_tags)
.and not_include(status_without_tags)
expect(described_class.tagged_with([tag_zebras.id]))
.to include(status_tagged_with_zebras, status_with_all_tags)
.and not_include(status_without_tags)
end end
end end
context 'when given multiple tags' do context 'when given multiple tags' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_dogs.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) .to include(status_with_tag_cats, status_with_tag_dogs, status_with_all_tags)
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) .and not_include(status_without_tags)
expect(described_class.tagged_with([tag_cats.id, tag_zebras.id]))
.to include(status_with_tag_cats, status_tagged_with_zebras, status_with_all_tags)
.and not_include(status_without_tags)
expect(described_class.tagged_with([tag_dogs.id, tag_zebras.id]))
.to include(status_with_tag_dogs, status_tagged_with_zebras, status_with_all_tags)
.and not_include(status_without_tags)
end end
end end
end end
@ -292,17 +304,26 @@ RSpec.describe Status do
context 'when given one tag' do context 'when given one tag' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_cats.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) .to include(status_with_tag_cats, status_with_all_tags)
expect(described_class.tagged_with_all([tag_zebras.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status_tagged_with_zebras.id) .and not_include(status_without_tags)
expect(described_class.tagged_with_all([tag_dogs.id]))
.to include(status_with_tag_dogs, status_with_all_tags)
.and not_include(status_without_tags)
expect(described_class.tagged_with_all([tag_zebras.id]))
.to include(status_tagged_with_zebras)
.and not_include(status_without_tags)
end end
end end
context 'when given multiple tags' do context 'when given multiple tags' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_dogs.id]))
expect(described_class.tagged_with_all([tag_cats.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to eq [] .to include(status_with_all_tags)
expect(described_class.tagged_with_all([tag_dogs.id, tag_zebras.id]).reorder(:id).pluck(:id).uniq).to eq [] expect(described_class.tagged_with_all([tag_cats.id, tag_zebras.id]))
.to eq []
expect(described_class.tagged_with_all([tag_dogs.id, tag_zebras.id]))
.to eq []
end end
end end
end end
@ -319,17 +340,29 @@ RSpec.describe Status do
context 'when given one tag' do context 'when given one tag' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_cats.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) .to include(status_with_tag_dogs, status_tagged_with_zebras, status_without_tags)
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) .and not_include(status_with_all_tags)
expect(described_class.tagged_with_none([tag_dogs.id]))
.to include(status_with_tag_cats, status_tagged_with_zebras, status_without_tags)
.and not_include(status_with_all_tags)
expect(described_class.tagged_with_none([tag_zebras.id]))
.to include(status_with_tag_cats, status_with_tag_dogs, status_without_tags)
.and not_include(status_with_all_tags)
end end
end end
context 'when given multiple tags' do context 'when given multiple tags' do
it 'returns the expected statuses' do it 'returns the expected statuses' do
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_dogs.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) .to include(status_tagged_with_zebras, status_without_tags)
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) .and not_include(status_with_all_tags)
expect(described_class.tagged_with_none([tag_cats.id, tag_zebras.id]))
.to include(status_with_tag_dogs, status_without_tags)
.and not_include(status_with_all_tags)
expect(described_class.tagged_with_none([tag_dogs.id, tag_zebras.id]))
.to include(status_with_tag_cats, status_without_tags)
.and not_include(status_with_all_tags)
end end
end end
end end

View File

@ -153,6 +153,7 @@ RSpec::Sidekiq.configure do |config|
end end
RSpec::Matchers.define_negated_matcher :not_change, :change RSpec::Matchers.define_negated_matcher :not_change, :change
RSpec::Matchers.define_negated_matcher :not_include, :include
def request_fixture(name) def request_fixture(name)
Rails.root.join('spec', 'fixtures', 'requests', name).read Rails.root.join('spec', 'fixtures', 'requests', name).read