Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8822: 1.2-STABLE_acts_as_list_remove_from_list_fix.diff

File 1.2-STABLE_acts_as_list_remove_from_list_fix.diff, 2.9 kB (added by mikel, 1 year ago)

Fixed tests to match recent changes in code for stable branch

  • test/mixin_test.rb

    old new  
    210210    new2.move_higher 
    211211    assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos') 
    212212  end 
     213   
     214  def test_remove_from_list_should_then_fail_in_list?  
     215    assert_equal true, mixins(:list_1).in_list? 
     216    mixins(:list_1).remove_from_list 
     217    assert_equal false, mixins(:list_1).in_list? 
     218  end  
     219   
     220  def test_remove_from_list_should_set_position_to_nil  
     221    assert_equal [mixins(:list_1), 
     222                  mixins(:list_2), 
     223                  mixins(:list_3), 
     224                  mixins(:list_4)],  
     225                  ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')  
    213226 
     227    mixins(:list_2).remove_from_list  
     228   
     229    assert_equal [mixins(:list_2, :reload), 
     230                  mixins(:list_1, :reload), 
     231                  mixins(:list_3, :reload), 
     232                  mixins(:list_4, :reload)],  
     233                  ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')  
     234   
     235    assert_equal 1, mixins(:list_1).pos  
     236    assert_equal nil, mixins(:list_2).pos  
     237    assert_equal 2, mixins(:list_3).pos  
     238    assert_equal 3, mixins(:list_4).pos  
     239  end  
     240   
     241  def test_remove_before_destroy_does_not_shift_lower_items_twice  
     242    assert_equal [mixins(:list_1), 
     243                  mixins(:list_2), 
     244                  mixins(:list_3), 
     245                  mixins(:list_4)],  
     246                  ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')  
     247   
     248    mixins(:list_2).remove_from_list  
     249    mixins(:list_2).destroy  
     250 
     251  assert_equal [mixins(:list_1, :reload), 
     252                mixins(:list_3, :reload), 
     253                mixins(:list_4, :reload)], 
     254                  ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')  
     255   
     256    assert_equal 1, mixins(:list_1).pos  
     257    assert_equal 2, mixins(:list_3).pos  
     258    assert_equal 3, mixins(:list_4).pos  
     259  end  
     260  
    214261end 
    215262 
    216263class TreeTest < Test::Unit::TestCase 
  • lib/active_record/acts/list.rb

    old new  
    6363             
    6464            #{scope_condition_method} 
    6565             
    66             after_destroy :remove_from_list 
     66            before_destroy :remove_from_list 
    6767            before_create  :add_to_list_bottom 
    6868          EOV 
    6969        end 
     
    121121         
    122122        # Removes the item from the list. 
    123123        def remove_from_list 
    124           decrement_positions_on_lower_items if in_list? 
     124          if in_list? 
     125            decrement_positions_on_lower_items 
     126            update_attribute position_column, nil 
     127          end 
    125128        end 
    126129 
    127130        # Increase the position of this item without adjusting the rest of the list.