mongo_mapper_tree 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.rdoc +2 -1
- data/lib/mongo_mapper/plugins/tree.rb +3 -1
- data/lib/version.rb +1 -1
- data/test/helper.rb +5 -28
- data/test/models/ordered_category.rb +1 -1
- data/test/test_order.rb +24 -20
- data/test/test_search_mixed_tree.rb +54 -0
- data/test/test_search_tree.rb +52 -0
- data/test/test_tree.rb +150 -156
- metadata +15 -29
- data/test/test_search_class.rb +0 -90
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWJhYjAwZDk3OWI3MGYxNmNlYzdmNGY4YjI0NDczYjY0ODYxNjg0MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTZiNWRlMGJjMWZhMzIzZjdkMzdhYzFkMDdkYzA1OGIzYzVhM2YxOQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjkxMzI3Mjk3MWM0MzJhMWMxMDgyYmU5MjU3ZmI2NDcxY2I1YTdkZGExNmE4
|
10
|
+
NGRmODY1ZWRjNDIxY2MyYjYyOWQ3ZGRmNzc2OTEwNzE0ZDNiNTQ4MTc0Mjc4
|
11
|
+
ZWFlNGZjY2QwZWNiNzVjMTA0ZjgwMzQwNTFjMDUwNDQ1OWNhODM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZmZmZjlkNWM3OTNiNGE3Mzk0MDQxNmQxZmRhMTU0NDA4ZDE4YTk0NzU3NGIw
|
14
|
+
YjIyY2Y4MmVjY2ExMDE0ZTIyNjdkMTc5YWMwZWZiMDMzYmQ2OTVkMDRkZDNh
|
15
|
+
YTJjNWY3YmFkNDNhZmQxYWJhMzY2YWJhMTQzNzIzNTVhZGU1ODE=
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= mongo_mapper_tree
|
2
2
|
|
3
|
-
This is an
|
3
|
+
This is an maintained version of mongo_mapper_acts_as_tree (https://github.com/ramdiv/mongo_mapper_acts_as_tree) (ie. most of the code is written by Jacob Vidmar)
|
4
4
|
In it's essence it's an implementation of a tree structure for MongoMapper, think acts as tree but for mongodb.
|
5
5
|
|
6
6
|
|
@@ -43,4 +43,5 @@ For best performance add a index on the field called path_field.
|
|
43
43
|
|
44
44
|
== Copyright
|
45
45
|
|
46
|
+
Original code written by Jakob Vidmar https://github.com/ramdiv/mongo_mapper_acts_as_tree
|
46
47
|
Copyright (c) 2011 Joel Junström. See LICENSE for details.
|
data/lib/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
require 'shoulda'
|
2
|
+
gem "minitest"
|
4
3
|
require 'database_cleaner'
|
4
|
+
require "minitest/autorun"
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -13,29 +13,6 @@ Dir["#{File.dirname(__FILE__)}/models/*.rb"].each {|file| require file}
|
|
13
13
|
|
14
14
|
DatabaseCleaner.strategy = :truncation
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
DatabaseCleaner.start
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
DatabaseCleaner.clean
|
24
|
-
end
|
25
|
-
|
26
|
-
# Make sure that each test case has a teardown
|
27
|
-
# method to clear the db after each test.
|
28
|
-
def inherited(base)
|
29
|
-
base.define_method setup do
|
30
|
-
super
|
31
|
-
end
|
32
|
-
|
33
|
-
base.define_method teardown do
|
34
|
-
super
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def eql_arrays?(first, second)
|
39
|
-
first.collect(&:_id).to_set == second.collect(&:_id).to_set
|
40
|
-
end
|
41
|
-
end
|
16
|
+
def eql_arrays?(first, second)
|
17
|
+
first.collect(&:_id).to_set == second.collect(&:_id).to_set
|
18
|
+
end
|
data/test/test_order.rb
CHANGED
@@ -1,26 +1,30 @@
|
|
1
1
|
require 'helper'
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
@root_1 = OrderedCategory.create(:name => "Root 1", :value => 2)
|
6
|
-
@child_1 = OrderedCategory.create(:name => "Child 1", :parent => @root_1, :value => 1)
|
7
|
-
@child_2 = OrderedCategory.create(:name => "Child 2", :parent => @root_1, :value => 9)
|
8
|
-
@child_2_1 = OrderedCategory.create(:name => "Child 2.1", :parent => @child_2, :value => 2)
|
9
|
-
@child_3 = OrderedCategory.create(:name => "Child 3", :parent => @root_1, :value => 5)
|
10
|
-
@root_2 = OrderedCategory.create(:name => "Root 2", :value => 1)
|
11
|
-
end
|
2
|
+
class TestOrder < Minitest::Test
|
3
|
+
def setup
|
4
|
+
DatabaseCleaner.start
|
12
5
|
|
13
|
-
|
14
|
-
|
6
|
+
@root_1 = OrderedCategory.create(:name => "Root 1", :value => 2)
|
7
|
+
@child_1 = OrderedCategory.create(:name => "Child 1", :parent => @root_1, :value => 1)
|
8
|
+
@child_2 = OrderedCategory.create(:name => "Child 2", :parent => @root_1, :value => 9)
|
9
|
+
@child_2_1 = OrderedCategory.create(:name => "Child 2.1", :parent => @child_2, :value => 2)
|
10
|
+
@child_3 = OrderedCategory.create(:name => "Child 3", :parent => @root_1, :value => 5)
|
11
|
+
@root_2 = OrderedCategory.create(:name => "Root 2", :value => 1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
DatabaseCleaner.clean
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_in_order
|
19
|
+
assert_equal OrderedCategory.roots, [@root_2, @root_1]
|
15
20
|
|
16
|
-
|
21
|
+
assert_equal @root_1.children, [@child_1, @child_3, @child_2]
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
assert_equal @root_1.descendants, [@child_1, @child_2_1, @child_3, @child_2]
|
24
|
+
assert_equal @root_1.self_and_descendants, [@root_1, @child_1, @child_2_1, @child_3, @child_2]
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
26
|
+
assert_equal @child_2.siblings, [@child_1, @child_3]
|
27
|
+
assert_equal @child_2.self_and_siblings, [@child_1, @child_3, @child_2]
|
28
|
+
assert_equal @root_1.self_and_siblings, [@root_2, @root_1]
|
25
29
|
end
|
26
|
-
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSearchMixedTree < Minitest::Test
|
4
|
+
def setup
|
5
|
+
DatabaseCleaner.start
|
6
|
+
shape = Shape.create(name: "Root")
|
7
|
+
circle = Circle.create(name: "Circle", parent: shape)
|
8
|
+
Square.create(name: "Square", parent: circle)
|
9
|
+
|
10
|
+
@shape, @circle, @square = Shape.first, Circle.first, Square.first
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
DatabaseCleaner.clean
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_circle_is_child_of_shape
|
18
|
+
assert_equal [@circle], @shape.children
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_square_is_child_of_circle
|
22
|
+
assert_equal [@square], @circle.children
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_circle_is_parent_of_square
|
26
|
+
assert_equal @circle, @square.parent
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_shape_is_parent_of_circle
|
30
|
+
assert_equal @shape, @circle.parent
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_shape_decendants
|
34
|
+
assert_equal [@circle, @square], @shape.descendants
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_circle_decendants
|
38
|
+
assert_equal [@square], @circle.descendants
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_square_ancestors
|
42
|
+
assert_equal [@shape, @circle], @square.ancestors
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_circle_ansestors
|
46
|
+
assert_equal [@shape], @circle.ancestors
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_destroy_shape_decendants
|
50
|
+
@shape.destroy_descendants
|
51
|
+
assert_nil Shape.find(@circle._id)
|
52
|
+
assert_nil Shape.find(@square._id)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSearchTree < Minitest::Test
|
4
|
+
def setup
|
5
|
+
DatabaseCleaner.start
|
6
|
+
shape = Shape.create(name: "Root")
|
7
|
+
Circle.create(name: "Circle", parent: shape)
|
8
|
+
Square.create(name: "Square", parent: shape)
|
9
|
+
|
10
|
+
# We are loading from the database here because this process proves the point. If we never did it this
|
11
|
+
# way, there would be no reason to change the code.
|
12
|
+
@shape, @circle, @square = Shape.first, Circle.first, Square.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
DatabaseCleaner.clean
|
17
|
+
end
|
18
|
+
|
19
|
+
def text_children
|
20
|
+
assert_equal [@circle, @square], @shape.children
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_shape_parenhood
|
24
|
+
assert_equal @shape, @circle.parent
|
25
|
+
assert_equal @shape, @square.parent
|
26
|
+
end
|
27
|
+
|
28
|
+
def text_siblings
|
29
|
+
assert_equal [@square], @circle.siblings
|
30
|
+
assert_equal [@circle, @square], @circle.self_and_siblings
|
31
|
+
|
32
|
+
assert_equal [@circle], @square.siblings
|
33
|
+
assert_equal [@circle, @square], @square.self_and_siblings
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_deendants
|
37
|
+
assert_equal [@circle, @square], @shape.descendants
|
38
|
+
assert_equal [@shape, @circle, @square], @shape.self_and_descendants
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_ancestors
|
42
|
+
assert_equal [@shape], @circle.ancestors
|
43
|
+
assert_equal [@shape, @circle], @circle.self_and_ancestors
|
44
|
+
assert_equal [@shape], @square.ancestors
|
45
|
+
assert_equal [@shape, @square], @square.self_and_ancestors
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_roots
|
49
|
+
assert_equal @shape, @square.root
|
50
|
+
assert_equal @shape, @circle.root
|
51
|
+
end
|
52
|
+
end
|
data/test/test_tree.rb
CHANGED
@@ -1,157 +1,151 @@
|
|
1
1
|
require 'helper'
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
should "have a parent" do
|
153
|
-
assert_equal @child_2, @child_2_1.parent
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
2
|
+
class TestTree < Minitest::Test
|
3
|
+
def setup
|
4
|
+
DatabaseCleaner.start
|
5
|
+
@root_1 = Category.create(name: "Root 1")
|
6
|
+
@child_1 = Category.create(name: "Child 1", parent: @root_1)
|
7
|
+
@child_2 = Category.create(name: "Child 2", parent: @root_1)
|
8
|
+
@child_2_1 = Category.create(name: "Child 2.1", parent: @child_2)
|
9
|
+
@child_3 = Category.create(name: "Child 3", parent: @root_1)
|
10
|
+
@root_2 = Category.create(name: "Root 2")
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
DatabaseCleaner.clean
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_node_from_id
|
18
|
+
assert Category.create(name: "Child 2.2", parent_id: @root_1.id).parent == @root_1
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_category_roots
|
22
|
+
assert eql_arrays?(Category.roots, [@root_1, @root_2])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_roots
|
26
|
+
assert_equal @root_1.root, @root_1
|
27
|
+
refute_equal @root_1.root, @root_2.root
|
28
|
+
assert_equal @root_1, @child_2_1.root
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_ancestors
|
32
|
+
assert_equal @root_1.ancestors, []
|
33
|
+
assert_equal @child_2_1.ancestors, [@root_1, @child_2]
|
34
|
+
assert_equal @root_1.self_and_ancestors, [@root_1]
|
35
|
+
assert_equal @child_2_1.self_and_ancestors, [@root_1, @child_2, @child_2_1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_siblings
|
39
|
+
assert eql_arrays?(@root_1.siblings, [@root_2])
|
40
|
+
assert eql_arrays?(@child_2.siblings, [@child_1, @child_3])
|
41
|
+
assert eql_arrays?(@child_2_1.siblings, [])
|
42
|
+
assert eql_arrays?(@root_1.self_and_siblings, [@root_1, @root_2])
|
43
|
+
assert eql_arrays?(@child_2.self_and_siblings, [@child_1, @child_2, @child_3])
|
44
|
+
assert eql_arrays?(@child_2_1.self_and_siblings, [@child_2_1])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_depths
|
48
|
+
assert_equal 0, @root_1.depth
|
49
|
+
assert_equal 1, @child_1.depth
|
50
|
+
assert_equal 2, @child_2_1.depth
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_children
|
54
|
+
assert @child_2_1.children.empty?
|
55
|
+
assert eql_arrays?(@root_1.children, [@child_1, @child_2, @child_3])
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_decendants
|
59
|
+
assert eql_arrays?(@root_1.descendants, [@child_1, @child_2, @child_3, @child_2_1])
|
60
|
+
assert eql_arrays?(@child_2.descendants, [@child_2_1])
|
61
|
+
assert @child_2_1.descendants.empty?
|
62
|
+
assert eql_arrays?(@root_1.self_and_descendants, [@root_1, @child_1, @child_2, @child_3, @child_2_1])
|
63
|
+
assert eql_arrays?(@child_2.self_and_descendants, [@child_2, @child_2_1])
|
64
|
+
assert eql_arrays?(@child_2_1.self_and_descendants, [@child_2_1])
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_knows_if_ancestor
|
68
|
+
assert @root_1.is_ancestor_of?(@child_1)
|
69
|
+
assert ! @root_2.is_ancestor_of?(@child_2_1)
|
70
|
+
assert ! @child_2.is_ancestor_of?(@child_2)
|
71
|
+
|
72
|
+
assert @root_1.is_or_is_ancestor_of?(@child_1)
|
73
|
+
assert ! @root_2.is_or_is_ancestor_of?(@child_2_1)
|
74
|
+
assert @child_2.is_or_is_ancestor_of?(@child_2)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_knows_if_decendant
|
78
|
+
assert ! @root_1.is_descendant_of?(@child_1)
|
79
|
+
assert @child_1.is_descendant_of?(@root_1)
|
80
|
+
assert ! @child_2.is_descendant_of?(@child_2)
|
81
|
+
|
82
|
+
assert ! @root_1.is_or_is_descendant_of?(@child_1)
|
83
|
+
assert @child_1.is_or_is_descendant_of?(@root_1)
|
84
|
+
assert @child_2.is_or_is_descendant_of?(@child_2)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_knows_if_sibling
|
88
|
+
assert ! @root_1.is_sibling_of?(@child_1)
|
89
|
+
assert ! @child_1.is_sibling_of?(@child_1)
|
90
|
+
assert ! @child_2.is_sibling_of?(@child_2)
|
91
|
+
|
92
|
+
assert ! @root_1.is_or_is_sibling_of?(@child_1)
|
93
|
+
assert @child_1.is_or_is_sibling_of?(@child_2)
|
94
|
+
assert @child_2.is_or_is_sibling_of?(@child_2)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_recalculates_path_and_depth_when_moved
|
98
|
+
@child_3.parent = @child_2
|
99
|
+
@child_3.save
|
100
|
+
|
101
|
+
assert @child_2.is_or_is_ancestor_of?(@child_3)
|
102
|
+
assert @child_3.is_or_is_descendant_of?(@child_2)
|
103
|
+
assert @child_2.children.include?(@child_3)
|
104
|
+
assert @child_2.descendants.include?(@child_3)
|
105
|
+
assert @child_2_1.is_or_is_sibling_of?(@child_3)
|
106
|
+
assert_equal 2, @child_3.depth
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_moved_children_when_moved
|
110
|
+
@child_2.parent = @root_2
|
111
|
+
|
112
|
+
assert ! @root_2.is_or_is_ancestor_of?(@child_2_1)
|
113
|
+
assert ! @child_2_1.is_or_is_descendant_of?(@root_2)
|
114
|
+
assert ! @root_2.descendants.include?(@child_2_1)
|
115
|
+
|
116
|
+
@child_2.save
|
117
|
+
@child_2_1.reload
|
118
|
+
|
119
|
+
assert @root_2.is_or_is_ancestor_of?(@child_2_1)
|
120
|
+
assert @child_2_1.is_or_is_descendant_of?(@root_2)
|
121
|
+
assert @root_2.descendants.include?(@child_2_1)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_checks_against_cyclic_graph
|
125
|
+
@root_1.parent = @child_2_1
|
126
|
+
assert ! @root_1.valid?
|
127
|
+
assert_equal I18n.t(:'mongo_mapper.errors.messages.cyclic'), @root_1.errors[:base].first
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_can_become_root
|
131
|
+
@child_2.parent = nil
|
132
|
+
@child_2.save
|
133
|
+
@child_2.reload
|
134
|
+
assert_nil @child_2.parent
|
135
|
+
@child_2_1.reload
|
136
|
+
assert (@child_2_1.path == [@child_2.id])
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_destroys_decendants
|
140
|
+
assert @child_2.destroy
|
141
|
+
assert_nil Category.find(@child_2_1._id)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_roots_cannot_have_parents
|
145
|
+
assert_nil @root_1.parent
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_children_have_a_parent
|
149
|
+
assert_equal @child_2, @child_2_1.parent
|
150
|
+
end
|
151
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joel Junström
|
@@ -10,30 +9,22 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: mongo_mapper
|
17
|
-
requirement:
|
18
|
-
none: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - '='
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
20
|
+
version: 0.13.0.beta2
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: shoulda
|
28
|
-
requirement: &70110048247860 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
24
|
requirements:
|
31
|
-
- -
|
25
|
+
- - '='
|
32
26
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *70110048247860
|
27
|
+
version: 0.13.0.beta2
|
37
28
|
description: An Acts As Tree like implementation for MongoMapper based on mongo_mapper_acts_as_tree
|
38
29
|
email:
|
39
30
|
- bender@oktavilla.se
|
@@ -50,39 +41,33 @@ files:
|
|
50
41
|
- test/models/ordered_category.rb
|
51
42
|
- test/models/shapes.rb
|
52
43
|
- test/test_order.rb
|
53
|
-
- test/
|
44
|
+
- test/test_search_mixed_tree.rb
|
45
|
+
- test/test_search_tree.rb
|
54
46
|
- test/test_tree.rb
|
55
47
|
- LICENSE
|
56
48
|
- README.rdoc
|
57
49
|
homepage: http://github.com/Oktavilla/mongo_mapper_tree
|
58
50
|
licenses: []
|
51
|
+
metadata: {}
|
59
52
|
post_install_message:
|
60
53
|
rdoc_options: []
|
61
54
|
require_paths:
|
62
55
|
- lib
|
63
56
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
57
|
requirements:
|
66
58
|
- - ! '>='
|
67
59
|
- !ruby/object:Gem::Version
|
68
60
|
version: '0'
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
hash: -1182322477251881257
|
72
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
62
|
requirements:
|
75
63
|
- - ! '>='
|
76
64
|
- !ruby/object:Gem::Version
|
77
65
|
version: '0'
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
hash: -1182322477251881257
|
81
66
|
requirements: []
|
82
67
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
68
|
+
rubygems_version: 2.0.1
|
84
69
|
signing_key:
|
85
|
-
specification_version:
|
70
|
+
specification_version: 4
|
86
71
|
summary: An Acts As Tree like implementation for MongoMapper
|
87
72
|
test_files:
|
88
73
|
- test/helper.rb
|
@@ -90,5 +75,6 @@ test_files:
|
|
90
75
|
- test/models/ordered_category.rb
|
91
76
|
- test/models/shapes.rb
|
92
77
|
- test/test_order.rb
|
93
|
-
- test/
|
78
|
+
- test/test_search_mixed_tree.rb
|
79
|
+
- test/test_search_tree.rb
|
94
80
|
- test/test_tree.rb
|
data/test/test_search_class.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestSearchScope < Test::Unit::TestCase
|
4
|
-
context "Simple, mixed type tree" do
|
5
|
-
setup do
|
6
|
-
shape = Shape.create(:name => "Root")
|
7
|
-
Circle.create(:name => "Circle", :parent => shape)
|
8
|
-
Square.create(:name => "Square", :parent => shape)
|
9
|
-
end
|
10
|
-
|
11
|
-
setup do
|
12
|
-
# We are loading from the database here because this process proves the point. If we never did it this
|
13
|
-
# way, there would be no reason to change the code.
|
14
|
-
@shape, @circle, @square = Shape.first, Circle.first, Square.first
|
15
|
-
end
|
16
|
-
|
17
|
-
should "return circle and square as children of shape" do
|
18
|
-
assert_equal [@circle, @square], @shape.children
|
19
|
-
end
|
20
|
-
|
21
|
-
should("return shape as parent of circle") { assert_equal @shape, @circle.parent }
|
22
|
-
should("return shape as parent of square") { assert_equal @shape, @square.parent }
|
23
|
-
|
24
|
-
should("return square as exclusive sibling of circle") { assert_equal [@square], @circle.siblings }
|
25
|
-
should "return self and square as inclusive siblings of circle" do
|
26
|
-
assert_equal [@circle, @square], @circle.self_and_siblings
|
27
|
-
end
|
28
|
-
|
29
|
-
should("return circle as exclusive sibling of square") { assert_equal [@circle], @square.siblings }
|
30
|
-
should "return self and circle as inclusive siblings of square" do
|
31
|
-
assert_equal [@circle, @square], @square.self_and_siblings
|
32
|
-
end
|
33
|
-
|
34
|
-
should "return circle and square as exclusive descendants of shape" do
|
35
|
-
assert_equal [@circle, @square], @shape.descendants
|
36
|
-
end
|
37
|
-
should "return shape, circle and square as inclusive descendants of shape" do
|
38
|
-
assert_equal [@shape, @circle, @square], @shape.self_and_descendants
|
39
|
-
end
|
40
|
-
|
41
|
-
should("return shape as exclusive ancestor of circle") { assert_equal [@shape], @circle.ancestors }
|
42
|
-
should "return self and shape as inclusive ancestors of circle" do
|
43
|
-
assert_equal [@shape, @circle], @circle.self_and_ancestors
|
44
|
-
end
|
45
|
-
|
46
|
-
should("return shape as exclusive ancestor of square") { assert_equal [@shape], @square.ancestors }
|
47
|
-
should "return self and shape as inclusive ancestors of square" do
|
48
|
-
assert_equal [@shape, @square], @square.self_and_ancestors
|
49
|
-
end
|
50
|
-
|
51
|
-
should("return shape as root of circle") { assert_equal @shape, @square.root }
|
52
|
-
should("return shape as root of square") { assert_equal @shape, @circle.root }
|
53
|
-
end
|
54
|
-
|
55
|
-
context "A tree with mixed types on either side of a branch" do
|
56
|
-
setup do
|
57
|
-
shape = Shape.create(:name => "Root")
|
58
|
-
circle = Circle.create(:name => "Circle", :parent => shape)
|
59
|
-
Square.create(:name => "Square", :parent => circle)
|
60
|
-
end
|
61
|
-
|
62
|
-
setup do
|
63
|
-
@shape, @circle, @square = Shape.first, Circle.first, Square.first
|
64
|
-
end
|
65
|
-
|
66
|
-
should("return circle as child of shape") { assert_equal [@circle], @shape.children }
|
67
|
-
should("return square as child of circle") { assert_equal [@square], @circle.children }
|
68
|
-
should("return circle as parent of square") { assert_equal @circle, @square.parent }
|
69
|
-
should("return shape as parent of circle") { assert_equal @shape, @circle.parent }
|
70
|
-
|
71
|
-
should "return circle and square as descendants of shape" do
|
72
|
-
assert_equal [@circle, @square], @shape.descendants
|
73
|
-
end
|
74
|
-
|
75
|
-
should("return square as descendant of circle") { assert_equal [@square], @circle.descendants }
|
76
|
-
|
77
|
-
should "return shape and circle as ancestors of square" do
|
78
|
-
assert_equal [@shape, @circle], @square.ancestors
|
79
|
-
end
|
80
|
-
|
81
|
-
should("return shape as ancestor of circle") { assert_equal [@shape], @circle.ancestors }
|
82
|
-
|
83
|
-
should "destroy descendants of shape" do
|
84
|
-
@shape.destroy_descendants
|
85
|
-
assert_nil Shape.find(@circle._id)
|
86
|
-
assert_nil Shape.find(@square._id)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end # TestSearchScope
|