closure_tree 3.3.0 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/closure_tree/acts_as_tree.rb +2 -0
- data/lib/closure_tree/version.rb +1 -1
- data/spec/label_spec.rb +1 -1
- data/spec/tag_spec.rb +19 -1
- data/spec/user_spec.rb +29 -17
- metadata +4 -4
data/README.md
CHANGED
@@ -317,6 +317,16 @@ Closure tree is [tested under every combination](https://secure.travis-ci.org/mc
|
|
317
317
|
|
318
318
|
## Change log
|
319
319
|
|
320
|
+
### 3.3.1
|
321
|
+
|
322
|
+
* Added support for partially-unsaved hierarchies [issue 13](https://github.com/mceachen/closure_tree/issues/13):
|
323
|
+
```
|
324
|
+
a = Tag.new(name: "a")
|
325
|
+
b = Tag.new(name: "b")
|
326
|
+
a.children << b
|
327
|
+
a.save
|
328
|
+
```
|
329
|
+
|
320
330
|
### 3.3.0
|
321
331
|
|
322
332
|
* Added [```hash_tree```](#nested-hashes).
|
data/lib/closure_tree/version.rb
CHANGED
data/spec/label_spec.rb
CHANGED
data/spec/tag_spec.rb
CHANGED
@@ -4,8 +4,8 @@ shared_examples_for Tag do
|
|
4
4
|
describe "empty db" do
|
5
5
|
|
6
6
|
def nuke_db
|
7
|
-
Tag.delete_all
|
8
7
|
TagHierarchy.delete_all
|
8
|
+
Tag.delete_all
|
9
9
|
end
|
10
10
|
|
11
11
|
before :each do
|
@@ -353,6 +353,24 @@ shared_examples_for Tag do
|
|
353
353
|
city.self_and_ancestors.should == [city, tags(:california), tags(:united_states), tags(:places)]
|
354
354
|
end
|
355
355
|
|
356
|
+
it "performs as the readme says it does" do
|
357
|
+
grandparent = Tag.create(:name => 'Grandparent')
|
358
|
+
parent = grandparent.children.create(:name => 'Parent')
|
359
|
+
child1 = Tag.create(:name => 'First Child')
|
360
|
+
parent.children << child1
|
361
|
+
child2 = Tag.create(:name => 'Second Child')
|
362
|
+
parent.add_child child2
|
363
|
+
grandparent.self_and_descendants.collect(&:name).should ==
|
364
|
+
["Grandparent", "Parent", "First Child", "Second Child"]
|
365
|
+
child1.ancestry_path.should ==
|
366
|
+
["Grandparent", "Parent", "First Child"]
|
367
|
+
d = Tag.find_or_create_by_path %w(a b c d)
|
368
|
+
h = Tag.find_or_create_by_path %w(e f g h)
|
369
|
+
e = h.root
|
370
|
+
d.add_child(e) # "d.children << e" would work too, of course
|
371
|
+
h.ancestry_path.should == %w(a b c d e f g h)
|
372
|
+
end
|
373
|
+
|
356
374
|
end
|
357
375
|
end
|
358
376
|
|
data/spec/user_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe "empty db" do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
User.delete_all
|
7
6
|
ReferralHierarchy.delete_all
|
7
|
+
User.delete_all
|
8
8
|
end
|
9
9
|
|
10
10
|
context "empty db" do
|
@@ -87,21 +87,33 @@ describe "empty db" do
|
|
87
87
|
u.root.indirect_contracts.to_a.should =~ [c1, c2]
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
90
|
+
|
91
|
+
it "supports << on shallow unsaved hierarchies" do
|
92
|
+
a = User.new(:email => "a")
|
93
|
+
b = User.new(:email => "b")
|
94
|
+
a.children << b
|
95
|
+
a.save
|
96
|
+
User.roots.should == [a]
|
97
|
+
User.leaves.should == [b]
|
98
|
+
b.ancestry_path.should == %w(a b)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "supports << on deep unsaved hierarchies" do
|
102
|
+
a = User.new(:email => "a")
|
103
|
+
b1 = User.new(:email => "b1")
|
104
|
+
a.children << b1
|
105
|
+
b2 = User.new(:email => "b2")
|
106
|
+
a.children << b2
|
107
|
+
c1 = User.new(:email => "c1")
|
108
|
+
b2.children << c1
|
109
|
+
c2 = User.new(:email => "c2")
|
110
|
+
b2.children << c2
|
111
|
+
d = User.new(:email => "d")
|
112
|
+
c2.children << d
|
113
|
+
|
114
|
+
a.save
|
115
|
+
User.roots.should == [a]
|
116
|
+
User.leaves.should == [b1, c1, d]
|
117
|
+
d.ancestry_path.should == %w(a b2 c2 d)
|
106
118
|
end
|
107
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closure_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
segments:
|
195
195
|
- 0
|
196
|
-
hash:
|
196
|
+
hash: 2911561954531339982
|
197
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
198
|
none: false
|
199
199
|
requirements:
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
segments:
|
204
204
|
- 0
|
205
|
-
hash:
|
205
|
+
hash: 2911561954531339982
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
208
|
rubygems_version: 1.8.21
|