public
Fork of NZKoz/koz-rails
Description: Koz's rails git-svn clone
Homepage: http://www.rubyonrails.org
Clone URL: git://github.com/eventualbuddha/koz-rails.git
Make sure acts_as_list's remove_from_list and in_list? play nicely with 
one another.  Closes #8822 [mikel]


git-svn-id: 
http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7815 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
nzkoz (author)
Mon Oct 08 22:16:43 -0700 2007
commit  767755b6c21206f58ff71d542427c48758c15672
tree    aaa0b07934583f258b38869ae06d057cf3d87a56
parent  d6fb2830f37a67dcd64cdd2c1c27e5df4de45661
...
63
64
65
66
 
67
68
69
...
121
122
123
124
 
 
 
 
125
126
127
...
63
64
65
 
66
67
68
69
...
121
122
123
 
124
125
126
127
128
129
130
0
@@ -63,7 +63,7 @@ module ActiveRecord
0
             
0
             #{scope_condition_method}
0
             
0
- after_destroy :remove_from_list
0
+ before_destroy :remove_from_list
0
             before_create :add_to_list_bottom
0
           EOV
0
         end
0
@@ -121,7 +121,10 @@ module ActiveRecord
0
         
0
         # Removes the item from the list.
0
         def remove_from_list
0
- decrement_positions_on_lower_items if in_list?
0
+ if in_list?
0
+ decrement_positions_on_lower_items
0
+ update_attribute position_column, nil
0
+ end
0
         end
0
 
0
         # Increase the position of this item without adjusting the rest of the list.
...
211
212
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
215
216
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
0
@@ -211,6 +211,53 @@ class ListTest < Test::Unit::TestCase
0
     assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos')
0
   end
0
 
0
+ def test_remove_from_list_should_then_fail_in_list?
0
+ assert_equal true, mixins(:list_1).in_list?
0
+ mixins(:list_1).remove_from_list
0
+ assert_equal false, mixins(:list_1).in_list?
0
+ end
0
+
0
+ def test_remove_from_list_should_set_position_to_nil
0
+ assert_equal [mixins(:list_1),
0
+ mixins(:list_2),
0
+ mixins(:list_3),
0
+ mixins(:list_4)],
0
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
0
+
0
+ mixins(:list_2).remove_from_list
0
+
0
+ assert_equal [mixins(:list_2, :reload),
0
+ mixins(:list_1, :reload),
0
+ mixins(:list_3, :reload),
0
+ mixins(:list_4, :reload)],
0
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
0
+
0
+ assert_equal 1, mixins(:list_1).pos
0
+ assert_equal nil, mixins(:list_2).pos
0
+ assert_equal 2, mixins(:list_3).pos
0
+ assert_equal 3, mixins(:list_4).pos
0
+ end
0
+
0
+ def test_remove_before_destroy_does_not_shift_lower_items_twice
0
+ assert_equal [mixins(:list_1),
0
+ mixins(:list_2),
0
+ mixins(:list_3),
0
+ mixins(:list_4)],
0
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
0
+
0
+ mixins(:list_2).remove_from_list
0
+ mixins(:list_2).destroy
0
+
0
+ assert_equal [mixins(:list_1, :reload),
0
+ mixins(:list_3, :reload),
0
+ mixins(:list_4, :reload)],
0
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
0
+
0
+ assert_equal 1, mixins(:list_1).pos
0
+ assert_equal 2, mixins(:list_3).pos
0
+ assert_equal 3, mixins(:list_4).pos
0
+ end
0
+
0
 end
0
 
0
 class TreeTest < Test::Unit::TestCase

Comments

    No one has commented yet.