Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 16 commits
  • 11 files changed
  • 0 comments
  • 7 contributors
May 12, 2011
Kevin Bullock use define_model_callbacks instead of define_callbacks
ActiveSupport::Callbacks.define_callbacks doesn't define the class
macros to create callbacks (anymore?). This means that in 2.0.0,
before_move, after_move, and around_move are missing.

ActiveModel::Callbacks.define_model_callbacks handles defining the
macros, and as a bonus adds the `:terminator` option itself.
8ca6491
May 28, 2011
Philip Arndt parndt Fix up usage of deprecated code (class_inheritable attributes). 5a54e47
Jul 01, 2011
scambra add inverse_of to associations to improve performance rendereing trees a73bd99
Jul 18, 2011
MarkusQ Cherry pick of row locking logic from vamosa's fork plus extention t…
…o set_default_left_and_right case (ANS issue #70)
0868405
Jul 31, 2011
Daniel Morrison danielmorrison Merge pull request #75 from parndt/patch-1
Fix up usage of deprecated code (class_inheritable attributes).
c2954b3
Philip Arndt parndt Merge pull request #80 from scambra/master
add inverse_of to associations
4a84a04
Aug 01, 2011
Philip Arndt parndt Merge remote-tracking branch 'krbullock/model-callbacks' f8f3d9a
Philip Arndt parndt Fix rdoc generation which was previously breaking on README which was…
… renamed to README.rdoc, updated README.rdoc to reflect SingletonMethods being gone now. (Related to Issue #77).
565c4fd
MarkusQ Resolve conflict between rails scope & sql ordering in race condition…
… patch
6bd7bdc
Aug 02, 2011
Philip Arndt parndt Merge remote-tracking branch 'MarkusQ/master' 92357ef
Philip Arndt parndt Allow options to be overridable and converted the lock code to ARel. (#… 75cfe90
Aug 22, 2011
Uģis Ozols ugisozols Convert Test::Unit assertions to RSpec matchers. 3f19d9a
Aug 25, 2011
Rahmat Budiharso rbudiharso modified helper to allow using array of objects as argument 4f7c7b3
Sep 03, 2011
Philip Arndt parndt This is what has been happening since 2.0.1, we're now moving to 2.0.2 99ddcfa
Sep 07, 2011
Philip Arndt parndt Ignore *.gem files and I am now authoring gems, just pushed 2.0.2 fc6bcdd
Philip Arndt parndt Merge remote-tracking branch 'rahmat-budiharso/master' fe6de6c
1  .gitignore
@@ -3,3 +3,4 @@ spec/debug.log
3 3 rdoc
4 4 coverage
5 5 pkg
  6 +*.gem
6 CHANGELOG
... ... @@ -1,3 +1,9 @@
  1 +2.0.2
  2 +* Fixed deprecation warning under Rails 3.1 [Philip Arndt]
  3 +* Converted Test::Unit matchers to RSpec. [Uģis Ozols]
  4 +* Added inverse_of to associations to improve performance rendering trees. [Sergio Cambra]
  5 +* Added row locking and fixed some race conditions. [Markus J. Q. Roberts]
  6 +
1 7 2.0.1
2 8 * Fixed a bug with move_to not using nested_set_scope [Andreas Sekine]
3 9
2  Gemfile.lock
... ... @@ -1,7 +1,7 @@
1 1 PATH
2 2 remote: .
3 3 specs:
4   - awesome_nested_set (2.0.1)
  4 + awesome_nested_set (2.0.2)
5 5 activerecord (>= 3.0.0)
6 6
7 7 GEM
2  README.rdoc
Source Rendered
@@ -39,7 +39,7 @@ Enable the nested set functionality by declaring acts_as_nested_set on your mode
39 39 acts_as_nested_set
40 40 end
41 41
42   -Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::Model::SingletonMethods for more info.
  42 +Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet for more info.
43 43
44 44 == Conversion from other trees
45 45
2  Rakefile
@@ -23,6 +23,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
23 23 rdoc.rdoc_dir = 'rdoc'
24 24 rdoc.title = 'AwesomeNestedSet'
25 25 rdoc.options << '--line-numbers' << '--inline-source'
26   - rdoc.rdoc_files.include('README')
  26 + rdoc.rdoc_files.include('README.rdoc')
27 27 rdoc.rdoc_files.include('lib/**/*.rb')
28 28 end
2  awesome_nested_set.gemspec
@@ -6,7 +6,7 @@ require 'awesome_nested_set/version'
6 6 Gem::Specification.new do |s|
7 7 s.name = %q{awesome_nested_set}
8 8 s.version = ::AwesomeNestedSet::VERSION
9   - s.authors = ["Brandon Keepers", "Daniel Morrison"]
  9 + s.authors = ["Brandon Keepers", "Daniel Morrison", "Philip Arndt"]
10 10 s.description = %q{An awesome nested set implementation for Active Record}
11 11 s.email = %q{info@collectiveidea.com}
12 12 s.extra_rdoc_files = [
26 lib/awesome_nested_set/awesome_nested_set.rb
@@ -51,8 +51,8 @@ def acts_as_nested_set(options = {})
51 51 options[:scope] = "#{options[:scope]}_id".intern
52 52 end
53 53
54   - write_inheritable_attribute :acts_as_nested_set_options, options
55   - class_inheritable_reader :acts_as_nested_set_options
  54 + class_attribute :acts_as_nested_set_options
  55 + self.acts_as_nested_set_options = options
56 56
57 57 include CollectiveIdea::Acts::NestedSet::Model
58 58 include Columns
@@ -60,9 +60,11 @@ def acts_as_nested_set(options = {})
60 60
61 61 belongs_to :parent, :class_name => self.base_class.to_s,
62 62 :foreign_key => parent_column_name,
63   - :counter_cache => options[:counter_cache]
  63 + :counter_cache => options[:counter_cache],
  64 + :inverse_of => :children
64 65 has_many :children, :class_name => self.base_class.to_s,
65   - :foreign_key => parent_column_name, :order => quoted_left_column_name
  66 + :foreign_key => parent_column_name, :order => quoted_left_column_name,
  67 + :inverse_of => :parent
66 68
67 69 attr_accessor :skip_before_destroy
68 70
@@ -88,7 +90,7 @@ def #{column}=(x)
88 90 scope :roots, where(parent_column_name => nil).order(quoted_left_column_name)
89 91 scope :leaves, where("#{quoted_right_column_name} - #{quoted_left_column_name} = 1").order(quoted_left_column_name)
90 92
91   - define_callbacks :move, :terminator => "result == false"
  93 + define_model_callbacks :move
92 94 end
93 95
94 96 module Model
@@ -382,8 +384,8 @@ def without_self(scope)
382 384 # All nested set queries should use this nested_set_scope, which performs finds on
383 385 # the base ActiveRecord class, using the :scope declared in the acts_as_nested_set
384 386 # declaration.
385   - def nested_set_scope
386   - options = {:order => quoted_left_column_name}
  387 + def nested_set_scope(options = {})
  388 + options = {:order => quoted_left_column_name}.merge(options)
387 389 scopes = Array(acts_as_nested_set_options[:scope])
388 390 options[:conditions] = scopes.inject({}) do |conditions,attr|
389 391 conditions.merge attr => self[attr]
@@ -406,7 +408,8 @@ def move_to_new_parent
406 408
407 409 # on creation, set automatically lft and rgt to the end of the tree
408 410 def set_default_left_and_right
409   - maxright = nested_set_scope.maximum(right_column_name) || 0
  411 + highest_right_row = nested_set_scope(:order => "#{quoted_right_column_name} desc").find(:first, :limit => 1,:lock => true )
  412 + maxright = highest_right_row ? highest_right_row[right_column_name] : 0
410 413 # adds the new node to the right of all existing nodes
411 414 self[left_column_name] = maxright + 1
412 415 self[right_column_name] = maxright + 2
@@ -490,6 +493,11 @@ def move_to(target, position)
490 493 # so sorting puts both the intervals and their boundaries in order
491 494 a, b, c, d = [self[left_column_name], self[right_column_name], bound, other_bound].sort
492 495
  496 + # select the rows in the model between a and d, and apply a lock
  497 + self.class.base_class.select('id').lock(true).where(
  498 + ["#{quoted_left_column_name} >= :a and #{quoted_right_column_name} <= :d", {:a => a, :d => d}]
  499 + )
  500 +
493 501 new_parent = case position
494 502 when :child; target.id
495 503 when :root; nil
@@ -561,4 +569,4 @@ def quoted_scope_column_names
561 569
562 570 end
563 571 end
564   -end
  572 +end
10 lib/awesome_nested_set/helper.rb
@@ -21,8 +21,12 @@ module Helper
21 21 # }) %>
22 22 #
23 23 def nested_set_options(class_or_item, mover = nil)
24   - class_or_item = class_or_item.roots if class_or_item.is_a?(Class)
25   - items = Array(class_or_item)
  24 + if class_or_item.is_a? Array
  25 + items = class_or_item.reject { |e| !e.root? }
  26 + else
  27 + class_or_item = class_or_item.roots if class_or_item.is_a?(Class)
  28 + items = Array(class_or_item)
  29 + end
26 30 result = []
27 31 items.each do |root|
28 32 result += root.self_and_descendants.map do |i|
@@ -37,4 +41,4 @@ def nested_set_options(class_or_item, mover = nil)
37 41 end
38 42 end
39 43 end
40   -end
  44 +end
2  lib/awesome_nested_set/version.rb
... ... @@ -1,3 +1,3 @@
1 1 module AwesomeNestedSet
2   - VERSION = '2.0.1' unless defined?(::AwesomeNestedSet::VERSION)
  2 + VERSION = '2.0.2' unless defined?(::AwesomeNestedSet::VERSION)
3 3 end
32 spec/awesome_nested_set/helper_spec.rb
@@ -8,7 +8,7 @@
8 8 end
9 9
10 10 describe "nested_set_options" do
11   - def test_nested_set_options
  11 + it "test_nested_set_options" do
12 12 expected = [
13 13 [" Top Level", 1],
14 14 ["- Child 1", 2],
@@ -23,7 +23,7 @@ def test_nested_set_options
23 23 actual.should == expected
24 24 end
25 25
26   - def test_nested_set_options_with_mover
  26 + it "test_nested_set_options_with_mover" do
27 27 expected = [
28 28 [" Top Level", 1],
29 29 ["- Child 1", 2],
@@ -35,5 +35,33 @@ def test_nested_set_options_with_mover
35 35 end
36 36 actual.should == expected
37 37 end
  38 +
  39 + it "test_nested_set_options_with_array_as_argument_without_mover" do
  40 + expected = [
  41 + [" Top Level", 1],
  42 + ["- Child 1", 2],
  43 + ['- Child 2', 3],
  44 + ['-- Child 2.1', 4],
  45 + ['- Child 3', 5],
  46 + [" Top Level 2", 6]
  47 + ]
  48 + actual = nested_set_options(Category.all) do |c|
  49 + "#{'-' * c.level} #{c.name}"
  50 + end
  51 + actual.should == expected
  52 + end
  53 +
  54 + it "test_nested_set_options_with_array_as_argument_with_mover" do
  55 + expected = [
  56 + [" Top Level", 1],
  57 + ["- Child 1", 2],
  58 + ['- Child 3', 5],
  59 + [" Top Level 2", 6]
  60 + ]
  61 + actual = nested_set_options(Category.all, categories(:child_2)) do |c|
  62 + "#{'-' * c.level} #{c.name}"
  63 + end
  64 + actual.should == expected
  65 + end
38 66 end
39 67 end
524 spec/awesome_nested_set_spec.rb
... ... @@ -1,11 +1,5 @@
1 1 require 'spec_helper'
2 2
3   -# these were copied from Test::Unit, so are named poorly.
4   -# Also, we're use Test::Unit's assertions until someone takes the time to remove them.
5   -# Patches welcome!
6   -require 'test/unit/assertions'
7   -include Test::Unit::Assertions
8   -
9 3 describe "AwesomeNestedSet" do
10 4 before(:all) do
11 5 self.class.fixtures :categories, :departments, :notes, :things
@@ -13,172 +7,176 @@
13 7
14 8 describe "defaults" do
15 9 it "should have left_column_default" do
16   - assert_equal 'lft', Default.acts_as_nested_set_options[:left_column]
  10 + Default.acts_as_nested_set_options[:left_column].should == 'lft'
17 11 end
18 12
19 13 it "should have right_column_default" do
20   - assert_equal 'rgt', Default.acts_as_nested_set_options[:right_column]
  14 + Default.acts_as_nested_set_options[:right_column].should == 'rgt'
21 15 end
22 16
23 17 it "should have parent_column_default" do
24   - assert_equal 'parent_id', Default.acts_as_nested_set_options[:parent_column]
  18 + Default.acts_as_nested_set_options[:parent_column].should == 'parent_id'
25 19 end
26 20
27 21 it "should have scope_default" do
28   - assert_nil Default.acts_as_nested_set_options[:scope]
  22 + Default.acts_as_nested_set_options[:scope].should be_nil
29 23 end
30 24
31 25 it "should have left_column_name" do
32   - assert_equal 'lft', Default.left_column_name
33   - assert_equal 'lft', Default.new.left_column_name
34   - assert_equal 'red', RenamedColumns.left_column_name
35   - assert_equal 'red', RenamedColumns.new.left_column_name
  26 + Default.left_column_name.should == 'lft'
  27 + Default.new.left_column_name.should == 'lft'
  28 + RenamedColumns.left_column_name.should == 'red'
  29 + RenamedColumns.new.left_column_name.should == 'red'
36 30 end
37 31
38 32 it "should have right_column_name" do
39   - assert_equal 'rgt', Default.right_column_name
40   - assert_equal 'rgt', Default.new.right_column_name
41   - assert_equal 'black', RenamedColumns.right_column_name
42   - assert_equal 'black', RenamedColumns.new.right_column_name
  33 + Default.right_column_name.should == 'rgt'
  34 + Default.new.right_column_name.should == 'rgt'
  35 + RenamedColumns.right_column_name.should == 'black'
  36 + RenamedColumns.new.right_column_name.should == 'black'
43 37 end
44 38
45 39 it "should have parent_column_name" do
46   - assert_equal 'parent_id', Default.parent_column_name
47   - assert_equal 'parent_id', Default.new.parent_column_name
48   - assert_equal 'mother_id', RenamedColumns.parent_column_name
49   - assert_equal 'mother_id', RenamedColumns.new.parent_column_name
  40 + Default.parent_column_name.should == 'parent_id'
  41 + Default.new.parent_column_name.should == 'parent_id'
  42 + RenamedColumns.parent_column_name.should == 'mother_id'
  43 + RenamedColumns.new.parent_column_name.should == 'mother_id'
50 44 end
51 45 end
52 46
53 47 it "creation_with_altered_column_names" do
54   - assert_nothing_raised do
  48 + lambda {
55 49 RenamedColumns.create!()
56   - end
  50 + }.should_not raise_exception
57 51 end
58 52
59 53 it "quoted_left_column_name" do
60 54 quoted = Default.connection.quote_column_name('lft')
61   - assert_equal quoted, Default.quoted_left_column_name
62   - assert_equal quoted, Default.new.quoted_left_column_name
  55 + Default.quoted_left_column_name.should == quoted
  56 + Default.new.quoted_left_column_name.should == quoted
63 57 end
64 58
65 59 it "quoted_right_column_name" do
66 60 quoted = Default.connection.quote_column_name('rgt')
67   - assert_equal quoted, Default.quoted_right_column_name
68   - assert_equal quoted, Default.new.quoted_right_column_name
  61 + Default.quoted_right_column_name.should == quoted
  62 + Default.new.quoted_right_column_name.should == quoted
69 63 end
70 64
71 65 it "left_column_protected_from_assignment" do
72   - assert_raises(ActiveRecord::ActiveRecordError) { Category.new.lft = 1 }
  66 + lambda {
  67 + Category.new.lft = 1
  68 + }.should raise_exception(ActiveRecord::ActiveRecordError)
73 69 end
74 70
75 71 it "right_column_protected_from_assignment" do
76   - assert_raises(ActiveRecord::ActiveRecordError) { Category.new.rgt = 1 }
  72 + lambda {
  73 + Category.new.rgt = 1
  74 + }.should raise_exception(ActiveRecord::ActiveRecordError)
77 75 end
78 76
79 77 it "colums_protected_on_initialize" do
80 78 c = Category.new(:lft => 1, :rgt => 2)
81   - assert_nil c.lft
82   - assert_nil c.rgt
  79 + c.lft.should be_nil
  80 + c.rgt.should be_nil
83 81 end
84 82
85 83 it "scoped_appends_id" do
86   - assert_equal :organization_id, ScopedCategory.acts_as_nested_set_options[:scope]
  84 + ScopedCategory.acts_as_nested_set_options[:scope].should == :organization_id
87 85 end
88 86
89 87 it "roots_class_method" do
90   - assert_equal Category.find_all_by_parent_id(nil), Category.roots
  88 + Category.roots.should == Category.find_all_by_parent_id(nil)
91 89 end
92 90
93 91 it "root_class_method" do
94   - assert_equal categories(:top_level), Category.root
  92 + Category.root.should == categories(:top_level)
95 93 end
96 94
97 95 it "root" do
98   - assert_equal categories(:top_level), categories(:child_3).root
  96 + categories(:child_3).root.should == categories(:top_level)
99 97 end
100 98
101 99 it "root?" do
102   - assert categories(:top_level).root?
103   - assert categories(:top_level_2).root?
  100 + categories(:top_level).root?.should be_true
  101 + categories(:top_level_2).root?.should be_true
104 102 end
105 103
106 104 it "leaves_class_method" do
107   - assert_equal Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1"), Category.leaves
108   - assert_equal Category.leaves.count, 4
109   - assert (Category.leaves.include? categories(:child_1))
110   - assert (Category.leaves.include? categories(:child_2_1))
111   - assert (Category.leaves.include? categories(:child_3))
112   - assert (Category.leaves.include? categories(:top_level_2))
  105 + Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1").should == Category.leaves
  106 + Category.leaves.count.should == 4
  107 + Category.leaves.should include(categories(:child_1))
  108 + Category.leaves.should include(categories(:child_2_1))
  109 + Category.leaves.should include(categories(:child_3))
  110 + Category.leaves.should include(categories(:top_level_2))
113 111 end
114 112
115 113 it "leaf" do
116   - assert categories(:child_1).leaf?
117   - assert categories(:child_2_1).leaf?
118   - assert categories(:child_3).leaf?
119   - assert categories(:top_level_2).leaf?
  114 + categories(:child_1).leaf?.should be_true
  115 + categories(:child_2_1).leaf?.should be_true
  116 + categories(:child_3).leaf?.should be_true
  117 + categories(:top_level_2).leaf?.should be_true
120 118
121   - assert !categories(:top_level).leaf?
122   - assert !categories(:child_2).leaf?
123   - assert !Category.new.leaf?
  119 + categories(:top_level).leaf?.should be_false
  120 + categories(:child_2).leaf?.should be_false
  121 + Category.new.leaf?.should be_false
124 122 end
125 123
126 124
127 125 it "parent" do
128   - assert_equal categories(:child_2), categories(:child_2_1).parent
  126 + categories(:child_2_1).parent.should == categories(:child_2)
129 127 end
130 128
131 129 it "self_and_ancestors" do
132 130 child = categories(:child_2_1)
133 131 self_and_ancestors = [categories(:top_level), categories(:child_2), child]
134   - assert_equal self_and_ancestors, child.self_and_ancestors
  132 + self_and_ancestors.should == child.self_and_ancestors
135 133 end
136 134
137 135 it "ancestors" do
138 136 child = categories(:child_2_1)
139 137 ancestors = [categories(:top_level), categories(:child_2)]
140   - assert_equal ancestors, child.ancestors
  138 + ancestors.should == child.ancestors
141 139 end
142 140
143 141 it "self_and_siblings" do
144 142 child = categories(:child_2)
145 143 self_and_siblings = [categories(:child_1), child, categories(:child_3)]
146   - assert_equal self_and_siblings, child.self_and_siblings
147   - assert_nothing_raised do
  144 + self_and_siblings.should == child.self_and_siblings
  145 + lambda do
148 146 tops = [categories(:top_level), categories(:top_level_2)]
149 147 assert_equal tops, categories(:top_level).self_and_siblings
150   - end
  148 + end.should_not raise_exception
151 149 end
152 150
153 151 it "siblings" do
154 152 child = categories(:child_2)
155 153 siblings = [categories(:child_1), categories(:child_3)]
156   - assert_equal siblings, child.siblings
  154 + siblings.should == child.siblings
157 155 end
158 156
159 157 it "leaves" do
160 158 leaves = [categories(:child_1), categories(:child_2_1), categories(:child_3)]
161   - assert_equal categories(:top_level).leaves, leaves
  159 + categories(:top_level).leaves.should == leaves
162 160 end
163 161
164 162 it "level" do
165   - assert_equal 0, categories(:top_level).level
166   - assert_equal 1, categories(:child_1).level
167   - assert_equal 2, categories(:child_2_1).level
  163 + categories(:top_level).level.should == 0
  164 + categories(:child_1).level.should == 1
  165 + categories(:child_2_1).level.should == 2
168 166 end
169 167
170 168 it "has_children?" do
171   - assert categories(:child_2_1).children.empty?
172   - assert !categories(:child_2).children.empty?
173   - assert !categories(:top_level).children.empty?
  169 + categories(:child_2_1).children.empty?.should be_true
  170 + categories(:child_2).children.empty?.should be_false
  171 + categories(:top_level).children.empty?.should be_false
174 172 end
175 173
176 174 it "self_and_descendents" do
177 175 parent = categories(:top_level)
178 176 self_and_descendants = [parent, categories(:child_1), categories(:child_2),
179 177 categories(:child_2_1), categories(:child_3)]
180   - assert_equal self_and_descendants, parent.self_and_descendants
181   - assert_equal self_and_descendants.count, parent.self_and_descendants.count
  178 + self_and_descendants.should == parent.self_and_descendants
  179 + self_and_descendants.count.should == parent.self_and_descendants.count
182 180 end
183 181
184 182 it "descendents" do
@@ -189,229 +187,229 @@
189 187 patent.move_to_child_of(us)
190 188 lawyers.reload
191 189
192   - assert_equal 1, lawyers.children.size
193   - assert_equal 1, us.children.size
194   - assert_equal 2, lawyers.descendants.size
  190 + lawyers.children.size.should == 1
  191 + us.children.size.should == 1
  192 + lawyers.descendants.size.should == 2
195 193 end
196 194
197 195 it "self_and_descendents" do
198 196 parent = categories(:top_level)
199 197 descendants = [categories(:child_1), categories(:child_2),
200 198 categories(:child_2_1), categories(:child_3)]
201   - assert_equal descendants, parent.descendants
  199 + descendants.should == parent.descendants
202 200 end
203 201
204 202 it "children" do
205 203 category = categories(:top_level)
206   - category.children.each {|c| assert_equal category.id, c.parent_id }
  204 + category.children.each {|c| category.id.should == c.parent_id }
207 205 end
208 206
209 207 it "order_of_children" do
210 208 categories(:child_2).move_left
211   - assert_equal categories(:child_2), categories(:top_level).children[0]
212   - assert_equal categories(:child_1), categories(:top_level).children[1]
213   - assert_equal categories(:child_3), categories(:top_level).children[2]
  209 + categories(:child_2).should == categories(:top_level).children[0]
  210 + categories(:child_1).should == categories(:top_level).children[1]
  211 + categories(:child_3).should == categories(:top_level).children[2]
214 212 end
215 213
216 214 it "is_or_is_ancestor_of?" do
217   - assert categories(:top_level).is_or_is_ancestor_of?(categories(:child_1))
218   - assert categories(:top_level).is_or_is_ancestor_of?(categories(:child_2_1))
219   - assert categories(:child_2).is_or_is_ancestor_of?(categories(:child_2_1))
220   - assert !categories(:child_2_1).is_or_is_ancestor_of?(categories(:child_2))
221   - assert !categories(:child_1).is_or_is_ancestor_of?(categories(:child_2))
222   - assert categories(:child_1).is_or_is_ancestor_of?(categories(:child_1))
  215 + categories(:top_level).is_or_is_ancestor_of?(categories(:child_1)).should be_true
  216 + categories(:top_level).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
  217 + categories(:child_2).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
  218 + categories(:child_2_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
  219 + categories(:child_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
  220 + categories(:child_1).is_or_is_ancestor_of?(categories(:child_1)).should be_true
223 221 end
224 222
225 223 it "is_ancestor_of?" do
226   - assert categories(:top_level).is_ancestor_of?(categories(:child_1))
227   - assert categories(:top_level).is_ancestor_of?(categories(:child_2_1))
228   - assert categories(:child_2).is_ancestor_of?(categories(:child_2_1))
229   - assert !categories(:child_2_1).is_ancestor_of?(categories(:child_2))
230   - assert !categories(:child_1).is_ancestor_of?(categories(:child_2))
231   - assert !categories(:child_1).is_ancestor_of?(categories(:child_1))
  224 + categories(:top_level).is_ancestor_of?(categories(:child_1)).should be_true
  225 + categories(:top_level).is_ancestor_of?(categories(:child_2_1)).should be_true
  226 + categories(:child_2).is_ancestor_of?(categories(:child_2_1)).should be_true
  227 + categories(:child_2_1).is_ancestor_of?(categories(:child_2)).should be_false
  228 + categories(:child_1).is_ancestor_of?(categories(:child_2)).should be_false
  229 + categories(:child_1).is_ancestor_of?(categories(:child_1)).should be_false
232 230 end
233 231
234 232 it "is_or_is_ancestor_of_with_scope" do
235 233 root = ScopedCategory.root
236 234 child = root.children.first
237   - assert root.is_or_is_ancestor_of?(child)
  235 + root.is_or_is_ancestor_of?(child).should be_true
238 236 child.update_attribute :organization_id, 'different'
239   - assert !root.is_or_is_ancestor_of?(child)
  237 + root.is_or_is_ancestor_of?(child).should be_false
240 238 end
241 239
242 240 it "is_or_is_descendant_of?" do
243   - assert categories(:child_1).is_or_is_descendant_of?(categories(:top_level))
244   - assert categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level))
245   - assert categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2))
246   - assert !categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1))
247   - assert !categories(:child_2).is_or_is_descendant_of?(categories(:child_1))
248   - assert categories(:child_1).is_or_is_descendant_of?(categories(:child_1))
  241 + categories(:child_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
  242 + categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
  243 + categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2)).should be_true
  244 + categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1)).should be_false
  245 + categories(:child_2).is_or_is_descendant_of?(categories(:child_1)).should be_false
  246 + categories(:child_1).is_or_is_descendant_of?(categories(:child_1)).should be_true
