mongoid-tree 1.0.3 → 1.0.4
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.
- checksums.yaml +4 -4
- data/lib/mongoid/tree.rb +4 -2
- data/spec/mongoid/tree_spec.rb +21 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf4b036f06eefaca63f1c88fd04f4acb8d17173
|
4
|
+
data.tar.gz: 32a71b36f7e617c50a0bed809a5cc0229abe6ce6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a57abc31fc56609eb406ed5278870945e48b666652dbf2cb824ce71f9cd0d0ba104945bbab8cfa2222e343e06b159d484dd14bc30facc3ec09fe4a8284cb71d
|
7
|
+
data.tar.gz: dbfd2350fbdeae186273be215fffbaca14a747b14ca07cb5200ae75a169964a47e706d9b8e9238b1f092ddc2a279d75d596e9bc83df8621323382578e3349e1f
|
data/lib/mongoid/tree.rb
CHANGED
@@ -273,7 +273,9 @@ module Mongoid
|
|
273
273
|
# @return [Mongoid::Criteria] Mongoid criteria to retrieve the documents ancestors
|
274
274
|
def ancestors
|
275
275
|
if parent_ids.any?
|
276
|
-
base_class.
|
276
|
+
base_class.and({
|
277
|
+
'$or' => parent_ids.map { |id| { :_id => id } }
|
278
|
+
})
|
277
279
|
else
|
278
280
|
base_class.where(:_id.in => [])
|
279
281
|
end
|
@@ -390,7 +392,7 @@ module Mongoid
|
|
390
392
|
# @return [undefined]
|
391
393
|
def move_children_to_parent
|
392
394
|
children.each do |c|
|
393
|
-
c.
|
395
|
+
c.parent = self.parent
|
394
396
|
c.save
|
395
397
|
end
|
396
398
|
end
|
data/spec/mongoid/tree_spec.rb
CHANGED
@@ -170,6 +170,11 @@ describe Mongoid::Tree do
|
|
170
170
|
expect(node(:child)).to be_leaf
|
171
171
|
expect(node(:root).children.to_a).to match_array([node(:child), node(:other_child), node(:subchild)])
|
172
172
|
end
|
173
|
+
|
174
|
+
it "should be able to handle a missing parent" do
|
175
|
+
node(:root).delete
|
176
|
+
expect { node(:child).move_children_to_parent }.to_not raise_error
|
177
|
+
end
|
173
178
|
end
|
174
179
|
|
175
180
|
describe ':destroy_children' do
|
@@ -293,6 +298,22 @@ describe Mongoid::Tree do
|
|
293
298
|
root = Node.new(:name => 'root')
|
294
299
|
expect(root.ancestors).to be_empty
|
295
300
|
end
|
301
|
+
|
302
|
+
it 'should allow chaning of other `or`-criterias' do
|
303
|
+
setup_tree <<-ENDTREE
|
304
|
+
- root:
|
305
|
+
- child:
|
306
|
+
- subchild:
|
307
|
+
- subsubchild
|
308
|
+
ENDTREE
|
309
|
+
|
310
|
+
filtered_ancestors = node(:subsubchild).ancestors.or(
|
311
|
+
{ :name => 'child' },
|
312
|
+
{ :name => 'subchild' }
|
313
|
+
)
|
314
|
+
|
315
|
+
expect(filtered_ancestors.to_a).to eq([node(:child), node(:subchild)])
|
316
|
+
end
|
296
317
|
end
|
297
318
|
|
298
319
|
describe '#ancestors_and_self' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.1.2
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: A tree structure for Mongoid documents
|