Class: ListSubTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- ListSubTest
- Defined in:
- vendor/plugins/acts_as_list/test/list_test.rb
Instance Method Summary
- - (Object) setup
- - (Object) teardown
- - (Object) test_delete_middle
- - (Object) test_injection
- - (Object) test_insert_at
- - (Object) test_move_to_bottom_with_next_to_last_item
- - (Object) test_next_prev
- - (Object) test_reordering
Instance Method Details
- (Object) setup
228 229 230 231 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 228 def setup setup_db (1..4).each { |i| ((i % 2 == 1) ? ListMixinSub1 : ListMixinSub2).create! :pos => i, :parent_id => 5000 } end |
- (Object) teardown
233 234 235 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 233 def teardown teardown_db end |
- (Object) test_delete_middle
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 313 def test_delete_middle assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(2).destroy assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) assert_equal 1, ListMixin.find(1).pos assert_equal 2, ListMixin.find(3).pos assert_equal 3, ListMixin.find(4).pos ListMixin.find(1).destroy assert_equal [3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) assert_equal 1, ListMixin.find(3).pos assert_equal 2, ListMixin.find(4).pos end |
- (Object) test_injection
272 273 274 275 276 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 272 def test_injection item = ListMixin.new("parent_id"=>1) assert_equal "parent_id = 1", item.scope_condition assert_equal "pos", item.position_column end |
- (Object) test_insert_at
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 278 def test_insert_at new = ListMixin.create("parent_id" => 20) assert_equal 1, new.pos new = ListMixinSub1.create("parent_id" => 20) assert_equal 2, new.pos new = ListMixinSub2.create("parent_id" => 20) assert_equal 3, new.pos new4 = ListMixin.create("parent_id" => 20) assert_equal 4, new4.pos new4.insert_at(3) assert_equal 3, new4.pos new.reload assert_equal 4, new.pos new.insert_at(2) assert_equal 2, new.pos new4.reload assert_equal 4, new4.pos new5 = ListMixinSub1.create("parent_id" => 20) assert_equal 5, new5.pos new5.insert_at(1) assert_equal 1, new5.pos new4.reload assert_equal 5, new4.pos end |
- (Object) test_move_to_bottom_with_next_to_last_item
259 260 261 262 263 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 259 def test_move_to_bottom_with_next_to_last_item assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(3).move_to_bottom assert_equal [1, 2, 4, 3], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) end |
- (Object) test_next_prev
265 266 267 268 269 270 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 265 def test_next_prev assert_equal ListMixin.find(2), ListMixin.find(1).lower_item assert_nil ListMixin.find(1).higher_item assert_equal ListMixin.find(3), ListMixin.find(4).higher_item assert_nil ListMixin.find(4).lower_item end |
- (Object) test_reordering
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'vendor/plugins/acts_as_list/test/list_test.rb', line 237 def test_reordering assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(2).move_lower assert_equal [1, 3, 2, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(2).move_higher assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(1).move_to_bottom assert_equal [2, 3, 4, 1], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(1).move_to_top assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(2).move_to_bottom assert_equal [1, 3, 4, 2], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) ListMixin.find(4).move_to_top assert_equal [4, 1, 3, 2], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id) end |