glebtv-mongoid_nested_set 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c33f021b3089d426f8cd762d26c1527892c483c2
4
- data.tar.gz: a2c4b42b74fac204f78bdead4dab8ded122389ff
3
+ metadata.gz: 0e1e7293361d84a09bef083837a25965156e79ea
4
+ data.tar.gz: 0f88693f2a679bf73cbd4b4960afbd6ff6c78aff
5
5
  SHA512:
6
- metadata.gz: 28bec66a742952b69fe7fbedbeeac8e4377a8ff33330c5e81767314f34a78cc5dd9519806424cc43657d8fd33afeb7bc87833b1d59412c4917082949acc13743
7
- data.tar.gz: 7b60408b936e2adc0bf80138b316a7a6255c85a721a451a4c56d64afef3e46f93486c2ae147ce50f3b8d747b56b6578883f7742ec6b10f862e8ce486d008c410
6
+ metadata.gz: 986372406b76254d3f874b7f1c0ba3c8a13002049d4c4b2d19858c8c6afc7d99c7d7c1fb0db303263b55b8fecc12e9064e2d1f441fc3c7a584cc00a32c569445
7
+ data.tar.gz: bb7b734fdabd023dd5fd1339813b5d55004476068040ef94fbb1c78d8421db9195d92418a29fdc9147300c41d416abdbf416d5cf7b49276003ab5f5c3d31b50e
@@ -28,8 +28,14 @@ module Mongoid::Acts::NestedSet
28
28
  )
29
29
  end
30
30
 
31
+ # scope rebuild for specified node
32
+ tree_scope = self.where(parent_field_name => nil)
33
+ if acts_as_nested_set_options[:scope] && options[:scope]
34
+ tree_scope = tree_scope.where( acts_as_nested_set_options[:scope] => options[:scope] )
35
+ end
36
+
31
37
  # Find root node(s)
32
- root_nodes = self.where(parent_field_name => nil).asc(left_field_name).asc(right_field_name).asc(:_id).each do |root_node|
38
+ root_nodes = tree_scope.asc(left_field_name).asc(right_field_name).asc(:_id).each do |root_node|
33
39
  # setup index for this scope
34
40
  indices[scope.call(root_node)] ||= 0
35
41
  set_left_and_rights.call(root_node)
@@ -1,3 +1,3 @@
1
1
  module MongoidNestedSet
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -666,7 +666,7 @@ describe "A Mongoid::Document" do
666
666
 
667
667
  context "in an adjaceny list tree" do
668
668
  before(:each) do
669
- @nodes = create_clothing_nodes(Node)
669
+ @nodes = create_clothing_nodes.merge(create_electronics_nodes)
670
670
  @nodes.each_value { |node| node.test_set_attributes(:rgt => nil) }
671
671
  persist_nodes(@nodes)
672
672
  end
@@ -684,6 +684,25 @@ describe "A Mongoid::Document" do
684
684
  @nodes[:skirts] .reload.should have_nestedset_pos(17, 18)
685
685
  end
686
686
 
687
+ it "can rebuild nested set properties for specified scope" do
688
+ Node.rebuild!( scope: 2 )
689
+
690
+ root = Node.where( root_id: 1 ).root
691
+ root.should be_a(Node)
692
+ root.rgt.should == nil
693
+
694
+ root = Node.where( root_id: 2 ).root
695
+ root.should be_a(Node)
696
+ root.name.should == 'Electronics'
697
+
698
+ @nodes[:electronics].reload.should have_nestedset_pos( 1, 20)
699
+ @nodes[:televisions].reload.should have_nestedset_pos( 2, 9)
700
+ @nodes[:tube] .reload.should have_nestedset_pos( 3, 4)
701
+ @nodes[:portable] .reload.should have_nestedset_pos(10, 19)
702
+ @nodes[:mp3] .reload.should have_nestedset_pos(11, 14)
703
+ @nodes[:flash] .reload.should have_nestedset_pos(12, 13)
704
+ end
705
+
687
706
  end
688
707
  end
689
708
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glebtv-mongoid_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GlebTV
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-03 00:00:00.000000000 Z
12
+ date: 2014-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid