Class: AwesomeNestedSetTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb

Defined Under Namespace

Classes: Default, Scoped

Instance Method Summary

Instance Method Details

- (Object) test_ancestors



130
131
132
133
134
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 130

def test_ancestors
  child = categories(:child_2_1)
  ancestors = [categories(:top_level), categories(:child_2)]
  assert_equal ancestors, child.ancestors
end

- (Object) test_children



197
198
199
200
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 197

def test_children
  category = categories(:top_level)
  category.children.each {|c| assert_equal category.id, c.parent_id }
end

- (Object) test_colums_protected_on_initialize



73
74
75
76
77
78
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 73

def test_colums_protected_on_initialize
  c = Category.new(:lft => 1, :rgt => 2, :parent_id => 3)
  assert_nil c.lft
  assert_nil c.rgt
  assert_nil c.parent_id
end

- (Object) test_descendents



177
178
179
180
181
182
183
184
185
186
187
188
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 177

def test_descendents
  lawyers = Category.create!(:name => "lawyers")
  us = Category.create!(:name => "United States")
  us.move_to_child_of(lawyers)
  patent = Category.create!(:name => "Patent Law")
  patent.move_to_child_of(us)
  lawyers.reload

  assert_equal 1, lawyers.children.size
  assert_equal 1, us.children.size
  assert_equal 2, lawyers.descendants.size
end

- (Object) test_difficult_move_to_child_of



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 384

def test_difficult_move_to_child_of
  assert_equal 1, categories(:top_level).left
  assert_equal 10, categories(:top_level).right
  assert_equal 5, categories(:child_2_1).left
  assert_equal 6, categories(:child_2_1).right
  
  # create a new top-level node and move an entire top-level tree inside it.
  new_top = Category.create(:name => 'New Top')
  categories(:top_level).move_to_child_of(new_top)
  categories(:child_2_1).reload
  assert Category.valid?  
  assert_equal new_top.id, categories(:top_level).parent_id
  
  assert_equal 4, categories(:top_level).left
  assert_equal 13, categories(:top_level).right
  assert_equal 8, categories(:child_2_1).left
  assert_equal 9, categories(:child_2_1).right    
end

- (Object) test_equal_in_different_scopes



599
600
601
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 599

def test_equal_in_different_scopes
  assert_not_equal notes(:scope1), notes(:scope2)
end

- (Object) test_equal_in_same_scope



594
595
596
597
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 594

def test_equal_in_same_scope
  assert_equal notes(:scope1), notes(:scope1)
  assert_not_equal notes(:scope1), notes(:child_1)
end

- (Boolean) test_has_children?

Returns:

  • (Boolean)


163
164
165
166
167
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 163

def test_has_children?
  assert categories(:child_2_1).children.empty?
  assert !categories(:child_2).children.empty?
  assert !categories(:top_level).children.empty?
end

- (Boolean) test_is_ancestor_of?

Returns:

  • (Boolean)


211
212
213
214
215
216
217
218
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 211

def test_is_ancestor_of?
  assert categories(:top_level).is_ancestor_of?(categories(:child_1))
  assert categories(:top_level).is_ancestor_of?(categories(:child_2_1))
  assert categories(:child_2).is_ancestor_of?(categories(:child_2_1))
  assert !categories(:child_2_1).is_ancestor_of?(categories(:child_2))
  assert !categories(:child_1).is_ancestor_of?(categories(:child_2))
  assert !categories(:child_1).is_ancestor_of?(categories(:child_1))
end

- (Boolean) test_is_descendant_of?

Returns:

  • (Boolean)


237
238
239
240
241
242
243
244
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 237

def test_is_descendant_of?
  assert categories(:child_1).is_descendant_of?(categories(:top_level))
  assert categories(:child_2_1).is_descendant_of?(categories(:top_level))
  assert categories(:child_2_1).is_descendant_of?(categories(:child_2))
  assert !categories(:child_2).is_descendant_of?(categories(:child_2_1))
  assert !categories(:child_2).is_descendant_of?(categories(:child_1))
  assert !categories(:child_1).is_descendant_of?(categories(:child_1))
end

- (Boolean) test_is_or_is_ancestor_of?

Returns:

  • (Boolean)


