From 7a6c659ad8015fa006969b360051ddf24d4604ab Mon Sep 17 00:00:00 2001 From: Theodor Tonum Date: Mon, 27 May 2024 20:42:36 +0200 Subject: [PATCH] Support Rails 7.2 normalized reflections API See https://github.com/rails/rails/pull/51726 --- .../active_record/have_attached_matcher_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/unit/shoulda/matchers/active_record/have_attached_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_attached_matcher_spec.rb index 3b3fec53a..2f45e23e0 100644 --- a/spec/unit/shoulda/matchers/active_record/have_attached_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_attached_matcher_spec.rb @@ -185,7 +185,13 @@ def record_having_one_attached( end if remove_attachments - reflections.delete("#{attached_name}_attachment") + if respond_to?(:normalized_reflections) + clear_reflections_cache + _reflections.delete("#{attached_name}_attachment".to_sym) + normalized_reflections + else + reflections.delete("#{attached_name}_attachment") + end end if invalidate_blobs @@ -223,7 +229,13 @@ def record_having_many_attached( end if remove_attachments - reflections.delete("#{attached_name}_attachments") + if respond_to?(:normalized_reflections) + clear_reflections_cache + _reflections.delete("#{attached_name}_attachments".to_sym) + normalized_reflections + else + reflections.delete("#{attached_name}_attachments") + end end if invalidate_blobs