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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2efbc10260f22d9266cedf4f51ea25db0e7385e0
4
- data.tar.gz: e07926dc9a02d5c22f8f49abd91305a94d96e3f3
3
+ metadata.gz: caf4b036f06eefaca63f1c88fd04f4acb8d17173
4
+ data.tar.gz: 32a71b36f7e617c50a0bed809a5cc0229abe6ce6
5
5
  SHA512:
6
- metadata.gz: 0328b760885d2a4442a1f4dedfcf741f6cd18f4a1902924287a06ca41fef76f7c927d8a110dfd869350fc02dc0aefde9381652d7d5f1dd25dad199c5b7b19491
7
- data.tar.gz: 24970a25867dc1550a658f569a84c4e596d53748268ab944a8424c2367f9221537f39cb04736aaf944992af541adb7a514fe43e4daddf68b919a8430ae279ee1
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.or(parent_ids.map { |id| { :_id => id } })
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.parent_id = self.parent_id
395
+ c.parent = self.parent
394
396
  c.save
395
397
  end
396
398
  end
@@ -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.3
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-07-16 00:00:00.000000000 Z
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.0.0
116
+ rubygems_version: 2.1.2
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: A tree structure for Mongoid documents