202
203
204
205
206
207
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 202

def test_is_or_is_ancestor_of?
  [:child_1, :child_2, :child_2_1, :child_3].each do |c|
    assert categories(:top_level).is_or_is_ancestor_of?(categories(c))
  end
  assert !categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2))
end

- (Object) test_is_or_is_ancestor_of_with_scope



220
221
222
223
224
225
226
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 220

def test_is_or_is_ancestor_of_with_scope
  root = Scoped.root
  child = root.children.first
  assert root.is_or_is_ancestor_of?(child)
  child.update_attribute :organization_id, 'different'
  assert !root.is_or_is_ancestor_of?(child)
end

- (Boolean) test_is_or_is_descendant_of?

Returns:

  • (Boolean)


228
229
230
231
232
233
234
235
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 228

def test_is_or_is_descendant_of?
  assert categories(:child_1).is_or_is_descendant_of?(categories(:top_level))
  assert categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level))
  assert categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2))
  assert !categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1))
  assert !categories(:child_2).is_or_is_descendant_of?(categories(:child_1))
  assert categories(:child_1).is_or_is_descendant_of?(categories(:child_1))
end

- (Object) test_is_or_is_descendant_of_with_scope



246
247
248
249
250
251
252
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 246

def test_is_or_is_descendant_of_with_scope
  root = Scoped.root
  child = root.children.first
  assert child.is_or_is_descendant_of?(root)
  child.update_attribute :organization_id, 'different'
  assert !child.is_or_is_descendant_of?(root)
end

- (Object) test_leaf



110
111
112
113
114
115
116
117
118
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 110

def test_leaf
  assert categories(:child_1).leaf?
  assert categories(:child_2_1).leaf?
  assert categories(:child_3).leaf?
  assert categories(:top_level_2).leaf?
  
  assert !categories(:top_level).leaf?
  assert !categories(:child_2).leaf?
end

- (Object) test_leaves



152
153
154
155
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 152

def test_leaves
  leaves = [categories(:child_1), categories(:child_2_1), categories(:child_3), categories(:top_level_2)]
  assert categories(:top_level).leaves, leaves
end

- (Object) test_leaves_class_method



101
102
103
104
105
106
107
108
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 101

def test_leaves_class_method
  assert_equal Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1"), Category.leaves
  assert_equal Category.leaves.count, 4
  assert (Category.leaves.include? categories(:child_1))
  assert (Category.leaves.include? categories(:child_2_1))
  assert (Category.leaves.include? categories(:child_3))
  assert (Category.leaves.include? categories(:top_level_2))
end

- (Object) test_left_and_rights_valid_with_blank_left



493
494
495
496
497
498
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 493

def test_left_and_rights_valid_with_blank_left
  assert Category.left_and_rights_valid?
  categories(:child_2)[:lft] = nil
  categories(:child_2).save(false)
  assert !Category.left_and_rights_valid?
end

- (Object) test_left_and_rights_valid_with_blank_right



500
501
502
503
504
505
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 500

def test_left_and_rights_valid_with_blank_right
  assert Category.left_and_rights_valid?
  categories(:child_2)[:rgt] = nil
  categories(:child_2).save(false)
  assert !Category.left_and_rights_valid?
end

- (Object) test_left_and_rights_valid_with_equal



507
508
509
510
511
512
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 507

def test_left_and_rights_valid_with_equal
  assert Category.left_and_rights_valid?
  categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]
  categories(:top_level_2).save(false)
  assert !Category.left_and_rights_valid?
end

- (Object) test_left_and_rights_valid_with_left_equal_to_parent



514
515
516
517
518
519
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 514

def test_left_and_rights_valid_with_left_equal_to_parent
  assert Category.left_and_rights_valid?
  categories(:child_2)[:lft] = categories(:top_level)[:lft]
  categories(:child_2).save(false)
  assert !Category.left_and_rights_valid?
end

- (Object) test_left_and_rights_valid_with_right_equal_to_parent



521
522
523
524
525
526
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 521

def test_left_and_rights_valid_with_right_equal_to_parent
  assert Category.left_and_rights_valid?
  categories(:child_2)[:rgt] = categories(:top_level)[:rgt]
  categories(:child_2).save(false)
  assert !Category.left_and_rights_valid?
end

- (Object) test_left_column_default



18
19
20
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 18

def test_left_column_default
  assert_equal 'lft', Default.acts_as_nested_set_options[:left_column]
end

- (Object) test_left_column_name



34
35
36
37
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 34

def test_left_column_name
  assert_equal 'lft', Default.left_column_name
  assert_equal 'lft', Default.new.left_column_name
end

- (Object) test_left_column_protected_from_assignment



61
62
63
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 61

def test_left_column_protected_from_assignment
  assert_raises(ActiveRecord::ActiveRecordError) { Category.new.lft = 1 }
end

- (Object) test_left_sibling



262
263
264
265
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 262

def test_left_sibling
  assert_equal categories(:child_1), categories(:child_2).left_sibling
  assert_equal categories(:child_2), categories(:child_3).left_sibling
end

- (Object) test_left_sibling_of_leftmost_node



275
276
277
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 275

def test_left_sibling_of_leftmost_node
  assert_nil categories(:child_1).left_sibling
end

- (Object) test_left_sibling_of_root



267
268
269
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 267

def test_left_sibling_of_root
  assert_nil categories(:top_level).left_sibling
end

- (Object) test_left_sibling_without_siblings



271
272
273
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 271

def test_left_sibling_without_siblings
  assert_nil categories(:child_2_1).left_sibling
end

- (Object) test_level



157
158
159
160
161
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 157

def test_level
  assert_equal 0, categories(:top_level).level
  assert_equal 1, categories(:child_1).level
  assert_equal 2, categories(:child_2_1).level
end

- (Object) test_move_left



297
298
299
300
301
302
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 297

def test_move_left
  categories(:child_2).move_left
  assert_nil categories(:child_2).left_sibling
  assert_equal categories(:child_1), categories(:child_2).right_sibling
  assert Category.valid?
end

- (Object) test_move_not_possible_to_parent



479
480
481
482
483
484
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 479

def test_move_not_possible_to_parent
  categories(:top_level).descendants.each do |descendant|
    assert !categories(:top_level).move_possible?(descendant)
    assert descendant.move_possible?(categories(:top_level))
  end
end

- (Object) test_move_not_possible_to_self



475
476
477
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 475

def test_move_not_possible_to_self
  assert !categories(:top_level).move_possible?(categories(:top_level))
end

- (Object) test_move_possible_for_sibling



471
472
473
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 471

def test_move_possible_for_sibling
  assert categories(:child_2).move_possible?(categories(:child_1))
end

- (Object) test_move_right



304
305
306
307
308
309
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 304

def test_move_right
  categories(:child_2).move_right
  assert_nil categories(:child_2).right_sibling
  assert_equal categories(:child_3), categories(:child_2).left_sibling
  assert Category.valid?
end

- (Object) test_move_to_child_more_than_once_per_parent_outside_in

doing move_to_child twice onto same parent from the furthest right first



420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 420

def test_move_to_child_more_than_once_per_parent_outside_in
  node1 = Category.create(:name => 'Node-1')
  node2 = Category.create(:name => 'Node-2')
  node3 = Category.create(:name => 'Node-3')
  
  node2.move_to_child_of node1
  node3.move_to_child_of node1
    
  output = Category.roots.last.to_text
  Category.update_all('lft = null, rgt = null')
  Category.rebuild!
  
  assert_equal Category.roots.last.to_text, output
end

- (Object) test_move_to_child_more_than_once_per_parent_rebuild

rebuild swaps the position of the 2 children when added using move_to_child twice onto same parent



404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 404

def test_move_to_child_more_than_once_per_parent_rebuild
  root1 = Category.create(:name => 'Root1')
  root2 = Category.create(:name => 'Root2')
  root3 = Category.create(:name => 'Root3')
  
  root2.move_to_child_of root1
  root3.move_to_child_of root1
    
  output = Category.roots.last.to_text
  Category.update_all('lft = null, rgt = null')
  Category.rebuild!
  
  assert_equal Category.roots.last.to_text, output
end

- (Object) test_move_to_child_of



335
336
337
338
339
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 335