249 247 end
250 248
251 249 it "is_descendant_of?" do
252   - assert categories(:child_1).is_descendant_of?(categories(:top_level))
253   - assert categories(:child_2_1).is_descendant_of?(categories(:top_level))
254   - assert categories(:child_2_1).is_descendant_of?(categories(:child_2))
255   - assert !categories(:child_2).is_descendant_of?(categories(:child_2_1))
256   - assert !categories(:child_2).is_descendant_of?(categories(:child_1))
257   - assert !categories(:child_1).is_descendant_of?(categories(:child_1))
  250 + categories(:child_1).is_descendant_of?(categories(:top_level)).should be_true
  251 + categories(:child_2_1).is_descendant_of?(categories(:top_level)).should be_true
  252 + categories(:child_2_1).is_descendant_of?(categories(:child_2)).should be_true
  253 + categories(:child_2).is_descendant_of?(categories(:child_2_1)).should be_false
  254 + categories(:child_2).is_descendant_of?(categories(:child_1)).should be_false
  255 + categories(:child_1).is_descendant_of?(categories(:child_1)).should be_false
258 256 end
259 257
260 258 it "is_or_is_descendant_of_with_scope" do
261 259 root = ScopedCategory.root
262 260 child = root.children.first
263   - assert child.is_or_is_descendant_of?(root)
  261 + child.is_or_is_descendant_of?(root).should be_true
