Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
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
4 changes: 2 additions & 2 deletions lib/dm-is-list/is/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,14 @@ def move_without_saving(vector)
# -- the same as self
# -- already below self
# -- higher up than self (lower number in list)
( (self == object) or (object.position > self.position) ) ? self.position : object.position
( (self == object) or (object.position == self.position + 1) ) ? self.position : object.position

when :below
# the object given, can either be:
# -- the same as self
# -- already above self
# -- lower than self (higher number in list)
( self == object or (object.position < self.position) ) ? self.position : object.position + 1
( self == object or (object.position == self.position - 1) ) ? self.position : object.position + 1

when :to
# can only move within top and bottom positions of list
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@
end
end

it "should move item directly :above another in list even if it's already above it" do
DataMapper.repository(:default) do |repos|
Todo.get(2).move(:above => Todo.get(4) ).should == true
todo_list.should == [ [1, 1], [3, 2], [2, 3], [4, 4], [5, 5] ]
end
end

it "should NOT move item :above itself" do
DataMapper.repository(:default) do |repos|
Todo.get(1).move(:above => Todo.get(1) ).should == false
Expand Down Expand Up @@ -238,6 +245,13 @@
end
end

it "should move item directly :below another in list even if it's already below it" do
DataMapper.repository(:default) do |repos|
Todo.get(4).move(:below => Todo.get(2) ).should == true
todo_list.should == [ [1, 1], [2, 2], [4, 3], [3, 4], [5, 5] ]
end
end

it "should NOT move item :below itself" do
DataMapper.repository(:default) do |repos|
Todo.get(1).move(:below => Todo.get(1) ).should == false # is this logical ???
Expand Down