def test_move_to_child_of
  categories(:child_1).move_to_child_of(categories(:child_3))
  assert_equal categories(:child_3).id, categories(:child_1).parent_id
  assert Category.valid?
end

- (Object) test_move_to_child_of_appends_to_end



341
342
343
344
345
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 341

def test_move_to_child_of_appends_to_end
  child = Category.create! :name => 'New Child'
  child.move_to_child_of categories(:top_level)
  assert_equal child, categories(:top_level).children.last
end

- (Object) test_move_to_left_of



311
312
313
314
315
316
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 311

def test_move_to_left_of
  categories(:child_3).move_to_left_of(categories(:child_1))
  assert_nil categories(:child_3).left_sibling
  assert_equal categories(:child_1), categories(:child_3).right_sibling
  assert Category.valid?
end

- (Object) test_move_to_right_of



318
319
320
321
322
323
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 318

def test_move_to_right_of
  categories(:child_1).move_to_right_of(categories(:child_3))
  assert_nil categories(:child_1).right_sibling
  assert_equal categories(:child_3), categories(:child_1).left_sibling
  assert Category.valid?
end

- (Object) test_move_to_root



325
326
327
328
329
330
331
332
333
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 325

def test_move_to_root
  categories(:child_2).move_to_root
  assert_nil categories(:child_2).parent
  assert_equal 0, categories(:child_2).level
  assert_equal 1, categories(:child_2_1).level
  assert_equal 1, categories(:child_2).left
  assert_equal 4, categories(:child_2).right
  assert Category.valid?
end

- (Object) test_moving_dirty_objects_doesnt_invalidate_tree



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 528

def test_moving_dirty_objects_doesnt_invalidate_tree
  r1 = Category.create
  r2 = Category.create
  r3 = Category.create
  r4 = Category.create
  nodes = [r1, r2, r3, r4]
  
  r2.move_to_child_of(r1)
  assert Category.valid?
  
  r3.move_to_child_of(r1)
  assert Category.valid?
  
  r4.move_to_child_of(r2)
  assert Category.valid?
end

- (Object) test_multi_scoped



557
558
559
560
561
562
563
564
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 557

def test_multi_scoped
  note1 = Note.create!(:body => "A", :notable_id => 2, :notable_type => 'Category')
  note2 = Note.create!(:body => "B", :notable_id => 2, :notable_type => 'Category')
  note3 = Note.create!(:body => "C", :notable_id => 2, :notable_type => 'Default')
  
  assert_equal [note1, note2], note1.self_and_siblings
  assert_equal [note3], note3.self_and_siblings
end

- (Boolean) test_multi_scoped_all_roots_valid?

Returns:

  • (Boolean)


551
552
553
554
555
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 551

def test_multi_scoped_all_roots_valid?
  assert_nothing_raised do
    Note.all_roots_valid?
  end
end

- (Boolean) test_multi_scoped_no_duplicates_for_columns?

Returns:

  • (Boolean)


545
546
547
548
549
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 545

def test_multi_scoped_no_duplicates_for_columns?
  assert_nothing_raised do
    Note.no_duplicates_for_columns?
  end
end

- (Object) test_multi_scoped_rebuild



566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 566

def test_multi_scoped_rebuild
  root = Note.create!(:body => "A", :notable_id => 3, :notable_type => 'Category')
  child1 = Note.create!(:body => "B", :notable_id => 3, :notable_type => 'Category')
  child2 = Note.create!(:body => "C", :notable_id => 3, :notable_type => 'Category')
  
  child1.move_to_child_of root
  child2.move_to_child_of root
        
  Note.update_all('lft = null, rgt = null')
  Note.rebuild!
  
  assert_equal Note.roots.find_by_body('A'), root
  assert_equal [child1, child2], Note.roots.find_by_body('A').children
end

- (Object) test_parent



120
121
122
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 120

def test_parent
  assert_equal categories(:child_2), categories(:child_2_1).parent
end

- (Object) test_parent_column_default



26
27
28
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 26

def test_parent_column_default
  assert_equal 'parent_id', Default.acts_as_nested_set_options[:parent_column]
end

- (Object) test_parent_column_name



44
45
46
47
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 44