264 262 child.update_attribute :organization_id, 'different'
265   - assert !child.is_or_is_descendant_of?(root)
  263 + child.is_or_is_descendant_of?(root).should be_false
266 264 end
267 265
268 266 it "same_scope?" do
269 267 root = ScopedCategory.root
270 268 child = root.children.first
271   - assert child.same_scope?(root)
  269 + child.same_scope?(root).should be_true
272 270 child.update_attribute :organization_id, 'different'
273   - assert !child.same_scope?(root)
  271 + child.same_scope?(root).should be_false
274 272 end
275 273
276 274 it "left_sibling" do
277   - assert_equal categories(:child_1), categories(:child_2).left_sibling
278   - assert_equal categories(:child_2), categories(:child_3).left_sibling
  275 + categories(:child_1).should == categories(:child_2).left_sibling
  276 + categories(:child_2).should == categories(:child_3).left_sibling
279 277 end
280 278
281 279 it "left_sibling_of_root" do
282   - assert_nil categories(:top_level).left_sibling
  280 + categories(:top_level).left_sibling.should be_nil
283 281 end
284 282
285 283 it "left_sibling_without_siblings" do
286   - assert_nil categories(:child_2_1).left_sibling
  284 + categories(:child_2_1).left_sibling.should be_nil
287 285 end
288 286
289 287 it "left_sibling_of_leftmost_node" do
290   - assert_nil categories(:child_1).left_sibling
  288 + categories(:child_1).left_sibling.should be_nil
291 289 end
292 290
293 291 it "right_sibling" do
294   - assert_equal categories(:child_3), categories(:child_2).right_sibling
295   - assert_equal categories(:child_2), categories(:child_1).right_sibling
  292 + categories(:child_3).should == categories(:child_2).right_sibling
  293 + categories(:child_2).should == categories(:child_1).right_sibling
296 294 end
297 295
298 296 it "right_sibling_of_root" do
299   - assert_equal categories(:top_level_2), categories(:top_level).right_sibling
300   - assert_nil categories(:top_level_2).right_sibling
  297 + categories(:top_level_2).should == categories(:top_level).right_sibling
  298 + categories(:top_level_2).right_sibling.should be_nil
301 299 end
302 300
303 301 it "right_sibling_without_siblings" do
304   - assert_nil categories(:child_2_1).right_sibling
  302 + categories(:child_2_1).right_sibling.should be_nil
305 303 end
306 304
307 305 it "right_sibling_of_rightmost_node" do
308   - assert_nil categories(:child_3).right_sibling
  306 + categories(:child_3).right_sibling.should be_nil
309 307 end
310 308
311 309 it "move_left" do
312 310 categories(:child_2).move_left
313   - assert_nil categories(:child_2).left_sibling
314   - assert_equal categories(:child_1), categories(:child_2).right_sibling
315   - assert Category.valid?
  311 + categories(:child_2).left_sibling.should be_nil
  312 + categories(:child_1).should == categories(:child_2).right_sibling
  313 + Category.valid?.should be_true
