simple_tree 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## v0.0.1
2
2
 
3
- * Initial release
3
+ * Initial release
4
+
5
+ ## v0.0.2
6
+ * Added spec coverage
7
+ * Fixed a bug with descendants method
@@ -1,3 +1,3 @@
1
1
  module SimpleTree
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/simple_tree.rb CHANGED
@@ -51,7 +51,7 @@ module SimpleTree
51
51
  def descendants
52
52
  return [] if children.empty?
53
53
  nodes = children
54
- children.each {|c| nodes + c.descendants}
54
+ children.each {|c| nodes = nodes + c.descendants}
55
55
  nodes
56
56
  end
57
57
 
@@ -16,14 +16,15 @@ describe SimpleTree do
16
16
  before do
17
17
  @root = Test.create :name => 'root'
18
18
  @c1 = Test.create :name => 'child1', :parent => @root
19
- @c2 = Test.create :name => 'child1', :parent => @root
20
- @gc1a = Test.create :name => 'child1', :parent => @c1
21
- @gc2a = Test.create :name => 'child1', :parent => @c2
19
+ @c2 = Test.create :name => 'child2', :parent => @root
20
+ @gc1a = Test.create :name => 'child1 > child a', :parent => @c1
21
+ @gc2a = Test.create :name => 'child2 > child a', :parent => @c2
22
22
  end
23
23
 
24
24
  describe "#children" do
25
25
  it "should return all children" do
26
26
  @root.children.should == [@c1,@c2]
27
+ @c1.children.should == [@gc1a]
27
28
  end
28
29
  end
29
30
 
@@ -40,4 +41,38 @@ describe SimpleTree do
40
41
  @root.root.should == @root
41
42
  end
42
43
  end
44
+
45
+ describe "#siblings" do
46
+ it "should return siblings for a child" do
47
+ @c1.siblings.should == [@c2]
48
+ end
49
+ it "should return empty array for root" do
50
+ @root.siblings.should == []
51
+ end
52
+ end
53
+
54
+ describe '#self_and_siblings' do
55
+ it "should return siblings and self for a child" do
56
+ @c1.self_and_siblings.should == [@c1,@c2]
57
+ end
58
+ it "should return empty array for root" do
59
+ @root.self_and_siblings.should == []
60
+ end
61
+ end
62
+ describe '#descendants' do
63
+ it "should return all descendants" do
64
+ @root.descendants.should == [@c1,@c2,@gc1a,@gc2a]
65
+ end
66
+ end
67
+
68
+ describe '#move_to_child_of' do
69
+ it "should move a branch to it's new parents" do
70
+ @gc2a.move_to_child_of(@root)
71
+ @gc2a.save
72
+ @gc2a.reload
73
+ @root.reload
74
+ @root.children.should == [@c1,@c2,@gc2a]
75
+ @c2.children.should == []
76
+ end
77
+ end
43
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70330458747320 !ruby/object:Gem::Requirement
16
+ requirement: &70132630472340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70330458747320
24
+ version_requirements: *70132630472340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: with_model
27
- requirement: &70330458746900 !ruby/object:Gem::Requirement
27
+ requirement: &70132630471920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70330458746900
35
+ version_requirements: *70132630471920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70330458746400 !ruby/object:Gem::Requirement
38
+ requirement: &70132630471400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.0.9
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70330458746400
46
+ version_requirements: *70132630471400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70330458745980 !ruby/object:Gem::Requirement
49
+ requirement: &70132630470980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70330458745980
57
+ version_requirements: *70132630470980
58
58
  description: simple tree gem
59
59
  email:
60
60
  - yinghai.zhao@mosaic.com