def test_parent_column_name
  assert_equal 'parent_id', Default.parent_column_name
  assert_equal 'parent_id', Default.new.parent_column_name
end

- (Object) test_parent_column_protected_from_assignment



69
70
71
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 69

def test_parent_column_protected_from_assignment
  assert_raises(ActiveRecord::ActiveRecordError) { Category.new.parent_id = 1 }
end

- (Object) test_quoted_left_column_name



49
50
51
52
53
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 49

def test_quoted_left_column_name
  quoted = Default.connection.quote_column_name('lft')
  assert_equal quoted, Default.quoted_left_column_name
  assert_equal quoted, Default.new.quoted_left_column_name
end

- (Object) test_quoted_right_column_name



55
56
57
58
59
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 55

def test_quoted_right_column_name
  quoted = Default.connection.quote_column_name('rgt')
  assert_equal quoted, Default.quoted_right_column_name
  assert_equal quoted, Default.new.quoted_right_column_name
end

- (Object) test_quoting_of_multi_scope_column_names



590
591
592
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 590

def test_quoting_of_multi_scope_column_names
  assert_equal ["\"notable_id\"", "\"notable_type\""], Note.quoted_scope_column_names
end

- (Object) test_rebuild



462
463
464
465
466
467
468
469
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 462

def test_rebuild
  assert Category.valid?
  before_text = Category.root.to_text
  Category.update_all('lft = null, rgt = null')
  Category.rebuild!
  assert Category.valid?
  assert_equal before_text, Category.root.to_text
end

- (Object) test_right_column_default



22
23
24
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 22

def test_right_column_default
  assert_equal 'rgt', Default.acts_as_nested_set_options[:right_column]
end

- (Object) test_right_column_name



39
40
41
42
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 39

def test_right_column_name
  assert_equal 'rgt', Default.right_column_name
  assert_equal 'rgt', Default.new.right_column_name
end

- (Object) test_right_column_protected_from_assignment



65
66
67
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 65

def test_right_column_protected_from_assignment
  assert_raises(ActiveRecord::ActiveRecordError) { Category.new.rgt = 1 }
end

- (Object) test_right_sibling



279
280
281
282
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 279

def test_right_sibling
  assert_equal categories(:child_3), categories(:child_2).right_sibling
  assert_equal categories(:child_2), categories(:child_1).right_sibling
end

- (Object) test_right_sibling_of_rightmost_node



293
294
295
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 293

def test_right_sibling_of_rightmost_node
  assert_nil categories(:child_3).right_sibling
end

- (Object) test_right_sibling_of_root



284
285
286
287
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 284

def test_right_sibling_of_root
  assert_equal categories(:top_level_2), categories(:top_level).right_sibling
  assert_nil categories(:top_level_2).right_sibling
end

- (Object) test_right_sibling_without_siblings



289
290
291
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 289

def test_right_sibling_without_siblings
  assert_nil categories(:child_2_1).right_sibling
end

- (Object) test_root



92
93
94
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 92

def test_root
  assert_equal categories(:top_level), categories(:child_3).root
end

- (Boolean) test_root?

Returns:

  • (Boolean)


96
97
98
99
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 96

def test_root?
  assert categories(:top_level).root?
  assert categories(:top_level_2).root?
end

- (Object) test_root_class_method



88
89
90
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 88

def test_root_class_method
  assert_equal categories(:top_level), Category.root
end

- (Object) test_roots_class_method



84
85
86
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 84

def test_roots_class_method
  assert_equal Category.find_all_by_parent_id(nil), Category.roots
end

- (Boolean) test_same_scope?

Returns:

  • (Boolean)


254
255
256
257
258
259
260
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 254

def test_same_scope?
  root = Scoped.root
  child = root.children.first
  assert child.same_scope?(root)
  child.update_attribute :organization_id, 'different'
  assert !child.same_scope?(root)
end

- (Object) test_same_scope_with_multi_scopes



581
582
583
584
585
586
587
588
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 581

def test_same_scope_with_multi_scopes
  assert_nothing_raised do
    notes(:scope1).same_scope?(notes(:child_1))
  end
  assert notes(:scope1).same_scope?(notes(:child_1))
  assert notes(:child_1).same_scope?(notes(:scope1))
  assert !notes(:scope1).same_scope?(notes(:scope2))
