From aed33620ba7518cab144f41c7f826dcadfe4d656 Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Fri, 13 Dec 2024 18:51:22 -0600 Subject: [PATCH] Reapply "Destroy equivalent filters upon resource removal" This reverts commit 5e09fddbe01e50e6678722ae8b76f030f7966201. --- app/models/filter/resources.rb | 2 ++ test/models/filter_test.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/models/filter/resources.rb b/app/models/filter/resources.rb index 85950f857..bde1a30d1 100644 --- a/app/models/filter/resources.rb +++ b/app/models/filter/resources.rb @@ -12,6 +12,8 @@ module Filter::Resources kind = resource.class.model_name.plural send "#{kind}=", send(kind).without(resource) empty? ? destroy! : save! + rescue ActiveRecord::RecordNotUnique + destroy! end def buckets diff --git a/test/models/filter_test.rb b/test/models/filter_test.rb index 6d871326c..7635d0ff7 100644 --- a/test/models/filter_test.rb +++ b/test/models/filter_test.rb @@ -89,6 +89,11 @@ class FilterTest < ActiveSupport::TestCase assert_includes filter.as_params[:bucket_ids], buckets(:writebook).id assert_includes filter.buckets, buckets(:writebook) + users(:david).filters.create! tag_ids: [ tags(:mobile).id, tags(:web).id ], bucket_ids: [ buckets(:writebook).id ] + assert_difference "Filter.count", -1 do + tags(:web).destroy! + end + assert_changes "filter.reload.updated_at" do tags(:mobile).destroy! end