Class: TreeTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TreeTest
- Defined in:
- lib/plugins/acts_as_tree/test/acts_as_tree_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_ancestors ⇒ Object
- #test_children ⇒ Object
- #test_delete ⇒ Object
- #test_insert ⇒ Object
- #test_parent ⇒ Object
- #test_root ⇒ Object
- #test_roots ⇒ Object
- #test_self_and_siblings ⇒ Object
- #test_siblings ⇒ Object
Instance Method Details
#setup ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 63 def setup setup_db @root1 = TreeMixin.create! @root_child1 = TreeMixin.create! :parent_id => @root1.id @child1_child = TreeMixin.create! :parent_id => @root_child1.id @root_child2 = TreeMixin.create! :parent_id => @root1.id @root2 = TreeMixin.create! @root3 = TreeMixin.create! end |
#teardown ⇒ Object
73 74 75 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 73 def teardown teardown_db end |
#test_ancestors ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 112 def test_ancestors assert_equal [], @root1.ancestors assert_equal [@root1], @root_child1.ancestors assert_equal [@root_child1, @root1], @child1_child.ancestors assert_equal [@root1], @root_child2.ancestors assert_equal [], @root2.ancestors assert_equal [], @root3.ancestors end |
#test_children ⇒ Object
77 78 79 80 81 82 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 77 def test_children assert_equal @root1.children, [@root_child1, @root_child2] assert_equal @root_child1.children, [@child1_child] assert_equal @child1_child.children, [] assert_equal @root_child2.children, [] end |
#test_delete ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 90 def test_delete assert_equal 6, TreeMixin.count @root1.destroy assert_equal 2, TreeMixin.count @root2.destroy @root3.destroy assert_equal 0, TreeMixin.count end |
#test_insert ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 99 def test_insert @extra = @root1.children.create assert @extra assert_equal @extra.parent, @root1 assert_equal 3, @root1.children.size assert @root1.children.include?(@extra) assert @root1.children.include?(@root_child1) assert @root1.children.include?(@root_child2) end |
#test_parent ⇒ Object
84 85 86 87 88 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 84 def test_parent assert_equal @root_child1.parent, @root1 assert_equal @root_child1.parent, @root_child2.parent assert_nil @root1.parent end |
#test_root ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 121 def test_root assert_equal @root1, TreeMixin.root assert_equal @root1, @root1.root assert_equal @root1, @root_child1.root assert_equal @root1, @child1_child.root assert_equal @root1, @root_child2.root assert_equal @root2, @root2.root assert_equal @root3, @root3.root end |
#test_roots ⇒ Object
131 132 133 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 131 def test_roots assert_equal [@root1, @root2, @root3], TreeMixin.roots end |
#test_self_and_siblings ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 144 def test_self_and_siblings assert_equal [@root1, @root2, @root3], @root1.self_and_siblings assert_equal [@root_child1, @root_child2], @root_child1.self_and_siblings assert_equal [@child1_child], @child1_child.self_and_siblings assert_equal [@root_child1, @root_child2], @root_child2.self_and_siblings assert_equal [@root1, @root2, @root3], @root2.self_and_siblings assert_equal [@root1, @root2, @root3], @root3.self_and_siblings end |
#test_siblings ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 135 def test_siblings assert_equal [@root2, @root3], @root1.siblings assert_equal [@root_child2], @root_child1.siblings assert_equal [], @child1_child.siblings assert_equal [@root_child1], @root_child2.siblings assert_equal [@root1, @root3], @root2.siblings assert_equal [@root1, @root2], @root3.siblings end |