end

- (Object) test_scope_default



30
31
32
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 30

def test_scope_default
  assert_nil Default.acts_as_nested_set_options[:scope]
end

- (Object) test_scoped_appends_id



80
81
82
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 80

def test_scoped_appends_id
  assert_equal :organization_id, Scoped.acts_as_nested_set_options[:scope]
end

- (Object) test_self_and_ancestors



124
125
126
127
128
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 124

def test_self_and_ancestors
  child = categories(:child_2_1)
  self_and_ancestors = [categories(:top_level), categories(:child_2), child]
  assert_equal self_and_ancestors, child.self_and_ancestors
end

- (Object) test_self_and_descendents



169
170
171
172
173
174
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 169

def test_self_and_descendents
  parent = categories(:top_level)
  descendants = [categories(:child_1), categories(:child_2),
    categories(:child_2_1), categories(:child_3)]
  assert_equal descendants, parent.descendants
end

- (Object) test_self_and_siblings



136
137
138
139
140
141
142
143
144
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 136

def test_self_and_siblings
  child = categories(:child_2)
  self_and_siblings = [categories(:child_1), child, categories(:child_3)]
  assert_equal self_and_siblings, child.self_and_siblings
  assert_nothing_raised do
    tops = [categories(:top_level), categories(:top_level_2)]
    assert_equal tops, categories(:top_level).self_and_siblings
  end
end

- (Object) test_siblings



146
147
148
149
150
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 146

def test_siblings
  child = categories(:child_2)
  siblings = [categories(:child_1), categories(:child_3)]
  assert_equal siblings, child.siblings
end

- (Object) test_slightly_difficult_move_to_child_of



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 364

def test_slightly_difficult_move_to_child_of
  assert_equal 11, categories(:top_level_2).left
  assert_equal 12, categories(:top_level_2).right
  
  # create a new top-level node and move single-node top-level tree inside it.
  new_top = Category.create(:name => 'New Top')
  assert_equal 13, new_top.left
  assert_equal 14, new_top.right
  
  categories(:top_level_2).move_to_child_of(new_top)
  
  assert Category.valid?
  assert_equal new_top.id, categories(:top_level_2).parent_id
  
  assert_equal 12, categories(:top_level_2).left
  assert_equal 13, categories(:top_level_2).right
  assert_equal 11, new_top.left
  assert_equal 14, new_top.right    
end

- (Object) test_subtree_move_to_child_of



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 347

def test_subtree_move_to_child_of
  assert_equal 4, categories(:child_2).left
  assert_equal 7, categories(:child_2).right
  
  assert_equal 2, categories(:child_1).left
  assert_equal 3, categories(:child_1).right
  
  categories(:child_2).move_to_child_of(categories(:child_1))
  assert Category.valid?
  assert_equal categories(:child_1).id, categories(:child_2).parent_id
  
  assert_equal 3, categories(:child_2).left
  assert_equal 6, categories(:child_2).right
  assert_equal 2, categories(:child_1).left
  assert_equal 7, categories(:child_1).right    
end

- (Object) test_valid_with_missing_intermediate_node



448
449
450
451
452
453
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 448

def test_valid_with_missing_intermediate_node
  # Even though child_2_1 will still exist, it is a sign of a sloppy delete, not an invalid tree.
  assert Category.valid?
  Category.delete(categories(:child_2).id)
  assert Category.valid?
end

- (Object) test_valid_with_null_lefts



436
437
438
439
440
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 436

def test_valid_with_null_lefts
  assert Category.valid?
  Category.update_all('lft = null')
  assert !Category.valid?
end

- (Object) test_valid_with_null_rights



442
443
444
445
446
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 442

def test_valid_with_null_rights
  assert Category.valid?
  Category.update_all('rgt = null')
  assert !Category.valid?
end

- (Object) test_valid_with_overlapping_and_rights



455
456
457
458
459
460
# File 'vendor/plugins/awesome_nested_set/test/awesome_nested_set_test.rb', line 455

def test_valid_with_overlapping_and_rights
  assert Category.valid?
  categories(:top_level_2)['lft'] = 0
  categories(:top_level_2).save
  assert !Category.valid?
end