Destroy dependent notifications of a collection (#39429)
This commit is contained in:
parent
fcf222246a
commit
dc53b0e077
@ -33,6 +33,7 @@ class Collection < ApplicationRecord
|
||||
has_many :accepted_collection_items, -> { accepted }, class_name: 'CollectionItem', inverse_of: :collection # rubocop:disable Rails/HasManyOrHasOneDependent
|
||||
has_many :collection_reports, dependent: :delete_all
|
||||
has_many :accounts, -> { merge(CollectionItem.pending_or_accepted) }, through: :collection_items
|
||||
has_many :notifications, as: :activity, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
validates :name, length: { maximum: 40 }, if: :local?
|
||||
|
||||
@ -136,7 +136,7 @@ class Notification < ApplicationRecord
|
||||
belongs_to :generated_annual_report, inverse_of: false
|
||||
belongs_to :quote, inverse_of: :notification
|
||||
belongs_to :collection_item, inverse_of: false # TODO: have an inverse?
|
||||
belongs_to :collection, inverse_of: false # TODO: have an inverse?
|
||||
belongs_to :collection, inverse_of: :notifications
|
||||
end
|
||||
|
||||
validates :type, inclusion: { in: TYPES }
|
||||
|
||||
@ -221,4 +221,19 @@ RSpec.describe Collection do
|
||||
expect(subject.to_log_permalink).to eq ActivityPub::TagManager.instance.uri_for(subject)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let(:collection) { Fabricate(:collection) }
|
||||
|
||||
before do
|
||||
Fabricate(:notification, activity: collection, type: :added_to_collection)
|
||||
Fabricate(:notification, activity: collection, type: :collection_update)
|
||||
end
|
||||
|
||||
it 'removes the collection and all notifications that reference it' do
|
||||
expect { collection.destroy }
|
||||
.to change(described_class, :count).by(-1)
|
||||
.and change(Notification, :count).by(-2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user