1
0

Test pass: test_update_add_and_simultaneously_remove_persisted_duplicate

Replace option[selected] with option:checked
Fix target validation when threshold destroyed
Extract #fill_threshold in tests
This commit is contained in:
cryptogopher
2021-04-26 15:29:04 +02:00
parent 788dbc67c1
commit a210ccc661
2 changed files with 51 additions and 21 deletions

View File

@@ -9,9 +9,9 @@ class Target < ActiveRecord::Base
validates :thresholds, presence: true
accepts_nested_attributes_for :thresholds, allow_destroy: true,
reject_if: proc { |attrs| attrs['quantity_id'].blank? && attrs['value'].blank? }
reject_if: proc { |attrs| attrs['quantity_id'].blank? && attrs['id'].blank? }
validate do
quantities = thresholds.map(&:quantity)
quantities = thresholds.reject(&:marked_for_destruction?).map(&:quantity)
ancestors = quantities.max_by(&:lft).self_and_ancestors
errors.add(:thresholds, :count_mismatch) unless quantities.length == ancestors.length
errors.add(:thresholds, :quantity_mismatch) unless quantities == ancestors