Skip to content

Commit

Permalink
Feature/add exception to wrong position (#323)
Browse files Browse the repository at this point in the history
* Add test checking for a raised error

* Raise exception if invalid position argument
  • Loading branch information
TheNeikos authored and brendon committed Sep 17, 2018
1 parent 78c6106 commit 7938ad6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/acts_as_list/active_record/acts/list.rb
Expand Up @@ -393,6 +393,7 @@ def shuffle_positions_on_intermediate_items(old_position, new_position, avoid_id
end

def insert_at_position(position, raise_exception_if_save_fails=false)
raise ArgumentError.new("position cannot be lower than top") if position < acts_as_list_top
return set_list_position(position, raise_exception_if_save_fails) if new_record?
with_lock do
if in_list?
Expand Down
8 changes: 8 additions & 0 deletions test/test_list.rb
Expand Up @@ -922,4 +922,12 @@ def test_destroy
assert_equal [1,2,3,4], SequentialUpdatesDefault.all.map(&:pos).sort

end

def test_exception_on_wrong_position
new_item = SequentialUpdatesDefault.create

assert_raises ArgumentError do
new_item.insert_at(0)
end
end
end

0 comments on commit 7938ad6

Please sign in to comment.