ordered_tree 0.1.6 → 0.1.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -8,7 +8,6 @@ module OrderedTree
8
8
  # return is cached
9
9
  # use self_and_siblings(true) to force a reload
10
10
  def self_and_siblings(reload = false)
11
- #parent(reload) ? parent.children(reload) : self.class.roots(scope_condition)
12
11
  parent(reload) ? parent.children(reload) : self.class.roots(scope_condition)
13
12
  end
14
13
 
@@ -141,7 +140,7 @@ module OrderedTree
141
140
  def reorder_roots
142
141
  self.class.transaction do
143
142
  self.class.roots(scope_condition).each do |root|
144
- new_position = self.class.roots.index(root) + 1
143
+ new_position = self.class.roots(scope_condition).index(root) + 1
145
144
  root.update_attribute(order_column, new_position) if (root.position_in_list != new_position)
146
145
  end
147
146
  end
data/ordered_tree.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ordered_tree}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ramon Tayag"]
12
- s.date = %q{2011-06-13}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{Uses parent_id and position to create an ordered tree.}
14
14
  s.email = %q{ramon@tayag.net}
15
15
  s.extra_rdoc_files = [
@@ -24,7 +24,9 @@ describe OrderedTree do
24
24
  Page.create(:person => @people[0]).position.should == 4
25
25
  Page.create(:person => @people[1]).position.should == 2
26
26
  end
27
+ end
27
28
 
29
+ it "should only work within that scope_condition overridden method" do
28
30
  # when the scope_condition method is overridden
29
31
  Page.class_eval do
30
32
  def scope_condition
@@ -37,12 +39,26 @@ describe OrderedTree do
37
39
  page_2.position.should == 1
38
40
  page_3 = Page.create(:person => @people[3], :name => "frankenstein")
39
41
  page_3.position.should == 2
42
+ page_4 = Page.create(:person => @people[3], :name => "frankenstein")
43
+ page_4.position.should == 3
44
+ page_5 = Page.create(:person => @people[4], :name => "frankenstein")
45
+ page_5.position.should == 1
40
46
 
41
47
  # when moving a root to be a child of another
42
48
  page_1.children << page_3
49
+
50
+ # reload all of them
51
+ [page_1, page_2, page_3, page_4, page_5].map(&:reload)
43
52
  page_1.position.should == 1
53
+ page_1.parent.should == nil
44
54
  page_2.position.should == 1
55
+ page_2.parent.should == nil
45
56
  page_3.position.should == 1
57
+ page_3.parent.should == page_1
58
+ page_4.position.should == 2
59
+ page_4.parent.should == nil
60
+ page_5.position.should == 1
61
+ page_5.parent.should == nil
46
62
  end
47
63
  end
48
64
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordered_tree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-13 00:00:00 +08:00
18
+ date: 2011-06-15 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency