Skip to content

Commit

Permalink
Test: アカウント削除時のブックマーク・スタンプなど削除のテスト (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Nov 11, 2023
1 parent 878936d commit 2753d44
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ RSpec/MultipleExpectations:
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 21
Exclude:
- 'spec/services/delete_account_service_spec.rb'

# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/account_associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module AccountAssociations

has_many :report_notes, dependent: :destroy
has_many :custom_filters, inverse_of: :account, dependent: :destroy
has_many :antennas, inverse_of: :account, dependent: :destroy
has_many :antenna_accounts, inverse_of: :account, dependent: :destroy

# Moderation notes
Expand Down
5 changes: 5 additions & 0 deletions app/services/delete_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class DeleteAccountService < BaseService
antennas
block_relationships
blocked_by_relationships
bookmark_categories
circles
conversation_mutes
conversations
custom_filters
Expand Down Expand Up @@ -39,6 +41,8 @@ class DeleteAccountService < BaseService
account_notes
account_pins
aliases
antenna_accounts
circle_accounts
conversation_mutes
conversations
custom_filters
Expand Down Expand Up @@ -225,6 +229,7 @@ def purge_feeds!

FeedManager.instance.clean_feeds!(:home, [@account.id])
FeedManager.instance.clean_feeds!(:list, @account.owned_lists.pluck(:id))
FeedManager.instance.clean_feeds!(:antenna, @account.antennas.pluck(:id))
end

def purge_profile!
Expand Down
6 changes: 6 additions & 0 deletions spec/fabricators/bookmark_category_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

Fabricator(:bookmark_category) do
account { Fabricate.build(:account) }
title 'MyString'
end
9 changes: 9 additions & 0 deletions spec/fabricators/bookmark_category_status_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

Fabricator(:bookmark_category_status) do
bookmark_category
status
before_create do |_bookmark_category_status, _|
Bookmark.create!(status: status, account: bookmark_category.account) unless bookmark_category.account.bookmarked?(status)
end
end
46 changes: 43 additions & 3 deletions spec/services/delete_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
shared_examples 'common behavior' do
subject { described_class.new.call(account) }

before do
account.follow!(list_target_account)
circle_target_account.follow!(account)
end

let!(:status) { Fabricate(:status, account: account) }
let!(:mention) { Fabricate(:mention, account: local_follower) }
let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) }
let!(:media_attachment) { Fabricate(:media_attachment, account: account) }
let!(:notification) { Fabricate(:notification, account: account) }
let!(:favourite) { Fabricate(:favourite, account: account, status: Fabricate(:status, account: local_follower)) }
let!(:emoji_reaction) { Fabricate(:emoji_reaction, account: account, status: Fabricate(:status, account: local_follower)) }
let!(:bookmark) { Fabricate(:bookmark, account: account) }
let!(:poll) { Fabricate(:poll, account: account) }
let!(:poll_vote) { Fabricate(:poll_vote, account: local_follower, poll: poll) }

Expand All @@ -23,8 +30,21 @@
let!(:status_notification) { Fabricate(:notification, account: local_follower, activity: status, type: :status) }
let!(:poll_notification) { Fabricate(:notification, account: local_follower, activity: poll, type: :poll) }
let!(:favourite_notification) { Fabricate(:notification, account: local_follower, activity: favourite, type: :favourite) }
let!(:emoji_reaction_notification) { Fabricate(:notification, account: local_follower, activity: emoji_reaction, type: :emoji_reaction) }
let!(:follow_notification) { Fabricate(:notification, account: local_follower, activity: active_relationship, type: :follow) }

let!(:list) { Fabricate(:list, account: account) }
let!(:list_account) { Fabricate(:list_account, list: list, account: list_target_account) }
let!(:list_target_account) { Fabricate(:account) }
let!(:antenna) { Fabricate(:antenna, account: account) }
let!(:antenna_account) { Fabricate(:antenna_account, antenna: antenna, account: list_target_account) }
let!(:circle) { Fabricate(:circle, account: account) }
let!(:circle_account) { Fabricate(:circle_account, circle: circle, account: circle_target_account) }
let!(:circle_target_account) { Fabricate(:account) }
let!(:circle_status) { Fabricate(:circle_status, circle: circle, status: Fabricate(:status, account: account, visibility: :limited)) }
let!(:bookmark_category) { Fabricate(:bookmark_category, account: account) }
let!(:bookmark_category_status) { Fabricate(:bookmark_category_status, bookmark_category: bookmark_category, status: bookmark.status) }

let!(:account_note) { Fabricate(:account_note, account: account) }

it 'deletes associated owned records' do
Expand All @@ -34,12 +54,32 @@
account.media_attachments,
account.notifications,
account.favourites,
account.emoji_reactions,
account.bookmarks,
account.active_relationships,
account.passive_relationships,
account.polls,
account.account_notes,
].map(&:count)
}.from([2, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
}.from([3, 1, 1, 1, 1, 1, 2, 2, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
end

it 'deletes associated owned record groups' do
expect { subject }.to change {
[
account.owned_lists,
account.antennas,
account.circles,
account.bookmark_categories,
].map(&:count)
}.from([1, 1, 1, 1]).to([0, 0, 0, 0])
expect { bookmark_category_status.status.reload }.to_not raise_error
expect { antenna_account.account.reload }.to_not raise_error
expect { circle_account.account.reload }.to_not raise_error
expect { antenna_account.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { circle_account.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { circle_status.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { bookmark_category_status.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it 'deletes associated target records' do
Expand All @@ -53,9 +93,9 @@
it 'deletes associated target notifications' do
expect { subject }.to change {
%w(
poll favourite status mention follow
poll favourite emoji_reaction status mention follow
).map { |type| Notification.where(type: type).count }
}.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0])
}.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
end
end

Expand Down

0 comments on commit 2753d44

Please sign in to comment.