Fix UnitsiTest#test_index

This commit is contained in:
cryptogopher 2024-12-09 20:00:14 +01:00
parent 40808639cc
commit f3f0b9dc9e
2 changed files with 3 additions and 2 deletions

View File

@ -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

View File

@ -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