mm-tree 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -11,7 +11,10 @@ Rational numbers is even better than left/right trees, as you can remove parts o
11
11
 
12
12
  == Installation
13
13
 
14
- I assume you are using bundler, so add this to your Gemfile:
14
+ If you are using bundler, and want latest stable gem
15
+ gem 'mm-tree'
16
+
17
+ For latest edge version:
15
18
  gem 'mm-tree', :git => 'http://github.com/leifcr/mm-tree.git'
16
19
 
17
20
  == Usage
@@ -187,7 +187,13 @@ module MongoMapper
187
187
  def set_nv_dv_if_missing
188
188
  return if !tree_use_rational_numbers
189
189
  if (self.tree_info.nv == 0 || self.tree_info.dv == 0 )
190
- new_keys = self.next_keys_available(self[tree_parent_id_field], (self.has_siblings? + 1) )
190
+ last_sibling = self.siblings.last
191
+ if (last_sibling == nil)
192
+ last_sibling_position = 0
193
+ else
194
+ last_sibling_position = self.class.position_from_nv_dv(last_sibling.tree_info.nv, last_sibling.tree_info.dv)
195
+ end
196
+ new_keys = self.next_keys_available(self[tree_parent_id_field], (last_sibling_position + 1) )
191
197
  self.tree_info.nv = new_keys[:nv]
192
198
  self.tree_info.dv = new_keys[:dv]
193
199
  self.tree_info.snv = new_keys[:snv]
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
3
  module Tree
4
- Version = '0.1.0'
4
+ Version = '0.1.1'
5
5
  end
6
6
  end
data/test/test_tree.rb CHANGED
@@ -270,7 +270,7 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
270
270
  assert @node_2_4_1_1.ancestor_tree_keys() == @node_2_4_1.tree_keys(), "After move: #{@node_2_4_1_1.name} ancestor keys should match #{@node_2_4_1.name} got: #{@node_2_4_1_1.ancestor_tree_keys()} expected: #{@node_2_4_1.tree_keys()}"
271
271
  end
272
272
 
273
- should "should have changed nv/dv after changing parent (id)" do
273
+ should "have changed nv/dv after changing parent (id)" do
274
274
  old_keys = @node_1_2.tree_keys()
275
275
  @node_1_2.parent = @node_2
276
276
  # before saved
@@ -286,6 +286,15 @@ class TestMongomapperActsAsTree < Test::Unit::TestCase
286
286
  # should still be able to find correct keys for child of moved item
287
287
  assert @node_1_2_1.ancestor_tree_keys() == @node_1_2.tree_keys(), "After move #{@node_1_2_1.name} ancestor keys should match #{@node_1_2.name} got: #{@node_1_2_1.ancestor_tree_keys()} expected: #{@node_1_2.tree_keys()}"
288
288
  end
289
+
290
+ should "have correct keys after destroying a sibling and creating a new item" do
291
+ old_id = @node_1_2._id
292
+ @node_1_2.destroy
293
+ Category.find(old_id).should == nil
294
+ node_1_4 = Category.create(:name => "Node 1.4", :parent => @node_1)
295
+ node_1_4.tree_keys.should_not == Hash[:nv => 7, :dv => 4, :snv => 9, :sdv => 5]
296
+ node_1_4.tree_keys.should == Hash[:nv => 9, :dv => 5, :snv => 11, :sdv => 6]
297
+ end
289
298
  end # tree keys
290
299
 
291
300
  should "rekey the entire treestructre" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo_mapper
@@ -61,12 +61,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  - - ! '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
+ segments:
65
+ - 0
66
+ hash: -3601179477307526079
64
67
  required_rubygems_version: !ruby/object:Gem::Requirement
65
68
  none: false
66
69
  requirements:
67
70
  - - ! '>='
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0'
73
+ segments:
74
+ - 0
75
+ hash: -3601179477307526079
70
76
  requirements: []
71
77
  rubyforge_project:
72
78
  rubygems_version: 1.8.24