closure_tree 4.6.2 → 4.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +6 -1
- data/closure_tree.gemspec +1 -1
- data/gemfiles/activerecord_3.2.gemfile +1 -1
- data/gemfiles/activerecord_4.0.gemfile +1 -1
- data/gemfiles/activerecord_4.1.gemfile +1 -1
- data/lib/closure_tree/hierarchy_maintenance.rb +1 -1
- data/lib/closure_tree/test/matcher.rb +13 -9
- data/lib/closure_tree/version.rb +1 -1
- data/spec/cuisine_type_spec.rb +6 -6
- data/spec/label_spec.rb +122 -121
- data/spec/matcher_spec.rb +16 -14
- data/spec/metal_spec.rb +1 -1
- data/spec/namespace_type_spec.rb +3 -3
- data/spec/parallel_spec.rb +12 -12
- data/spec/support_spec.rb +2 -2
- data/spec/tag_examples.rb +135 -132
- data/spec/user_spec.rb +46 -46
- metadata +6 -6
data/spec/user_spec.rb
CHANGED
@@ -4,16 +4,16 @@ describe "empty db" do
|
|
4
4
|
|
5
5
|
context "empty db" do
|
6
6
|
it "should return no entities" do
|
7
|
-
User.roots.
|
8
|
-
User.leaves.
|
7
|
+
expect(User.roots).to be_empty
|
8
|
+
expect(User.leaves).to be_empty
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
context "1 user db" do
|
13
13
|
it "should return the only entity as a root and leaf" do
|
14
14
|
a = User.create!(:email => "me@domain.com")
|
15
|
-
User.roots.
|
16
|
-
User.leaves.
|
15
|
+
expect(User.roots).to eq([a])
|
16
|
+
expect(User.leaves).to eq([a])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,8 +21,8 @@ describe "empty db" do
|
|
21
21
|
it "should return a simple root and leaf" do
|
22
22
|
root = User.create!(:email => "first@t.co")
|
23
23
|
leaf = root.children.create!(:email => "second@t.co")
|
24
|
-
User.roots.
|
25
|
-
User.leaves.
|
24
|
+
expect(User.roots).to eq([root])
|
25
|
+
expect(User.leaves).to eq([leaf])
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -35,36 +35,36 @@ describe "empty db" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should create all Users" do
|
38
|
-
User.all.to_a.
|
38
|
+
expect(User.all.to_a).to match_array([@root, @mid, @leaf])
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'orders self_and_ancestor_ids nearest generation first' do
|
42
|
-
@leaf.self_and_ancestor_ids.
|
42
|
+
expect(@leaf.self_and_ancestor_ids).to eq([@leaf.id, @mid.id, @root.id])
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'orders self_and_descendant_ids nearest generation first' do
|
46
|
-
@root.self_and_descendant_ids.
|
46
|
+
expect(@root.self_and_descendant_ids).to eq([@root.id, @mid.id, @leaf.id])
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should have children" do
|
50
|
-
@root.children.to_a.
|
51
|
-
@mid.children.to_a.
|
52
|
-
@leaf.children.to_a.
|
50
|
+
expect(@root.children.to_a).to eq([@mid])
|
51
|
+
expect(@mid.children.to_a).to eq([@leaf])
|
52
|
+
expect(@leaf.children.to_a).to eq([])
|
53
53
|
end
|
54
54
|
|
55
55
|
it "roots should have children" do
|
56
|
-
User.roots.first.children.to_a.
|
56
|
+
expect(User.roots.first.children.to_a).to match_array([@mid])
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should return a root and leaf without middle User" do
|
60
|
-
User.roots.to_a.
|
61
|
-
User.leaves.to_a.
|
60
|
+
expect(User.roots.to_a).to eq([@root])
|
61
|
+
expect(User.leaves.to_a).to eq([@leaf])
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should delete leaves" do
|
65
65
|
User.leaves.destroy_all
|
66
|
-
User.roots.to_a.
|
67
|
-
User.leaves.to_a.
|
66
|
+
expect(User.roots.to_a).to eq([@root]) # untouched
|
67
|
+
expect(User.leaves.to_a).to eq([@mid])
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should delete roots and maintain hierarchies" do
|
@@ -78,27 +78,27 @@ describe "empty db" do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def assert_mid_and_leaf_remain
|
81
|
-
ReferralHierarchy.where(:ancestor_id => @root_id).
|
82
|
-
ReferralHierarchy.where(:descendant_id => @root_id).
|
83
|
-
@mid.ancestry_path.
|
84
|
-
@leaf.ancestry_path.
|
85
|
-
@mid.self_and_descendants.to_a.
|
86
|
-
User.roots.
|
87
|
-
User.leaves.
|
81
|
+
expect(ReferralHierarchy.where(:ancestor_id => @root_id)).to be_empty
|
82
|
+
expect(ReferralHierarchy.where(:descendant_id => @root_id)).to be_empty
|
83
|
+
expect(@mid.ancestry_path).to eq(%w{matt@t.co})
|
84
|
+
expect(@leaf.ancestry_path).to eq(%w{matt@t.co james@t.co})
|
85
|
+
expect(@mid.self_and_descendants.to_a).to match_array([@mid, @leaf])
|
86
|
+
expect(User.roots).to eq([@mid])
|
87
|
+
expect(User.leaves).to eq([@leaf])
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
it "supports users with contracts" do
|
92
92
|
u = User.find_or_create_by_path(%w(a@t.co b@t.co c@t.co))
|
93
|
-
u.descendant_ids.
|
94
|
-
u.ancestor_ids.
|
95
|
-
u.self_and_ancestor_ids.
|
96
|
-
u.root.descendant_ids.
|
97
|
-
u.root.ancestor_ids.
|
98
|
-
u.root.self_and_ancestor_ids.
|
93
|
+
expect(u.descendant_ids).to eq([])
|
94
|
+
expect(u.ancestor_ids).to eq([u.parent.id, u.root.id])
|
95
|
+
expect(u.self_and_ancestor_ids).to eq([u.id, u.parent.id, u.root.id])
|
96
|
+
expect(u.root.descendant_ids).to eq([u.parent.id, u.id])
|
97
|
+
expect(u.root.ancestor_ids).to eq([])
|
98
|
+
expect(u.root.self_and_ancestor_ids).to eq([u.root.id])
|
99
99
|
c1 = u.contracts.create!
|
100
100
|
c2 = u.parent.contracts.create!
|
101
|
-
u.root.indirect_contracts.to_a.
|
101
|
+
expect(u.root.indirect_contracts.to_a).to match_array([c1, c2])
|
102
102
|
end
|
103
103
|
|
104
104
|
it "supports << on shallow unsaved hierarchies" do
|
@@ -106,9 +106,9 @@ describe "empty db" do
|
|
106
106
|
b = User.new(:email => "b")
|
107
107
|
a.children << b
|
108
108
|
a.save
|
109
|
-
User.roots.
|
110
|
-
User.leaves.
|
111
|
-
b.ancestry_path.
|
109
|
+
expect(User.roots).to eq([a])
|
110
|
+
expect(User.leaves).to eq([b])
|
111
|
+
expect(b.ancestry_path).to eq(%w(a b))
|
112
112
|
end
|
113
113
|
|
114
114
|
it "supports << on deep unsaved hierarchies" do
|
@@ -125,30 +125,30 @@ describe "empty db" do
|
|
125
125
|
c2.children << d
|
126
126
|
|
127
127
|
a.save
|
128
|
-
User.roots.to_a.
|
129
|
-
User.leaves.to_a.
|
130
|
-
d.ancestry_path.
|
128
|
+
expect(User.roots.to_a).to eq([a])
|
129
|
+
expect(User.leaves.to_a).to match_array([b1, c1, d])
|
130
|
+
expect(d.ancestry_path).to eq(%w(a b2 c2 d))
|
131
131
|
end
|
132
132
|
|
133
133
|
it "supports siblings" do
|
134
|
-
User._ct.order_option
|
134
|
+
expect(User._ct.order_option?).to be_falsey
|
135
135
|
a = User.create(:email => "a")
|
136
136
|
b1 = a.children.create(:email => "b1")
|
137
137
|
b2 = a.children.create(:email => "b2")
|
138
138
|
b3 = a.children.create(:email => "b3")
|
139
|
-
a.siblings.
|
140
|
-
b1.siblings.to_a.
|
139
|
+
expect(a.siblings).to be_empty
|
140
|
+
expect(b1.siblings.to_a).to match_array([b2, b3])
|
141
141
|
end
|
142
142
|
|
143
143
|
context "when a user is not yet saved" do
|
144
144
|
it "supports siblings" do
|
145
|
-
User._ct.order_option
|
145
|
+
expect(User._ct.order_option?).to be_falsey
|
146
146
|
a = User.create(:email => "a")
|
147
147
|
b1 = a.children.new(:email => "b1")
|
148
148
|
b2 = a.children.create(:email => "b2")
|
149
149
|
b3 = a.children.create(:email => "b3")
|
150
|
-
a.siblings.
|
151
|
-
b1.siblings.to_a.
|
150
|
+
expect(a.siblings).to be_empty
|
151
|
+
expect(b1.siblings.to_a).to match_array([b2, b3])
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -156,8 +156,8 @@ describe "empty db" do
|
|
156
156
|
c = User.find_or_create_by_path %w(a b c)
|
157
157
|
b = c.parent
|
158
158
|
c.root.destroy
|
159
|
-
b.reload.
|
160
|
-
b.child_ids.
|
159
|
+
expect(b.reload).to be_root
|
160
|
+
expect(b.child_ids).to eq([c.id])
|
161
161
|
end
|
162
162
|
|
163
163
|
context "roots" do
|
@@ -168,7 +168,7 @@ describe "empty db" do
|
|
168
168
|
u.email = ea
|
169
169
|
end
|
170
170
|
end
|
171
|
-
User.roots.collect { |ea| ea.email }.sort.
|
171
|
+
expect(User.roots.collect { |ea| ea.email }.sort).to eq(expected)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closure_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew McEachen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec-instafail
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|