From f3f0b9dc9e24a182dca5a812694c238643e62646 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Mon, 9 Dec 2024 20:00:14 +0100 Subject: [PATCH] Fix UnitsiTest#test_index --- app/models/unit.rb | 2 +- test/system/units_test.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/unit.rb b/app/models/unit.rb index d10de22..c4445b2 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -3,7 +3,7 @@ class Unit < ApplicationRecord belongs_to :user, optional: true belongs_to :base, optional: true, class_name: "Unit" - has_many :subunits, class_name: "Unit", dependent: :restrict_with_error, inverse_of: :base + has_many :subunits, class_name: "Unit", inverse_of: :base, dependent: :restrict_with_error validate if: ->{ base.present? } do errors.add(:base, :user_mismatch) unless user == base.user diff --git a/test/system/units_test.rb b/test/system/units_test.rb index 67d415b..a67a629 100644 --- a/test/system/units_test.rb +++ b/test/system/units_test.rb @@ -12,7 +12,8 @@ class UnitsTest < ApplicationSystemTestCase assert_selector 'tr', count: @user.units.count end - Unit.destroy_all + # Cannot #destroy_all due to {dependent: :restrict*} on Unit.subunits association + @user.units.delete_all visit units_path within 'tbody' do assert_selector 'tr', count: 1