#818 ✓resolved
Mark Lynn

dm-is-list not updating positioning for new instances

Reported by Mark Lynn | March 19th, 2009 @ 01:56 PM | in 0.10.0

The following test fails for dm-list


require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
  describe 'DataMapper::Is::List' do

    class User
      include DataMapper::Resource
      property :id, Serial
      property :name, String
      has n, :todos
    end

    class Todo
      include DataMapper::Resource
      property :id, Serial
      property :title, String
      belongs_to :user
      is :list, :scope => [:user_id]
    end

    before :each do
      User.auto_migrate!(:default)
      Todo.auto_migrate!(:default)
    end
    
    it 'should rearrange items when setting position yourself on newly created items' do
      u3 = User.create(:name => "Mark")
      todo1 = Todo.create(:user => u3, :title => "Cleanup garage")
      todo2 = Todo.create(:user => u3, :title => "Cleanup yard")
      todo3 = Todo.create(:user => u3, :title => "Cleanup basement")
      todo3.position = 1
      todo3.save
      
      Todo.get(todo3.id).position.should == 1
      Todo.get(todo1.id).position.should == 2
    end
  end
end

The problem appears to be that the moved flag is set true during object creation and not cleared. This can be fixed by setting moved=false in before :create block or alternatively adding a block such as


after :save do
  self.moved = false
end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Referenced by

Pages