Skip to content

Commit

Permalink
Merge pull request #104 from csaura/fix-top-position
Browse files Browse the repository at this point in the history
Fix top position when position is lower than top position
  • Loading branch information
swanandp committed Feb 22, 2014
2 parents 332d2d7 + 475307d commit 3ebaffc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/acts_as_list/active_record/acts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def add_new_at
after_destroy :decrement_positions_on_lower_items
before_update :check_scope
after_update :update_positions
before_validation :check_top_position
scope :in_list, lambda { where("#{table_name}.#{configuration[:column]} IS NOT NULL") }
EOV
Expand Down Expand Up @@ -441,6 +442,12 @@ def check_scope
def reload_position
self.reload
end

def check_top_position
if send(position_column) && send(position_column) < acts_as_list_top
self[position_column] = acts_as_list_top
end
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/shared_zero_based.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def test_insert
assert_equal 0, new.pos
assert new.first?
assert new.last?

new = ZeroBasedMixin.create(parent_id: 1, pos: -500)
assert_equal 0, new.pos
assert new.first?
assert new.last?
end

def test_reordering
Expand Down

0 comments on commit 3ebaffc

Please sign in to comment.