mongoid_acts_as_tree 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -32,7 +32,7 @@ module Mongoid
32
32
  self.class_eval do
33
33
  define_method "#{parent_id_field}=" do | new_parent_id |
34
34
  new_parent = self.class.find new_parent_id
35
- new_parent.children << self
35
+ new_parent.children.push self, false
36
36
  end
37
37
  end
38
38
 
@@ -184,7 +184,7 @@ module Mongoid
184
184
  end
185
185
 
186
186
  #Add new child to list of object children
187
- def <<(object)
187
+ def <<(object, will_save=true)
188
188
  if object.descendants.include? @parent
189
189
  object.instance_variable_set :@_cyclic, true
190
190
  else
@@ -192,12 +192,14 @@ module Mongoid
192
192
  object[object.path_field] = @parent[@parent.path_field] + [@parent._id]
193
193
  object[object.depth_field] = @parent[@parent.depth_field] + 1
194
194
  object.instance_variable_set :@_will_move, true
195
- object.save
195
+ object.save if will_save
196
196
  end
197
197
 
198
198
  super(object)
199
199
  end
200
200
 
201
+ alias push <<
202
+
201
203
  #Deletes object only from children list.
202
204
  #To delete object use <tt>object.destroy</tt>.
203
205
  def delete(object_or_id)
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_acts_as_tree}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakob Vidmar, Aliaksandr Rahalevich"]
data/test/test_tree.rb CHANGED
@@ -67,8 +67,14 @@ class TestMongoidActsAsTree < Test::Unit::TestCase
67
67
  assert_equal 1, child.depth
68
68
  assert_equal [parent.id], child.path
69
69
 
70
- more_deep_child = Category.create :name => 'more deep child'
71
- more_deep_child.parent_id = child.id
70
+ more_deep_child = Category.new(
71
+ :name => 'more deep child',
72
+ :parent_id => child.id
73
+ )
74
+
75
+ assert more_deep_child.new_record?
76
+ more_deep_child.save
77
+ assert !more_deep_child.new_record?
72
78
 
73
79
  assert_equal child.children.first.id, more_deep_child.id
74
80
  assert_equal child.id, more_deep_child.parent_id
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jakob Vidmar, Aliaksandr Rahalevich