Navigation Menu

Skip to content

Commit

Permalink
Fix bug - item_at_offset method was not scoping correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
shuber committed May 14, 2009
1 parent d994756 commit 9c9b399
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
2009-05-13 - Sean Huber (shuber@huberry.com)
* Fix bug - item_at_offset method was not scoping correctly

2009-01-17 - Sean Huber (shuber@huberry.com)
* Update code documentation
* Make the sortable_scope_changes instance method public
Expand Down
2 changes: 1 addition & 1 deletion lib/sortable.rb
Expand Up @@ -204,7 +204,7 @@ def insert_at!(position = 1, list_name = nil)
# Returns nil if an item at the specified offset could not be found
def item_at_offset(offset, list_name = nil)
options = evaluate_sortable_options(list_name)
in_list?(list_name) ? self.class.send("find_by_#{options[:column]}".to_sym, send(options[:column]) + offset) : nil
in_list?(list_name) ? self.class.send("find_by_#{options[:column]}".to_sym, send(options[:column]) + offset, :conditions => options[:conditions]) : nil
end

# Returns the last item in a list associated with the current item
Expand Down
4 changes: 2 additions & 2 deletions sortable.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'sortable'
s.version = '1.0.0'
s.date = '2009-01-17'
s.version = '1.0.1'
s.date = '2009-05-13'

s.summary = 'Allows you to sort ActiveRecord items in multiple lists with multiple scopes'
s.description = 'Allows you to sort ActiveRecord items in multiple lists with multiple scopes'
Expand Down
10 changes: 6 additions & 4 deletions test/sortable_test.rb
Expand Up @@ -105,14 +105,16 @@ def test_should_insert_at!

def test_item_at_offset_should_return_previous_item
@todo = Todo.create
@todo_2 = Todo.create
assert_equal @todo, @todo_2.item_at_offset(-1, :client)
@todo_2 = Todo.create :project_id => 1
@todo_3 = Todo.create
assert_equal @todo, @todo_3.item_at_offset(-1, :client)
end

def test_item_at_offset_should_return_next_item
@todo = Todo.create
@todo_2 = Todo.create
assert_equal @todo_2, @todo.item_at_offset(1, :client)
@todo_2 = Todo.create :project_id => 1
@todo_3 = Todo.create
assert_equal @todo_3, @todo.item_at_offset(1, :client)
end

def test_item_at_offset_should_return_nil_for_non_existent_offset
Expand Down

0 comments on commit 9c9b399

Please sign in to comment.