ramdiv-mongo_mapper_acts_as_tree 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -28,9 +28,10 @@ The method accepts :parent_id_field, :path_field, :depth_field, :order as a hash
28
28
 
29
29
  Check the test_tree.rb for examples.
30
30
 
31
- == !WARNING!
31
+ == About bugs
32
+
33
+ Use it. If you find any bugs, contact me (if possible with a test case) or patch it yourself (see next section).
32
34
 
33
- This is not production-ready code. Bugs are to be expected.
34
35
  == Note on Patches/Pull Requests
35
36
 
36
37
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -50,9 +50,9 @@ module MongoMapper
50
50
  end
51
51
 
52
52
  def parent=(var)
53
- var = self.find(var) if var.is_a? String
53
+ var = self.class.find(var) if var.is_a? String
54
54
 
55
- if self.descendents.include? var
55
+ if self.descendants.include? var
56
56
  @_cyclic = true
57
57
  else
58
58
  @_parent = var
@@ -110,13 +110,13 @@ module MongoMapper
110
110
  self.class.all(parent_id_field => self._id.to_s, :order => tree_order)
111
111
  end
112
112
 
113
- def descendents
113
+ def descendants
114
114
  return [] if new_record?
115
115
  self.class.all(path_field => self._id, :order => tree_order)
116
116
  end
117
117
 
118
- def self_and_descendents
119
- [self] + self.descendents
118
+ def self_and_descendants
119
+ [self] + self.descendants
120
120
  end
121
121
 
122
122
  def is_ancestor_of?(other)
@@ -155,7 +155,7 @@ module MongoMapper
155
155
  end
156
156
 
157
157
  def destroy_descendants
158
- self.class.destroy(self.descendents.map(&:_id))
158
+ self.class.destroy(self.descendants.map(&:_id))
159
159
  end
160
160
  end
161
161
 
@@ -178,4 +178,4 @@ module MongoMapper
178
178
  end
179
179
  end
180
180
  end
181
- end
181
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ramdiv-mongo_mapper_acts_as_tree}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakob Vidmar"]
12
- s.date = %q{2009-12-20}
12
+ s.date = %q{2010-01-09}
13
13
  s.description = %q{Port of the old, venerable ActsAsTree with a bit of a twist}
14
14
  s.email = %q{jakob.vidmar@gmail.com}
15
15
  s.extra_rdoc_files = [
data/test/test_order.rb CHANGED
@@ -17,8 +17,8 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
17
17
 
18
18
  assert_equal @root_1.children, [@child_1, @child_3, @child_2]
19
19
 
20
- assert_equal @root_1.descendents, [@child_1, @child_2_1, @child_3, @child_2]
21
- assert_equal @root_1.self_and_descendents, [@root_1, @child_1, @child_2_1, @child_3, @child_2]
20
+ assert_equal @root_1.descendants, [@child_1, @child_2_1, @child_3, @child_2]
21
+ assert_equal @root_1.self_and_descendants, [@root_1, @child_1, @child_2_1, @child_3, @child_2]
22
22
 
23
23
  assert_equal @child_2.siblings, [@child_1, @child_3]
24
24
  assert_equal @child_2.self_and_siblings, [@child_1, @child_3, @child_2]
data/test/test_tree.rb CHANGED
@@ -12,7 +12,10 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
12
12
  @root_2 = Category.create(:name => "Root 2")
13
13
  end
14
14
 
15
-
15
+ should "create node from id " do
16
+ assert Category.create(:name => "Child 2.2", :parent => @root_1.id.to_s).parent == @root_1
17
+ end
18
+
16
19
  should "have roots" do
17
20
  assert eql_arrays?(Category.roots, [@root_1, @root_2])
18
21
  end
@@ -51,13 +54,13 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
51
54
  assert eql_arrays?(@root_1.children, [@child_1, @child_2, @child_3])
52
55
  end
53
56
 
54
- should "have descendents" do
55
- assert eql_arrays?(@root_1.descendents, [@child_1, @child_2, @child_3, @child_2_1])
56
- assert eql_arrays?(@child_2.descendents, [@child_2_1])
57
- assert @child_2_1.descendents.empty?
58
- assert eql_arrays?(@root_1.self_and_descendents, [@root_1, @child_1, @child_2, @child_3, @child_2_1])
59
- assert eql_arrays?(@child_2.self_and_descendents, [@child_2, @child_2_1])
60
- assert eql_arrays?(@child_2_1.self_and_descendents, [@child_2_1])
57
+ should "have descendants" do
58
+ assert eql_arrays?(@root_1.descendants, [@child_1, @child_2, @child_3, @child_2_1])
59
+ assert eql_arrays?(@child_2.descendants, [@child_2_1])
60
+ assert @child_2_1.descendants.empty?
61
+ assert eql_arrays?(@root_1.self_and_descendants, [@root_1, @child_1, @child_2, @child_3, @child_2_1])
62
+ assert eql_arrays?(@child_2.self_and_descendants, [@child_2, @child_2_1])
63
+ assert eql_arrays?(@child_2_1.self_and_descendants, [@child_2_1])
61
64
  end
62
65
 
63
66
  should "be able to tell if ancestor" do
@@ -70,7 +73,7 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
70
73
  assert @child_2.is_or_is_ancestor_of?(@child_2)
71
74
  end
72
75
 
73
- should "be able to tell if descendent" do
76
+ should "be able to tell if descendant" do
74
77
  assert !@root_1.is_descendant_of?(@child_1)
75
78
  assert @child_1.is_descendant_of?(@root_1)
76
79
  assert !@child_2.is_descendant_of?(@child_2)
@@ -98,7 +101,7 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
98
101
  assert @child_2.is_or_is_ancestor_of?(@child_3)
99
102
  assert @child_3.is_or_is_descendant_of?(@child_2)
100
103
  assert @child_2.children.include?(@child_3)
101
- assert @child_2.descendents.include?(@child_3)
104
+ assert @child_2.descendants.include?(@child_3)
102
105
  assert @child_2_1.is_or_is_sibling_of?(@child_3)
103
106
  assert_equal 2, @child_3.depth
104
107
  end
@@ -108,14 +111,14 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
108
111
 
109
112
  assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
110
113
  assert !@child_2_1.is_or_is_descendant_of?(@root_2)
111
- assert !@root_2.descendents.include?(@child_2_1)
114
+ assert !@root_2.descendants.include?(@child_2_1)
112
115
 
113
116
  @child_2.save
114
117
  @child_2_1.reload
115
118
 
116
119
  assert @root_2.is_or_is_ancestor_of?(@child_2_1)
117
120
  assert @child_2_1.is_or_is_descendant_of?(@root_2)
118
- assert @root_2.descendents.include?(@child_2_1)
121
+ assert @root_2.descendants.include?(@child_2_1)
119
122
  end
120
123
 
121
124
  should "check agains cyclic graph" do
@@ -124,7 +127,7 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
124
127
  end
125
128
  end
126
129
 
127
- should "destroy descendents when destroyed" do
130
+ should "destroy descendants when destroyed" do
128
131
  @child_2.destroy
129
132
  assert_nil Category.find(@child_2_1._id)
130
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramdiv-mongo_mapper_acts_as_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Vidmar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-20 00:00:00 +01:00
12
+ date: 2010-01-09 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency