class ListTest
Public Instance Methods
setup()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 52 def setup setup_db (1..4).each { |counter| ListMixin.create! :pos => counter, :parent_id => 5 } end
teardown()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 57 def teardown teardown_db end
test_delete_middle()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 159 def test_delete_middle assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).destroy assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :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 = 5', :order => 'pos').map(&:id) assert_equal 1, ListMixin.find(3).pos assert_equal 2, ListMixin.find(4).pos end
test_injection()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 96 def test_injection item = ListMixin.new(:parent_id => 1) assert_equal "parent_id = 1", item.scope_condition assert_equal "pos", item.position_column end
test_insert()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 102 def test_insert new = ListMixin.create(:parent_id => 20) assert_equal 1, new.pos assert new.first? assert new.last? new = ListMixin.create(:parent_id => 20) assert_equal 2, new.pos assert !new.first? assert new.last? new = ListMixin.create(:parent_id => 20) assert_equal 3, new.pos assert !new.first? assert new.last? new = ListMixin.create(:parent_id => 0) assert_equal 1, new.pos assert new.first? assert new.last? end
test_insert_at()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 124 def test_insert_at new = ListMixin.create(:parent_id => 20) assert_equal 1, new.pos new = ListMixin.create(:parent_id => 20) assert_equal 2, new.pos new = ListMixin.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 = ListMixin.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
test_move_to_bottom_with_next_to_last_item()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 83 def test_move_to_bottom_with_next_to_last_item assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(3).move_to_bottom assert_equal [1, 2, 4, 3], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) end
test_next_prev()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 89 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
test_nil_scope()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 185 def test_nil_scope new1, new2, new3 = ListMixin.create, ListMixin.create, ListMixin.create new2.move_higher assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos') end
test_remove_before_destroy_does_not_shift_lower_items_twice()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 211 def test_remove_before_destroy_does_not_shift_lower_items_twice assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).remove_from_list ListMixin.find(2).destroy assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :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 end
test_remove_from_list_should_set_position_to_nil()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 198 def test_remove_from_list_should_set_position_to_nil assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).remove_from_list assert_equal [2, 1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) assert_equal 1, ListMixin.find(1).pos assert_equal nil, ListMixin.find(2).pos assert_equal 2, ListMixin.find(3).pos assert_equal 3, ListMixin.find(4).pos end
test_remove_from_list_should_then_fail_in_list?()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 192 def test_remove_from_list_should_then_fail_in_list? assert_equal true, ListMixin.find(1).in_list? ListMixin.find(1).remove_from_list assert_equal false, ListMixin.find(1).in_list? end
test_reordering()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 61 def test_reordering assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).move_lower assert_equal [1, 3, 2, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).move_higher assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(1).move_to_bottom assert_equal [2, 3, 4, 1], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(1).move_to_top assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(2).move_to_bottom assert_equal [1, 3, 4, 2], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) ListMixin.find(4).move_to_top assert_equal [4, 1, 3, 2], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) end
test_with_string_based_scope()
click to toggle source
# File lib/plugins/acts_as_list/test/list_test.rb, line 178 def test_with_string_based_scope new = ListWithStringScopeMixin.create(:parent_id => 500) assert_equal 1, new.pos assert new.first? assert new.last? end