docbrown/spec/services/users/delete_podcasts_spec.rb
Jeremy Friesen 0ef5bc6351
Ensuring we delete podcasts when we banish a user (#18063)
Prior to this commit, we may have left lingering podcast entries that
required manual cleanup.  As a bonus, I also added deleting podcasts
when we delete users.

Closes forem/forem#18041

In addition I adjusted rubocop to not complain about the require method call

```
spec/services/users/delete_spec.rb:1:1: C: \
  Style/TopLevelMethodDefinition: \
  Do not define methods at the top-level. \
  (https://rubystyle.guide#top-level-methods)
require "rails_helper"
^^^^^^^^^^^^^^^^^^^^^^
```
2022-07-12 09:18:06 -04:00

35 lines
1,002 B
Ruby

require "rails_helper"
RSpec.describe Users::DeletePodcasts do
let!(:user) { create(:user) }
let!(:podcast) { create(:podcast, creator: user) }
before do
create(:podcast_ownership, owner: user, podcast: podcast)
end
context "when podcast is owned by multiple users" do
before do
other_user = create(:user)
create(:podcast_ownership, owner: other_user, podcast: podcast)
end
it "only removes ownership from the given user", :aggregate_failures do
expect do
expect do
described_class.call(user)
end.not_to change(Podcast, :count)
end.to change(PodcastOwnership, :count).by(-1)
end
end
context "when podcast is owned by one user" do
it "removes ownership from the given user and deletes the podcast", :aggregate_failures do
expect do
expect do
described_class.call(user)
end.to change(Podcast, :count).by(-1)
end.to change(PodcastOwnership, :count).by(-1)
end
end
end