mongoid-tree 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,3 +25,8 @@ desc "Push the .gem file to rubygems.org"
25
25
  task :release => :build do
26
26
  system "gem push #{spec.name}-#{spec.version}.gem"
27
27
  end
28
+
29
+ desc "Open an irb session"
30
+ task :console do
31
+ sh "irb -rubygems -I lib -r ./spec/spec_helper.rb"
32
+ end
data/lib/mongoid/tree.rb CHANGED
@@ -268,7 +268,10 @@ module Mongoid # :nodoc:
268
268
  ##
269
269
  # Nullifies all children's parent_id
270
270
  def nullify_children
271
- children.nullify_all
271
+ children.each do |c|
272
+ c.parent = c.parent_id = nil
273
+ c.save
274
+ end
272
275
  end
273
276
 
274
277
  ##
@@ -42,6 +42,12 @@ module Mongoid
42
42
  after_destroy :move_lower_siblings_up
43
43
  end
44
44
 
45
+ ##
46
+ # Returns a chainable criteria for this document's ancestors
47
+ def ancestors
48
+ base_class.unscoped.where(:_id.in => parent_ids)
49
+ end
50
+
45
51
  ##
46
52
  # Returns siblings below the current document.
47
53
  # Siblings with a position greater than this documents's position.
@@ -181,7 +187,7 @@ module Mongoid
181
187
  if self.siblings.empty? || self.siblings.collect(&:position).compact.empty?
182
188
  self.position = 0
183
189
  else
184
- self.position = self.siblings.max(:position) + 1
190
+ self.position = self.siblings.max(:position).to_i + 1
185
191
  end
186
192
  end
187
193
  end
@@ -164,6 +164,20 @@ describe Mongoid::Tree::Ordering do
164
164
  node(:third_root).first_sibling_in_list.should == node(:first_root)
165
165
  end
166
166
  end
167
+
168
+ describe 'ancestors' do
169
+ it "#ancestors should be returned in the correct order" do
170
+ setup_tree <<-ENDTREE
171
+ - root:
172
+ - level_1_a
173
+ - level_1_b:
174
+ - level_2_a:
175
+ - leaf
176
+ ENDTREE
177
+
178
+ node(:leaf).ancestors.to_a.should == [node(:root), node(:level_1_b), node(:level_2_a)]
179
+ end
180
+ end
167
181
  end
168
182
 
169
183
  describe 'moving nodes around' do
metadata CHANGED
@@ -1,84 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tree
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2
4
5
  prerelease:
5
- version: 0.6.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Benedikt Deicke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-12 00:00:00 +02:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: mongoid
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70159403726680 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
18
+ requirements:
22
19
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: "2.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70159403726680
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70159403726180 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
35
32
  version: 0.8.7
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rspec
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70159403726180
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70159403725700 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
40
+ requirements:
44
41
  - - ~>
45
- - !ruby/object:Gem::Version
46
- version: "2.3"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.3'
47
44
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: autotest
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70159403725700
47
+ - !ruby/object:Gem::Dependency
48
+ name: autotest
49
+ requirement: &70159403755660 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
57
54
  version: 4.3.2
58
55
  type: :development
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: hanna-nouveau
62
56
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70159403755660
58
+ - !ruby/object:Gem::Dependency
59
+ name: hanna-nouveau
60
+ requirement: &70159403755180 !ruby/object:Gem::Requirement
64
61
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
68
65
  version: 0.2.2
69
66
  type: :development
70
- version_requirements: *id005
67
+ prerelease: false
68
+ version_requirements: *70159403755180
71
69
  description: A tree structure for Mongoid documents using the materialized path pattern
72
- email:
70
+ email:
73
71
  - benedikt@synatic.net
74
72
  executables: []
75
-
76
73
  extensions: []
77
-
78
- extra_rdoc_files:
74
+ extra_rdoc_files:
79
75
  - README.rdoc
80
76
  - LICENSE
81
- files:
77
+ files:
82
78
  - lib/mongoid/tree/ordering.rb
83
79
  - lib/mongoid/tree/traversal.rb
84
80
  - lib/mongoid/tree.rb
@@ -93,35 +89,32 @@ files:
93
89
  - Rakefile
94
90
  - Gemfile
95
91
  - .rspec
96
- has_rdoc: true
97
92
  homepage: https://github.com/benedikt/mongoid-tree
98
93
  licenses: []
99
-
100
94
  post_install_message:
101
- rdoc_options:
95
+ rdoc_options:
102
96
  - --main
103
97
  - README.rdoc
104
98
  - --charset=UTF-8
105
- require_paths:
99
+ require_paths:
106
100
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
101
+ required_ruby_version: !ruby/object:Gem::Requirement
108
102
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
108
  none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: "0"
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
119
113
  requirements: []
120
-
121
114
  rubyforge_project:
122
- rubygems_version: 1.6.2
115
+ rubygems_version: 1.8.10
123
116
  signing_key:
124
117
  specification_version: 3
125
118
  summary: A tree structure for Mongoid documents
126
119
  test_files: []
127
-
120
+ has_rdoc: