Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ RSpec/LetSetup:
- 'spec/controllers/auth/passwords_controller_spec.rb'
- 'spec/controllers/auth/sessions_controller_spec.rb'
- 'spec/models/account_statuses_cleanup_policy_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/services/activitypub/fetch_featured_collection_service_spec.rb'

RSpec/MultipleExpectations:
Expand Down
69 changes: 51 additions & 18 deletions spec/models/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,29 @@

context 'when given one tag' 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_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)
expect(described_class.tagged_with([tag_cats.id]))
.to include(status_with_tag_cats, status_with_all_tags)
.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

context 'when given multiple tags' 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_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)
expect(described_class.tagged_with([tag_cats.id, tag_dogs.id]))
.to include(status_with_tag_cats, status_with_tag_dogs, status_with_all_tags)
.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
Expand All @@ -292,17 +304,26 @@

context 'when given one tag' 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_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)
expect(described_class.tagged_with_all([tag_cats.id]))
.to include(status_with_tag_cats, status_with_all_tags)
.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

context 'when given multiple tags' 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_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 []
expect(described_class.tagged_with_all([tag_cats.id, tag_dogs.id]))
.to include(status_with_all_tags)
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
Expand All @@ -319,17 +340,29 @@

context 'when given one tag' 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_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)
expect(described_class.tagged_with_none([tag_cats.id]))
.to include(status_with_tag_dogs, status_tagged_with_zebras, status_without_tags)
.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

context 'when given multiple tags' 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_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)
expect(described_class.tagged_with_none([tag_cats.id, tag_dogs.id]))
.to include(status_tagged_with_zebras, status_without_tags)
.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
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def sign_in(resource, _deprecated = nil, scope: nil)
end

RSpec::Matchers.define_negated_matcher :not_change, :change
RSpec::Matchers.define_negated_matcher :not_include, :include

def request_fixture(name)
Rails.root.join('spec', 'fixtures', 'requests', name).read
Expand Down