Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

position not updated with move_higher or move_lover #23

Closed
nortcele opened this issue Nov 16, 2011 · 8 comments
Closed

position not updated with move_higher or move_lover #23

nortcele opened this issue Nov 16, 2011 · 8 comments
Assignees

Comments

@nortcele
Copy link

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

Steps to reproduce

  • Create a test application
    rails new asl_test
    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.

@ghost ghost assigned swanandp Nov 16, 2011
@nerab
Copy link

nerab commented Dec 17, 2011

I put this into a unit test: https://github.com/nerab/acts_as_list_issue_23

My test passes with Rails 3.1.3 on Ruby 1.8.7.

@swanandp
Copy link
Contributor

swanandp commented Jan 3, 2012

This seems like a serious bug. I am on it.

@jschairb
Copy link

Is there any status on this?

@swanandp
Copy link
Contributor

Unfortunately, not yet. If anyone is willing to send pull request, I'll be more than glad to merge it.

@splattael
Copy link
Contributor

I've added a test case which is passing on 1.8.7 and 1.9.2.

@swanandp
Copy link
Contributor

This might be a data caching issue. I tried the same thing, seems to work w/o issue.
Also, test_reordering and test_move_to_bottom_with_next_to_last_item do cover this case.

@jschairb
Copy link

I've spent a few minutes trying to write a failing test with the existing test harnesses, but I can verify that the problem exists with the sqlite3 and PostgreSQL adapters. I'm continuing to investigate however I think the problem lies with #bottom_item.

@swanandp
Copy link
Contributor

@jschairb When you verified the problem, did you actually check DB values? i.e. lefty.reload.fingers.each { |finger| puts "#{finger.position}: #{finger.name}" } or something to that effect? But in any case, can you create gist with that test case and point us to it? I tested it too, and my results are similar to @splattael's.

zdavis added a commit to ManifoldScholar/manifold that referenced this issue Jun 13, 2017
See brendon/acts_as_list#23 for context. We
were seeing an issue in which moving a model up in the list would not
update the models position property if there were two items in the list.
For now, we're reloading the model after changing the position to ensure
an accurate position property.
zdavis added a commit to ManifoldScholar/manifold that referenced this issue Jun 13, 2017
See brendon/acts_as_list#23 for context. We
were seeing an issue in which moving a model up in the list would not
update the models position property if there were two items in the list.
For now, we're reloading the model after changing the position to ensure
an accurate position property.
zdavis added a commit to ManifoldScholar/manifold that referenced this issue Jun 13, 2017
See brendon/acts_as_list#23 for context. We
were seeing an issue in which moving a model up in the list would not
update the models position property if there were two items in the list.
For now, we're reloading the model after changing the position to ensure
an accurate position property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants