Cascade mute/block destruction to notes (#193)

This commit is contained in:
David Yip 2018-01-27 01:31:22 -06:00
parent 2ce4af84e9
commit 1b3ff6a92f
No known key found for this signature in database
GPG Key ID: 7DA0036508FCC0CC
4 changed files with 19 additions and 2 deletions

View File

@ -21,7 +21,7 @@ class Block < ApplicationRecord
after_create :remove_blocking_cache
after_destroy :remove_blocking_cache
has_one :note, class_name: 'Glitch::Note', as: :target
has_one :note, class_name: 'Glitch::Note', as: :target, dependent: :destroy
private

View File

@ -22,7 +22,7 @@ class Mute < ApplicationRecord
after_create :remove_blocking_cache
after_destroy :remove_blocking_cache
has_one :note, class_name: 'Glitch::Note', as: :target
has_one :note, class_name: 'Glitch::Note', as: :target, dependent: :destroy
private

View File

@ -44,4 +44,12 @@ RSpec.describe Block, type: :model do
expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to eq false
expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to eq false
end
it 'removes associated note after destruction' do
block = Fabricate(:block)
block.create_note!(note: 'Too many oats')
block.destroy!
expect(Glitch::Note.count).to eq(0)
end
end

View File

@ -1,5 +1,14 @@
require 'rails_helper'
RSpec.describe Mute, type: :model do
subject { Fabricate(:mute) }
describe '#destroy' do
it 'destroys associated notes' do
subject.create_note!(note: 'Too many jorts')
subject.destroy!
expect(Glitch::Note.count).to eq(0)
end
end
end