swanandp/acts_as_list — Issue #23: position not updated with move_higher or move_lover
Author: nortcele
Created: 2011-11-16 12:59:45+00:00
State: open

I have a strange behavior with acts_as_list, Rails 3.1 and Ruby 1.9.2p290.

Steps to reproduce
- Create a test application
shell> rails new asl_test
shell> cd asl_test

- Add

gem 'acts_as_list', :git => 'https://github.com/swanandp/acts_as_list.git'

in gemfile.

- Update gems

bundle update

- Generate a model
rails generate model Hand side:string

- Generate a second model
rails generate model Finger position:integer name:string hand_id:integer

- Migrate the db
bundle exec rake db:migrate

- Modify the hand model
class Hand < ActiveRecord::Base
has_many :fingers
end

- Modify the finger model
class Finger < ActiveRecord::Base
belongs_to :hand
acts_as_list :scope => :hand
end

- Now go to the console
rails console

- Create a hand
lefty = Hand.create(:side => "left")

- Add some fingers
lefty.fingers.create(:name => "thumb")
lefty.fingers.create(:name => "index")
lefty.fingers.create(:name => "ring")
lefty.fingers.create(:name => "middle")
lefty.fingers.create(:name => "baby")

Let's see the fingers
lefty.fingers.each do |finger| puts "#{finger.position}: #{finger.name}" end

That gives what was inserted.
1: thumb
2: index
3: ring
4: middle
5: baby

But one finger is not at the good place so try to correct that.
lefty.fingers[3].move_lower

Let's see the fingers now
lefty.fingers.each do |finger| puts "#{finger.position}: #{finger.name}" end

The result is not what I expected
1: thumb
2: index
3: ring
5: middle
5: baby

I don't know why middle and ring where not interverted and why there are two fingers whose position is 5.