nested_set 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,6 +103,10 @@ module CollectiveIdea #:nodoc:
103
103
  where("#{quoted_right_column_name} - #{quoted_left_column_name} = 1").
104
104
  order(quoted_left_column_name)
105
105
  }
106
+ scope :nodes, lambda {
107
+ where("(#{quoted_right_column_name} - #{quoted_left_column_name} - 1) / 2 != 0").
108
+ order(quoted_left_column_name)
109
+ }
106
110
  scope :with_depth, proc {|level| where(:"#{depth_column_name}" => level).order(quoted_left_column_name) }
107
111
 
108
112
  define_callbacks :move, :terminator => "result == false"
@@ -282,7 +286,7 @@ module CollectiveIdea #:nodoc:
282
286
  end
283
287
 
284
288
  def nodes_for_rebuild(node, node_scope)
285
- where(parent_column_name => node).
289
+ where(parent_column_name => node.id).
286
290
  where(node_scope).
287
291
  order(order_for_rebuild).
288
292
  all
@@ -22,7 +22,9 @@ module CollectiveIdea #:nodoc:
22
22
  # Update cached_level attribute
23
23
  def update_depth
24
24
  send :"#{depth_column_name}=", level
25
- if depth_changed?
25
+ depth_changed = send :"#{depth_column_name}_changed?"
26
+ if depth_changed
27
+ depth_change = send :"#{depth_column_name}_change"
26
28
  self.self_and_descendants.
27
29
  update_all(["#{self.class.quoted_depth_column_name} = COALESCE(#{self.class.quoted_depth_column_name}, 0) + ?",
28
30
  depth_change[1] - depth_change[0].to_i])
@@ -32,7 +34,7 @@ module CollectiveIdea #:nodoc:
32
34
  # Update cached_level attribute for all record tree
33
35
  def update_all_depth
34
36
  if has_depth_column?
35
- self.class.connection.execute("UPDATE #{self.class.quoted_table_name} a SET a.depth = \
37
+ self.class.connection.execute("UPDATE #{self.class.quoted_table_name} a SET a.#{self.class.quoted_depth_column_name} = \
36
38
  (SELECT count(*) - 1 FROM (SELECT * FROM #{self.class.quoted_table_name} WHERE #{scope_condition}) AS b \
37
39
  WHERE #{scope_condition('a')} AND \
38
40
  (a.#{quoted_left_column_name} BETWEEN b.#{quoted_left_column_name} AND b.#{quoted_right_column_name}))
@@ -23,7 +23,7 @@ module CollectiveIdea #:nodoc:
23
23
  #
24
24
  # <%= f.select :parent_id, nested_set_options(Category, @category) {|i, level|
25
25
  # "#{'–' * level} #{i.name}"
26
- # }) %>
26
+ # } %>
27
27
  #
28
28
  def nested_set_options(class_or_items, mover = nil, options = {})
29
29
  items = case
@@ -1,3 +1,3 @@
1
1
  module NestedSet
2
- VERSION = "1.7.0"
2
+ VERSION = "1.7.1"
3
3
  end
@@ -138,6 +138,13 @@ class NestedSetTest < ActiveSupport::TestCase
138
138
  assert Category.leaves.include?(categories(:top_level_2))
139
139
  end
140
140
 
141
+ def test_nodes_class_method
142
+ assert_equal Category.find(:all, :conditions => "(#{Category.right_column_name} - #{Category.left_column_name} - 1) / 2 != 0"), Category.nodes
143
+ assert_equal Category.nodes.count, 2
144
+ assert Category.nodes.include?(categories(:top_level))
145
+ assert Category.nodes.include?(categories(:child_2))
146
+ end
147
+
141
148
  def test_leaf
142
149
  assert categories(:child_1).leaf?
143
150
  assert categories(:child_2_1).leaf?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-21 00:00:00.000000000 Z
13
+ date: 2012-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
17
- requirement: &7512700 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *7512700
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: activerecord
28
- requirement: &7510820 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 3.0.0
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *7510820
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rails
39
- requirement: &7508320 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 3.0.0
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *7508320
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: sqlite3
50
- requirement: &7504440 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *7504440
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: bench_press
61
- requirement: &7502500 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,7 +86,12 @@ dependencies:
66
86
  version: 0.3.1
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *7502500
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 0.3.1
70
95
  description: An awesome nested set implementation for Active Record
71
96
  email:
72
97
  - info@collectiveidea.com
@@ -115,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
140
  version: '0'
116
141
  segments:
117
142
  - 0
118
- hash: 1989674500396068183
143
+ hash: 2463211120196063113
119
144
  required_rubygems_version: !ruby/object:Gem::Requirement
120
145
  none: false
121
146
  requirements:
@@ -124,10 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
149
  version: '0'
125
150
  segments:
126
151
  - 0
127
- hash: 1989674500396068183
152
+ hash: 2463211120196063113
128
153
  requirements: []
129
154
  rubyforge_project:
130
- rubygems_version: 1.8.15
155
+ rubygems_version: 1.8.24
131
156
  signing_key:
132
157
  specification_version: 3
133
158
  summary: An awesome nested set implementation for Active Record