316 314 end
317 315
318 316 it "move_right" do
319 317 categories(:child_2).move_right
320   - assert_nil categories(:child_2).right_sibling
321   - assert_equal categories(:child_3), categories(:child_2).left_sibling
322   - assert Category.valid?
  318 + categories(:child_2).right_sibling.should be_nil
  319 + categories(:child_3).should == categories(:child_2).left_sibling
  320 + Category.valid?.should be_true
323 321 end
324 322
325 323 it "move_to_left_of" do
326 324 categories(:child_3).move_to_left_of(categories(:child_1))
327   - assert_nil categories(:child_3).left_sibling
328   - assert_equal categories(:child_1), categories(:child_3).right_sibling
329   - assert Category.valid?
  325 + categories(:child_3).left_sibling.should be_nil
  326 + categories(:child_1).should == categories(:child_3).right_sibling
  327 + Category.valid?.should be_true
330 328 end
331 329
332 330 it "move_to_right_of" do
333 331 categories(:child_1).move_to_right_of(categories(:child_3))
334   - assert_nil categories(:child_1).right_sibling
335   - assert_equal categories(:child_3), categories(:child_1).left_sibling
336   - assert Category.valid?
  332 + categories(:child_1).right_sibling.should be_nil
  333 + categories(:child_3).should == categories(:child_1).left_sibling
  334 + Category.valid?.should be_true
337 335 end
338 336
339 337 it "move_to_root" do
340 338 categories(:child_2).move_to_root
341   - assert_nil categories(:child_2).parent
342   - assert_equal 0, categories(:child_2).level
343   - assert_equal 1, categories(:child_2_1).level
344   - assert_equal 1, categories(:child_2).left
345   - assert_equal 4, categories(:child_2).right
346   - assert Category.valid?
  339 + categories(:child_2).parent.should be_nil
  340 + categories(:child_2).level.should == 0
  341 + categories(:child_2_1).level.should == 1
  342 + categories(:child_2).left.should == 1
  343 + categories(:child_2).right.should == 4
  344 + Category.valid?.should be_true
347 345 end
348 346
349 347 it "move_to_child_of" do
350 348 categories(:child_1).move_to_child_of(categories(:child_3))
351   - assert_equal categories(:child_3).id, categories(:child_1).parent_id
352   - assert Category.valid?
  349 + categories(:child_3).id.should == categories(:child_1).parent_id
  350 + Category.valid?.should be_true
353 351 end
354 352
355 353 it "move_to_child_of_appends_to_end" do
356 354 child = Category.create! :name => 'New Child'
357 355 child.move_to_child_of categories(:top_level)
358   - assert_equal child, categories(:top_level).children.last
  356 + child.should == categories(:top_level).children.last
359 357 end
360 358
361 359 it "subtree_move_to_child_of" do
362   - assert_equal 4, categories(:child_2).left
363   - assert_equal 7, categories(:child_2).right
  360 + categories(:child_2).left.should == 4
  361 + categories(:child_2).right.should == 7
364 362
365   - assert_equal 2, categories(:child_1).left
366   - assert_equal 3, categories(:child_1).right
  363 + categories(:child_1).left.should == 2
  364 + categories(:child_1).right.should == 3
367 365
368 366 categories(:child_2).move_to_child_of(categories(:child_1))
369   - assert Category.valid?
370   - assert_equal categories(:child_1).id, categories(:child_2).parent_id
  367 + Category.valid?.should be_true
  368 + categories(:child_1).id.should == categories(:child_2).parent_id
371 369
372   - assert_equal 3, categories(:child_2).left
373   - assert_equal 6, categories(:child_2).right
374   - assert_equal 2, categories(:child_1).left
375   - assert_equal 7, categories(:child_1).right
  370 + categories(:child_2).left.should == 3
  371 + categories(:child_2).right.should == 6
  372 + categories(:child_1).left.should == 2
  373 + categories(:child_1).right.should == 7
376 374 end
377 375
378 376 it "slightly_difficult_move_to_child_of" do
379   - assert_equal 11, categories(:top_level_2).left
380   - assert_equal 12, categories(:top_level_2).right
  377 + categories(:top_level_2).left.should == 11
  378 + categories(:top_level_2).right.should == 12
381 379
382 380 # create a new top-level node and move single-node top-level tree inside it.
383 381 new_top = Category.create(:name => 'New Top')
384   - assert_equal 13, new_top.left
385   - assert_equal 14, new_top.right
  382 + new_top.left.should == 13
  383 + new_top.right.should == 14
386 384
387 385 categories(:top_level_2).move_to_child_of(new_top)
388 386
389   - assert Category.valid?
390   - assert_equal new_top.id, categories(:top_level_2).parent_id
  387 + Category.valid?.should be_true
  388 + new_top.id.should == categories(:top_level_2).parent_id
391 389
392   - assert_equal 12, categories(:top_level_2).left
393   - assert_equal 13, categories(:top_level_2).right
394   - assert_equal 11, new_top.left
395   - assert_equal 14, new_top.right
  390 + categories(:top_level_2).left.should == 12
  391 + categories(:top_level_2).right.should == 13
  392 + new_top.left.should == 11
  393 + new_top.right.should == 14
396 394 end
397 395
398 396 it "difficult_move_to_child_of" do
399   - assert_equal 1, categories(:top_level).left
400   - assert_equal 10, categories(:top_level).right
401   - assert_equal 5, categories(:child_2_1).left
402   - assert_equal 6, categories(:child_2_1).right
  397 + categories(:top_level).left.should == 1
  398 + categories(:top_level).right.should == 10
  399 + categories(:child_2_1).left.should == 5
  400 + categories(:child_2_1).right.should == 6
403 401
404 402 # create a new top-level node and move an entire top-level tree inside it.
405 403 new_top = Category.create(:name => 'New Top')
406 404 categories(:top_level).move_to_child_of(new_top)
407 405 categories(:child_2_1).reload
408   - assert Category.valid?
409   - assert_equal new_top.id, categories(:top_level).parent_id
  406 + Category.valid?.should be_true
  407 + new_top.id.should == categories(:top_level).parent_id
410 408
411   - assert_equal 4, categories(:top_level).left
412   - assert_equal 13, categories(:top_level).right
413   - assert_equal 8, categories(:child_2_1).left
414   - assert_equal 9, categories(:child_2_1).right
  409 + categories(:top_level).left.should == 4
  410 + categories(:top_level).right.should == 13
  411 + categories(:child_2_1).left.should == 8
  412 + categories(:child_2_1).right.should == 9
415 413 end
416 414
417 415 #rebuild swaps the position of the 2 children when added using move_to_child twice onto same parent
@@ -427,7 +425,7 @@
427 425 Category.update_all('lft = null, rgt = null')
428 426 Category.rebuild!
429 427
430   - assert_equal Category.roots.last.to_text, output
  428 + Category.roots.last.to_text.should == output
431 429 end
432 430
433 431 # doing move_to_child twice onto same parent from the furthest right first
@@ -443,7 +441,7 @@
443 441 Category.update_all('lft = null, rgt = null')
444 442 Category.rebuild!
445 443
446   - assert_equal Category.roots.last.to_text, output
  444 + Category.roots.last.to_text.should == output
447 445 end
448 446
449 447 it "should be able to rebuild without validating each record" do
@@ -461,99 +459,99 @@
461 459 Category.update_all('lft = null, rgt = null')
462 460 Category.rebuild!(false)
463 461
464   - assert_equal Category.roots.last.to_text, output
  462 + Category.roots.last.to_text.should == output
465 463 end
466 464
467 465 it "valid_with_null_lefts" do
468   - assert Category.valid?
  466 + Category.valid?.should be_true
469 467 Category.update_all('lft = null')
470   - assert !Category.valid?
  468 + Category.valid?.should be_false
471 469 end
472 470
473 471 it "valid_with_null_rights" do
474   - assert Category.valid?
  472 + Category.valid?.should be_true
475 473 Category.update_all('rgt = null')
476   - assert !Category.valid?
  474 + Category.valid?.should be_false
477 475 end
478 476
479 477 it "valid_with_missing_intermediate_node" do
480 478 # Even though child_2_1 will still exist, it is a sign of a sloppy delete, not an invalid tree.
481   - assert Category.valid?
  479 + Category.valid?.should be_true
482 480 Category.delete(categories(:child_2).id)
483   - assert Category.valid?
  481 + Category.valid?.should be_true
484 482 end
485 483
486 484 it "valid_with_overlapping_and_rights" do
487   - assert Category.valid?
  485 + Category.valid?.should be_true
488 486 categories(:top_level_2)['lft'] = 0
489 487 categories(:top_level_2).save
490   - assert !Category.valid?
  488 + Category.valid?.should be_false
491 489 end
492 490
493 491 it "rebuild" do
494   - assert Category.valid?
  492 + Category.valid?.should be_true
495 493 before_text = Category.root.to_text
496 494 Category.update_all('lft = null, rgt = null')
497 495 Category.rebuild!
498   - assert Category.valid?
499   - assert_equal before_text, Category.root.to_text
  496 + Category.valid?.should be_true
  497 + before_text.should == Category.root.to_text
500 498 end
501 499
502 500 it "move_possible_for_sibling" do
503   - assert categories(:child_2).move_possible?(categories(:child_1))
  501 + categories(:child_2).move_possible?(categories(:child_1)).should be_true
