Class: TreeTestWithEagerLoading
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TreeTestWithEagerLoading
- Defined in:
- vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb
Instance Method Summary
- - (Object) setup
- - (Object) teardown
- - (Object) test_eager_association_loading
- - (Object) test_eager_association_loading_with_recursive_cascading_three_levels_belongs_to
- - (Object) test_eager_association_loading_with_recursive_cascading_three_levels_has_many
- - (Object) test_eager_association_loading_with_recursive_cascading_three_levels_has_one
Instance Method Details
- (Object) setup
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 154 def setup teardown_db 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! @rc1 = RecursivelyCascadedTreeMixin.create! @rc2 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc1.id @rc3 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc2.id @rc4 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc3.id end |
- (Object) teardown
170 171 172 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 170 def teardown teardown_db end |
- (Object) test_eager_association_loading
174 175 176 177 178 179 180 181 182 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 174 def test_eager_association_loading roots = TreeMixin.find(:all, :include => :children, :conditions => "mixins.parent_id IS NULL", :order => "mixins.id") assert_equal [@root1, @root2, @root3], roots assert_no_queries do assert_equal 2, roots[0].children.size assert_equal 0, roots[1].children.size assert_equal 0, roots[2].children.size end end |
- (Object) test_eager_association_loading_with_recursive_cascading_three_levels_belongs_to
194 195 196 197 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 194 def test_eager_association_loading_with_recursive_cascading_three_levels_belongs_to leaf_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :parent => { :parent => :parent } }, :order => 'mixins.id DESC') assert_equal @rc1, assert_no_queries { leaf_node.parent.parent.parent } end |
- (Object) test_eager_association_loading_with_recursive_cascading_three_levels_has_many
184 185 186 187 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 184 def test_eager_association_loading_with_recursive_cascading_three_levels_has_many root_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :children => { :children => :children } }, :order => 'mixins.id') assert_equal @rc4, assert_no_queries { root_node.children.first.children.first.children.first } end |
- (Object) test_eager_association_loading_with_recursive_cascading_three_levels_has_one
189 190 191 192 |
# File 'vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb', line 189 def test_eager_association_loading_with_recursive_cascading_three_levels_has_one root_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :first_child => { :first_child => :first_child } }, :order => 'mixins.id') assert_equal @rc4, assert_no_queries { root_node.first_child.first_child.first_child } end |