Class: ListSubTest
- Inherits:
-
ActiveSupport::TestCase
- Object
- ActiveSupport::TestCase
- ListSubTest
- Defined in:
- test/sub_list_test.rb
Instance Method Summary collapse
- #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 ⇒ Object
- #test_sti ⇒ Object
Instance Method Details
#setup ⇒ Object
11 12 13 14 |
# File 'test/sub_list_test.rb', line 11 def setup setup_db (1..4).each { |i| ((i % 2 == 1) ? ListMixinSub1 : ListMixinSub2).create! :pos => i, :parent_id => 5000 } end |
#teardown ⇒ Object
16 17 18 |
# File 'test/sub_list_test.rb', line 16 def teardown teardown_db end |
#test_delete_middle ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'test/sub_list_test.rb', line 108 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 |
#test_injection ⇒ Object
67 68 69 70 71 |
# File 'test/sub_list_test.rb', line 67 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_at ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'test/sub_list_test.rb', line 73 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 |
#test_move_to_bottom_with_next_to_last_item ⇒ Object
42 43 44 45 46 |
# File 'test/sub_list_test.rb', line 42 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 |
#test_next_prev ⇒ Object
48 49 50 51 52 53 |
# File 'test/sub_list_test.rb', line 48 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_reordering ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'test/sub_list_test.rb', line 20 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 |
#test_sti ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'test/sub_list_test.rb', line 55 def test_sti new = StiMixinSub1.create assert_equal 1, new.position new = StiMixinSub1.create assert_equal 2, new.position new = StiMixinSub2.create assert_equal 1, new.position new = StiMixinSub2.create assert_equal 2, new.position end |