504 502 end
505 503
506 504 it "move_not_possible_to_self" do
507   - assert !categories(:top_level).move_possible?(categories(:top_level))
  505 + categories(:top_level).move_possible?(categories(:top_level)).should be_false
508 506 end
509 507
510 508 it "move_not_possible_to_parent" do
511 509 categories(:top_level).descendants.each do |descendant|
512   - assert !categories(:top_level).move_possible?(descendant)
513   - assert descendant.move_possible?(categories(:top_level))
  510 + categories(:top_level).move_possible?(descendant).should be_false
  511 + descendant.move_possible?(categories(:top_level)).should be_true
514 512 end
515 513 end
516 514
517 515 it "is_or_is_ancestor_of?" do
518 516 [:child_1, :child_2, :child_2_1, :child_3].each do |c|
519   - assert categories(:top_level).is_or_is_ancestor_of?(categories(c))
  517 + categories(:top_level).is_or_is_ancestor_of?(categories(c)).should be_true
520 518 end
521   - assert !categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2))
  519 + categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2)).should be_false
522 520 end
523 521
524 522 it "left_and_rights_valid_with_blank_left" do
525   - assert Category.left_and_rights_valid?
  523 + Category.left_and_rights_valid?.should be_true
526 524 categories(:child_2)[:lft] = nil
527 525 categories(:child_2).save(:validate => false)
528   - assert !Category.left_and_rights_valid?
  526 + Category.left_and_rights_valid?.should be_false
529 527 end
530 528
531 529 it "left_and_rights_valid_with_blank_right" do
532   - assert Category.left_and_rights_valid?
  530 + Category.left_and_rights_valid?.should be_true
533 531 categories(:child_2)[:rgt] = nil
534 532 categories(:child_2).save(:validate => false)
535   - assert !Category.left_and_rights_valid?
  533 + Category.left_and_rights_valid?.should be_false
536 534 end
537 535
538 536 it "left_and_rights_valid_with_equal" do
539   - assert Category.left_and_rights_valid?
  537 + Category.left_and_rights_valid?.should be_true
540 538 categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]
541 539 categories(:top_level_2).save(:validate => false)
542   - assert !Category.left_and_rights_valid?
  540 + Category.left_and_rights_valid?.should be_false
543 541 end
544 542
545 543 it "left_and_rights_valid_with_left_equal_to_parent" do
546   - assert Category.left_and_rights_valid?
  544 + Category.left_and_rights_valid?.should be_true
547 545 categories(:child_2)[:lft] = categories(:top_level)[:lft]
548 546 categories(:child_2).save(:validate => false)
549   - assert !Category.left_and_rights_valid?
  547 + Category.left_and_rights_valid?.should be_false
550 548 end
551 549
552 550 it "left_and_rights_valid_with_right_equal_to_parent" do
553   - assert Category.left_and_rights_valid?
  551 + Category.left_and_rights_valid?.should be_true
554 552 categories(:child_2)[:rgt] = categories(:top_level)[:rgt]
555 553 categories(:child_2).save(:validate => false)
556   - assert !Category.left_and_rights_valid?
  554 + Category.left_and_rights_valid?.should be_false
557 555 end
558 556
559 557 it "moving_dirty_objects_doesnt_invalidate_tree" do
@@ -564,25 +562,25 @@
564 562 nodes = [r1, r2, r3, r4]
565 563
566 564 r2.move_to_child_of(r1)
567   - assert Category.valid?
  565 + Category.valid?.should be_true
568 566
569 567 r3.move_to_child_of(r1)
570   - assert Category.valid?
  568 + Category.valid?.should be_true
571 569
572 570 r4.move_to_child_of(r2)
573   - assert Category.valid?
  571 + Category.valid?.should be_true
574 572 end
575 573
576 574 it "multi_scoped_no_duplicates_for_columns?" do
577   - assert_nothing_raised do
  575 + lambda {
578 576 Note.no_duplicates_for_columns?
579   - end
  577 + }.should_not raise_exception
580 578 end
581 579
582 580 it "multi_scoped_all_roots_valid?" do
583   - assert_nothing_raised do
  581 + lambda {
584 582 Note.all_roots_valid?
585   - end
  583 + }.should_not raise_exception
586 584 end
587 585
588 586 it "multi_scoped" do
@@ -590,8 +588,8 @@
590 588 note2 = Note.create!(:body => "B", :notable_id => 2, :notable_type => 'Category')
591 589 note3 = Note.create!(:body => "C", :notable_id => 2, :notable_type => 'Default')
592 590
593   - assert_equal [note1, note2], note1.self_and_siblings
594   - assert_equal [note3], note3.self_and_siblings
  591 + [note1, note2].should == note1.self_and_siblings
  592 + [note3].should == note3.self_and_siblings
595 593 end
596 594
597 595 it "multi_scoped_rebuild" do
@@ -605,26 +603,26 @@
605 603 Note.update_all('lft = null, rgt = null')
606 604 Note.rebuild!
607 605
608   - assert_equal Note.roots.find_by_body('A'), root
609   - assert_equal [child1, child2], Note.roots.find_by_body('A').children
  606 + Note.roots.find_by_body('A').should == root
  607 + [child1, child2].should == Note.roots.find_by_body('A').children
610 608 end
611 609
612 610 it "same_scope_with_multi_scopes" do
613   - assert_nothing_raised do
  611 + lambda {
614 612 notes(:scope1).same_scope?(notes(:child_1))
615   - end
616   - assert notes(:scope1).same_scope?(notes(:child_1))
617   - assert notes(:child_1).same_scope?(notes(:scope1))
618   - assert !notes(:scope1).same_scope?(notes(:scope2))
  613 + }.should_not raise_exception
  614 + notes(:scope1).same_scope?(notes(:child_1)).should be_true
  615 + notes(:child_1).same_scope?(notes(:scope1)).should be_true
  616 + notes(:scope1).same_scope?(notes(:scope2)).should be_false
619 617 end
620 618
621 619 it "quoting_of_multi_scope_column_names" do
622   - assert_equal ["\"notable_id\"", "\"notable_type\""], Note.quoted_scope_column_names
  620 + ["\"notable_id\"", "\"notable_type\""].should == Note.quoted_scope_column_names
623 621 end
624 622
625 623 it "equal_in_same_scope" do
626   - assert_equal notes(:scope1), notes(:scope1)
627   - assert_not_equal notes(:scope1), notes(:child_1)
  624 + notes(:scope1).should == notes(:scope1)
  625 + notes(:scope1).should_not == notes(:child_1)
628 626 end
629 627
630 628 it "equal_in_different_scopes" do
@@ -634,47 +632,47 @@
634 632 it "delete_does_not_invalidate" do
635 633 Category.acts_as_nested_set_options[:dependent] = :delete
636 634 categories(:child_2).destroy
637   - assert Category.valid?
  635 + Category.valid?.should be_true
638 636 end
639 637
640 638 it "destroy_does_not_invalidate" do
641 639 Category.acts_as_nested_set_options[:dependent] = :destroy
642 640 categories(:child_2).destroy
643   - assert Category.valid?
  641 + Category.valid?.should be_true
644 642 end
645 643
646 644 it "destroy_multiple_times_does_not_invalidate" do
647 645 Category.acts_as_nested_set_options[:dependent] = :destroy
648 646 categories(:child_2).destroy
649 647 categories(:child_2).destroy
650   - assert Category.valid?
  648 + Category.valid?.should be_true
651 649 end
652 650
653 651 it "assigning_parent_id_on_create" do
654 652 category = Category.create!(:name => "Child", :parent_id => categories(:child_2).id)
655   - assert_equal categories(:child_2), category.parent
656   - assert_equal categories(:child_2).id, category.parent_id
657   - assert_not_nil category.left
658   - assert_not_nil category.right
659   - assert Category.valid?
  653 + categories(:child_2).should == category.parent
  654 + categories(:child_2).id.should == category.parent_id
  655 + category.left.should_not be_nil
  656 + category.right.should_not be_nil
  657 + Category.valid?.should be_true
660 658 end
661 659
662 660 it "assigning_parent_on_create" do
663 661 category = Category.create!(:name => "Child", :parent => categories(:child_2))
664   - assert_equal categories(:child_2), category.parent
665   - assert_equal categories(:child_2).id, category.parent_id
666   - assert_not_nil category.left
667   - assert_not_nil category.right
668   - assert Category.valid?
  662 + categories(:child_2).should == category.parent
  663 + categories(:child_2).id.should == category.parent_id
  664 + category.left.should_not be_nil
  665 + category.right.should_not be_nil
  666 + Category.valid?.should be_true
669 667 end
670 668
671 669 it "assigning_parent_id_to_nil_on_create" do
672 670 category = Category.create!(:name => "New Root", :parent_id => nil)
673   - assert_nil category.parent
674   - assert_nil category.parent_id
675   - assert_not_nil category.left
676   - assert_not_nil category.right
677   - assert Category.valid?
  671 + category.parent.should be_nil
  672 + category.parent_id.should be_nil
  673 + category.left.should_not be_nil
  674 + category.right.should_not be_nil
  675 + Category.valid?.should be_true
678 676 end
679 677
680 678 it "assigning_parent_id_on_update" do
@@ -683,9 +681,9 @@
683 681 category.save
684 682 category.reload
685 683 categories(:child_3).reload
686   - assert_equal categories(:child_3), category.parent
687   - assert_equal categories(:child_3).id, category.parent_id
688   - assert Category.valid?
  684 + categories(:child_3).should == category.parent
  685 + categories(:child_3).id.should == category.parent_id
  686 + Category.valid?.should be_true
689 687 end
690 688
691 689 it "assigning_parent_on_update" do
@@ -694,35 +692,35 @@
694 692 category.save
695 693 category.reload
696 694 categories(:child_3).reload
697   - assert_equal categories(:child_3), category.parent
698   - assert_equal categories(:child_3).id, category.parent_id
699   - assert Category.valid?
  695 + categories(:child_3).should == category.parent
  696 + categories(:child_3).id.should == category.parent_id
  697 + Category.valid?.should be_true
700 698 end
701 699
702 700 it "assigning_parent_id_to_nil_on_update" do
703 701 category = categories(:child_2_1)
704 702 category.parent_id = nil
705 703 category.save
706   - assert_nil category.parent
707   - assert_nil category.parent_id
708   - assert Category.valid?
  704 + category.parent.should be_nil
  705 + category.parent_id.should be_nil
  706 + Category.valid?.should be_true
709 707 end
710 708
711 709 it "creating_child_from_parent" do
712 710 category = categories(:child_2).children.create!(:name => "Child")
713   - assert_equal categories(:child_2), category.parent
714   - assert_equal categories(:child_2).id, category.parent_id
715   - assert_not_nil category.left
716   - assert_not_nil category.right
717   - assert Category.valid?
  711 + categories(:child_2).should == category.parent
  712 + categories(:child_2).id.should == category.parent_id
  713 + category.left.should_not be_nil
  714 + category.right.should_not be_nil
  715 + Category.valid?.should be_true
718 716 end
719 717
720 718 def check_structure(entries, structure)
721 719 structure = structure.dup
722 720 Category.each_with_level(entries) do |category, level|
723 721 expected_level, expected_name = structure.shift
724   - assert_equal expected_name, category.name, "wrong category"
725   - assert_equal expected_level, level, "wrong level for #{category.name}"
  722 + expected_name.should == category.name
  723 + expected_level.should == level
726 724 end
727 725 end
728 726
@@ -767,10 +765,10 @@ def check_structure(entries, structure)
767 765 model = Class.new(ActiveRecord::Base)
768 766 model.set_table_name 'categories'
769 767 model.attr_accessible :name
770   - assert_nothing_raised do
  768 + lambda {
771 769 model.acts_as_nested_set
772 770 model.new(:name => 'foo')
773   - end
  771 + }.should_not raise_exception
774 772 end
775 773
776 774 describe "before_move_callback" do
@@ -781,8 +779,8 @@ def check_structure(entries, structure)
781 779
782 780 it "should stop move when callback returns false" do
783 781 Category.test_allows_move = false
784   - assert !categories(:child_3).move_to_root
785   - assert !categories(:child_3).root?
  782 + categories(:child_3).move_to_root.should be_false
  783 + categories(:child_3).root?.should be_false
786 784 end
787 785
788 786 it "should not halt save actions" do
@@ -796,28 +794,28 @@ def check_structure(entries, structure)
796 794
797 795 it "should allow use of a counter cache for children" do
798 796 note1 = things(:parent1)
799   - assert_equal 2, note1.children.count
  797 + note1.children.count.should == 2
800 798 end
801 799
802 800 it "should increment the counter cache on create" do
803 801 ActiveRecord::Base.logger.info 'FOO'
804 802 note1 = things(:parent1)
805   - assert_equal 2, note1.children.count
806   - assert_equal 2, note1[:children_count]
  803 + note1.children.count.should == 2
  804 + note1[:children_count].should == 2
807 805 note1.children.create :body => 'Child 3'
808   - assert_equal 3, note1.children.count
  806 + note1.children.count.should == 3
809 807 note1.reload
810   - assert_equal 3, note1[:children_count]
  808 + note1[:children_count].should == 3
811 809 end
812 810
813 811 it "should decrement the counter cache on destroy" do
814 812 note1 = things(:parent1)
815   - assert_equal 2, note1.children.count
816   - assert_equal 2, note1[:children_count]
  813 + note1.children.count.should == 2
  814 + note1[:children_count].should == 2
817 815 note1.children.last.destroy
818