acts_as_list gem does not correctly assign position when model has a default_scope order(:position) in rails 3 #3

Closed
MissingHandle opened this Issue Dec 14, 2010 · 0 comments

Comments

Projects
None yet
1 participant

Migration:

    class CreateFoos < ActiveRecord::Migration
      def self.up
        create_table :foos do |t|
          t.integer :position

          t.timestamps
        end
      end

      def self.down
        drop_table :foos
      end
    end

Model:
class Foo < ActiveRecord::Base
acts_as_list
default_scope order(:position)
end

Tests:

    require 'test_helper'

    class FooTest < ActiveSupport::TestCase
      # Replace this with your real tests.

      test "it creates foos with the correct position without any scoping" do
        Foo.destroy_all
        Foo.send(:with_exclusive_scope) do 
          Foo.create!
          Foo.create!
          @three = Foo.create!
        end
        assert_equal 3, @three.position
      end

      test "it creates foos with the correct position with a default_scope order(:position)" do
        Foo.destroy_all
        Foo.create!
        Foo.create!
        three = Foo.create!
        assert_equal 3, three.position
      end

    end

The first test passes, the second test fails. Methinks the likely suspect for this issue is line 196 within the bottom_item method:

  # Returns the bottom item
  def bottom_item(except = nil)
    conditions = scope_condition
    conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
    acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC")
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment