Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/ancestry/instance_methods_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def ancestry_changed?
end

def sane_ancestor_ids?
current_context, self.validation_context = validation_context, nil
errors.clear

ancestry_value = read_attribute(:#{column})
Expand All @@ -111,8 +110,6 @@ def sane_ancestor_ids?
end
ancestry_exclude_self
errors.none?
ensure
self.validation_context = current_context
end

# Navigation
Expand Down
19 changes: 19 additions & 0 deletions test/concerns/integrity_checking_and_restoration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ def test_integrity_checking
end
end

def test_sane_ancestor_ids_does_not_rely_on_validation_context_writer
# Regression test for https://github.com/stefankroes/ancestry/issues/766:
# Rails main removed the private validation_context= writer that
# sane_ancestor_ids? used to save/restore around direct validator calls.
# Simulate that removal on a single instance and confirm the integrity
# check still runs without touching that writer at all.
AncestryTestDatabase.with_model :width => 2, :depth => 2 do |model, _roots|
instance = model.first

instance.define_singleton_method(:validation_context=) do |*_args|
raise NoMethodError, "validation_context= is not available (simulating Rails main)"
end

assert_nothing_raised do
assert instance.sane_ancestor_ids?
end
end
end

def test_integrity_checking_echo
# ltree and array columns reject invalid values at the DB level (type constraint)
skip "DB enforces column type" if AncestryTestDatabase.ltree? || AncestryTestDatabase.array?
Expand Down
Loading