Skip to content

Commit

Permalink
Merge pull request brendon#47 from bastien/master
Browse files Browse the repository at this point in the history
Fixed issue with update_positions that wasn't taking 'scope_condition' into account
  • Loading branch information
swanandp committed Aug 9, 2012
2 parents caa41b9 + d8e176f commit 06f847e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_list/active_record/acts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def store_at_0
def update_positions
old_position = send("#{position_column}_was").to_i
new_position = send(position_column).to_i
return unless acts_as_list_class.unscoped.where("#{position_column} = #{new_position}").count > 1
return unless acts_as_list_class.unscoped.where("#{scope_condition} AND #{position_column} = #{new_position}").count > 1
shuffle_positions_on_intermediate_items old_position, new_position, id
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/shared_array_scope_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Shared
module ArrayScopeList
def setup
(1..4).each { |counter| ArrayScopeListMixin.create! :pos => counter, :parent_id => 5, :parent_type => 'ParentClass' }
(1..4).each { |counter| ArrayScopeListMixin.create! :pos => counter, :parent_id => 6, :parent_type => 'ParentClass' }
end

def test_reordering
Expand All @@ -24,6 +25,10 @@ def test_reordering

ArrayScopeListMixin.find(4).move_to_top
assert_equal [4, 1, 3, 2], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)

ArrayScopeListMixin.find(4).insert_at(4)
assert_equal [1, 3, 2, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:pos)
end

def test_move_to_bottom_with_next_to_last_item
Expand Down

0 comments on commit 06f847e

Please sign in to comment.