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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

- Fix the healer not locking scopes without a `belongs_to` association (or with a nil one).
- Don't write anything when an assigned position doesn't change. `updated_at` is no longer bumped and `saved_change_to_position?` is false in that case.

## [0.4.7] - 2025-08-09

Expand Down
7 changes: 7 additions & 0 deletions lib/positioning/mechanisms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def update_position
clear_position if positioning_scope_changed? && !position_changed?

solidify_position

# Assigning the position a record already has (e.g. a form resubmitting it) moves nothing
if !positioning_scope_changed? && position == position_was
@positioned.clear_attribute_changes [@column]
return
end

move_out_of_the_way

if positioning_scope_changed?
Expand Down
18 changes: 18 additions & 0 deletions test/test_positioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,24 @@ def test_that_updating_an_item_does_not_change_its_position
assert_equal [1, 2, 3], [@first_item, @second_item, @third_item].map(&:position)
end

def test_that_assigning_the_current_position_does_not_write_anything
[2, {after: @first_item}, {before: @third_item}].each do |position|
queries = []
callback = ->(*, payload) { queries << payload[:sql] }

ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
@second_item.update position: position
end

assert_empty queries.grep(/\AUPDATE/i)
refute @second_item.saved_change_to_position?
end

reload_models

assert_equal [1, 2, 3], [@first_item, @second_item, @third_item].map(&:position)
end

def test_that_prior_item_is_found
assert_nil @first_item.prior_position
assert_equal @first_item, @second_item.prior_position
Expand Down
Loading