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
16 changes: 8 additions & 8 deletions lib/closure_tree/hierarchy_maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def _ct_before_save
end

def _ct_after_save
scope_changed = _ct.order_is_numeric? && _ct.scope_changed?(self)

if saved_changes[_ct.parent_column_name] || @was_new_record
rebuild!
elsif scope_changed
# Scope changed without parent change - reorder old scope's siblings
_ct_reorder_prior_siblings_if_parent_changed
_ct_reorder_siblings
elsif _ct.order_option? && saved_changes[_ct.order_column_sym]
_ct_reorder_siblings(saved_changes[_ct.order_column_sym].min)
elsif _ct.order_is_numeric?
if _ct.scope_changed?(self)
# Scope changed without parent change - reorder old scope's siblings
_ct_reorder_prior_siblings_if_parent_changed
_ct_reorder_siblings
elsif saved_changes[_ct.order_column_sym]
_ct_reorder_siblings(saved_changes[_ct.order_column_sym].min)
end
end
if saved_changes[_ct.parent_column_name] && !@was_new_record
# Resetting the ancestral collections addresses
Expand Down
8 changes: 8 additions & 0 deletions test/closure_tree/hierarchy_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
end
end

describe '#_ct_after_save' do
it 'does not raise when updating a node with non-numeric order column' do
tag = Tag.create!(name: 'Alpha')
tag.update!(name: 'Beta')
assert_equal 'Beta', tag.reload.name
end
end

describe '.cleanup!' do
before do
@parent = Metal.create(value: 'parent metal')
Expand Down