mongoid_acts_as_tree 0.2.0 → 0.3.0.rc0

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.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2@mongoid_acts_as_tree
1
+ rvm 1.9.3@mongoid_acts_as_tree --create
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'mongoid'
4
+ gem 'mongo'
4
5
  gem 'bson'
5
6
  gem 'bson_ext'
6
7
  gem 'shoulda'
data/Gemfile.lock CHANGED
@@ -1,32 +1,44 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.7)
5
- activesupport (= 3.0.7)
6
- builder (~> 2.1.2)
7
- i18n (~> 0.5.0)
8
- activesupport (3.0.7)
9
- bson (1.3.1)
10
- bson_ext (1.3.1)
11
- builder (2.1.2)
12
- gemcutter (0.7.0)
4
+ activemodel (3.2.8)
5
+ activesupport (= 3.2.8)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.8)
8
+ i18n (~> 0.6)
9
+ multi_json (~> 1.0)
10
+ bson (1.7.0)
11
+ bson_ext (1.7.0)
12
+ bson (~> 1.7.0)
13
+ builder (3.0.3)
13
14
  git (1.2.5)
14
- i18n (0.5.0)
15
- jeweler (1.4.0)
16
- gemcutter (>= 0.1.0)
15
+ i18n (0.6.1)
16
+ jeweler (1.8.4)
17
+ bundler (~> 1.0)
17
18
  git (>= 1.2.5)
18
- rubyforge (>= 2.0.0)
19
- json_pure (1.5.1)
19
+ rake
20
+ rdoc
21
+ json (1.7.5)
20
22
  mongo (1.3.1)
21
23
  bson (>= 1.3.1)
22
- mongoid (2.0.2)
23
- activemodel (~> 3.0)
24
- mongo (~> 1.3)
24
+ mongoid (3.0.5)
25
+ activemodel (~> 3.1)
26
+ moped (~> 1.1)
27
+ origin (~> 1.0)
25
28
  tzinfo (~> 0.3.22)
26
- rubyforge (2.0.4)
27
- json_pure (>= 1.1.7)
28
- shoulda (2.11.3)
29
- tzinfo (0.3.27)
29
+ moped (1.2.1)
30
+ multi_json (1.3.6)
31
+ origin (1.0.8)
32
+ rake (0.9.2.2)
33
+ rdoc (3.12)
34
+ json (~> 1.4)
35
+ shoulda (3.1.1)
36
+ shoulda-context (~> 1.0)
37
+ shoulda-matchers (~> 1.2)
38
+ shoulda-context (1.0.0)
39
+ shoulda-matchers (1.3.0)
40
+ activesupport (>= 3.0.0)
41
+ tzinfo (0.3.33)
30
42
 
31
43
  PLATFORMS
32
44
  ruby
@@ -35,5 +47,6 @@ DEPENDENCIES
35
47
  bson
36
48
  bson_ext
37
49
  jeweler
50
+ mongo
38
51
  mongoid
39
52
  shoulda
data/Rakefile CHANGED
@@ -2,53 +2,52 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mongoid_acts_as_tree"
8
- gem.summary = %Q{ActsAsTree plugin for Mongoid}
9
- gem.description = %Q{Port of the old, venerable ActsAsTree with a bit of a twist}
10
- gem.email = "saksmlz@gmail.com"
11
- gem.homepage = "http://github.com/saks/mongoid_acts_as_tree"
12
- gem.authors = ["Jakob Vidmar, Aliaksandr Rahalevich"]
13
- gem.add_dependency("mongoid", ">= 2.0.0")
14
- gem.add_dependency("bson", ">= 0.20.1")
15
-
16
- gem.add_development_dependency "shoulda", ">=2.10.2"
17
- end
18
- Jeweler::GemcutterTasks.new
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mongoid_acts_as_tree"
8
+ gem.summary = %Q{ActsAsTree plugin for Mongoid}
9
+ gem.description = %Q{Port of the old, venerable ActsAsTree with a bit of a twist}
10
+ gem.email = "saksmlz@gmail.com"
11
+ gem.homepage = "http://github.com/saks/mongoid_acts_as_tree"
12
+ gem.authors = ["Jakob Vidmar, Aliaksandr Rahalevich"]
13
+ gem.add_dependency("mongoid", ">= 2.0.0")
14
+ gem.add_dependency("bson", ">= 0.20.1")
15
+
16
+ gem.add_development_dependency "shoulda", ">=2.10.2"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
19
  rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
21
  end
22
22
 
23
23
  require 'rake/testtask'
24
24
  Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/test_*.rb'
27
- test.verbose = true
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
28
  end
29
29
 
30
30
  begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
37
  rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
41
  end
42
42
 
43
43
  task :default => :test
44
44
 
45
- require 'rake/rdoctask'
45
+ require 'rdoc/task'
46
46
  Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
48
 
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "mongoid_acts_as_tree #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "mongoid_acts_as_tree #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
53
  end
54
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0.rc0
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: 'acts_as_tree-test'
5
+ hosts:
6
+ - localhost:27017
@@ -12,9 +12,9 @@ module Mongoid
12
12
  module InitializerMethods
13
13
  def acts_as_tree(options = {})
14
14
  options = {
15
- :parent_id_field => "parent_id",
16
- :path_field => "path",
17
- :depth_field => "depth",
15
+ :parent_id_field => 'parent_id',
16
+ :path_field => 'path',
17
+ :depth_field => 'depth',
18
18
  :class => self
19
19
  }.merge(options)
20
20
 
@@ -27,19 +27,22 @@ module Mongoid
27
27
  extend ClassMethods
28
28
 
29
29
  field parent_id_field, :type => BSON::ObjectId
30
- field path_field, :type => Array, :default => [], :index => true
30
+ field path_field, :type => Array, :default => []
31
31
  field depth_field, :type => Integer, :default => 0
32
32
 
33
+ index path_field => 1
34
+
35
+
33
36
  self.class_eval do
34
37
  define_method "#{parent_id_field}=" do | new_parent_id |
35
- if new_parent_id.present?
38
+ if new_parent_id.present?
36
39
  new_parent = acts_as_tree_options[:class].find new_parent_id
37
40
  new_parent.children.push self, false
38
41
  else
39
42
  self.write_attribute parent_id_field, nil
40
43
  self[path_field] = []
41
44
  self[depth_field] = 0
42
- end
45
+ end
43
46
  end
44
47
  end
45
48
 
@@ -103,7 +106,7 @@ module Mongoid
103
106
 
104
107
  def ancestors
105
108
  return [] if root?
106
- acts_as_tree_options[:class].where(:_id.in => self[path_field]).order_by(depth_field)
109
+ acts_as_tree_options[:class].in(_id: self[path_field])
107
110
  end
108
111
 
109
112
  def self_and_ancestors
@@ -165,12 +168,11 @@ module Mongoid
165
168
  end
166
169
 
167
170
  def move_children
168
-
169
171
  if @_will_move
170
172
  @_will_move = false
171
173
  self.children.each do | child |
172
174
  child.fix_position
173
- child.save
175
+ child.save
174
176
  end
175
177
  @_will_move = true
176
178
  end
@@ -219,15 +221,15 @@ module Mongoid
219
221
  #To delete object use <tt>object.destroy</tt>.
220
222
  def delete(object_or_id)
221
223
  object = case object_or_id
222
- when String, BSON::ObjectId
223
- @parent.class.find object_or_id
224
- else
225
- object_or_id
224
+ when String, Moped::BSON::ObjectId
225
+ @parent.class.find object_or_id
226
+ else
227
+ object_or_id
226
228
  end
227
229
 
228
230
  object.write_attribute object.parent_id_field, nil
229
- object[object.path_field] = []
230
- object[object.depth_field] = 0
231
+ object[object.path_field] = []
232
+ object[object.depth_field] = 0
231
233
  object.save
232
234
 
233
235
  super(object)
@@ -269,4 +271,3 @@ module Mongoid
269
271
  end
270
272
  end
271
273
  end
272
-
@@ -1,68 +1,77 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mongoid_acts_as_tree"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0.rc0"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakob Vidmar, Aliaksandr Rahalevich"]
12
- s.date = "2012-01-24"
12
+ s.date = "2012-09-11"
13
13
  s.description = "Port of the old, venerable ActsAsTree with a bit of a twist"
14
14
  s.email = "saksmlz@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- ".rvmrc",
23
- "CHANGELOG",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "lib/mongoid_acts_as_tree.rb",
31
- "mongoid_acts_as_tree.gemspec",
32
- "test/helper.rb",
33
- "test/models/category.rb",
34
- "test/models/ordered_category.rb",
35
- "test/models/sub_category.rb",
36
- "test/test_order.rb",
37
- "test/test_tree.rb"
21
+ ".rvmrc",
22
+ "CHANGELOG",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "config/mongoid.yml",
30
+ "lib/mongoid_acts_as_tree.rb",
31
+ "mongoid_acts_as_tree.gemspec",
32
+ "test/helper.rb",
33
+ "test/models/category.rb",
34
+ "test/models/ordered_category.rb",
35
+ "test/models/sub_category.rb",
36
+ "test/test_order.rb",
37
+ "test/test_tree.rb"
38
38
  ]
39
39
  s.homepage = "http://github.com/saks/mongoid_acts_as_tree"
40
- s.rdoc_options = ["--charset=UTF-8"]
41
40
  s.require_paths = ["lib"]
42
- s.rubygems_version = "1.8.10"
41
+ s.rubygems_version = "1.8.24"
43
42
  s.summary = "ActsAsTree plugin for Mongoid"
44
- s.test_files = [
45
- "test/models/category.rb",
46
- "test/models/ordered_category.rb",
47
- "test/models/sub_category.rb",
48
- "test/helper.rb",
49
- "test/test_tree.rb",
50
- "test/test_order.rb"
51
- ]
52
43
 
53
44
  if s.respond_to? :specification_version then
54
45
  s.specification_version = 3
55
46
 
56
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
49
+ s.add_runtime_dependency(%q<mongo>, [">= 0"])
50
+ s.add_runtime_dependency(%q<bson>, [">= 0"])
51
+ s.add_runtime_dependency(%q<bson_ext>, [">= 0"])
52
+ s.add_runtime_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
57
54
  s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0"])
58
55
  s.add_runtime_dependency(%q<bson>, [">= 0.20.1"])
59
56
  s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
60
57
  else
58
+ s.add_dependency(%q<mongoid>, [">= 0"])
59
+ s.add_dependency(%q<mongo>, [">= 0"])
60
+ s.add_dependency(%q<bson>, [">= 0"])
61
+ s.add_dependency(%q<bson_ext>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, [">= 0"])
61
64
  s.add_dependency(%q<mongoid>, [">= 2.0.0"])
62
65
  s.add_dependency(%q<bson>, [">= 0.20.1"])
63
66
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
64
67
  end
65
68
  else
69
+ s.add_dependency(%q<mongoid>, [">= 0"])
70
+ s.add_dependency(%q<mongo>, [">= 0"])
71
+ s.add_dependency(%q<bson>, [">= 0"])
72
+ s.add_dependency(%q<bson_ext>, [">= 0"])
73
+ s.add_dependency(%q<shoulda>, [">= 0"])
74
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
75
  s.add_dependency(%q<mongoid>, [">= 2.0.0"])
67
76
  s.add_dependency(%q<bson>, [">= 0.20.1"])
68
77
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
data/test/helper.rb CHANGED
@@ -1,33 +1,33 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'mongo'
5
+ require 'mongoid'
4
6
 
5
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'mongoid'
8
9
 
9
- Mongoid.configure.master = Mongo::Connection.new.db('acts_as_tree-test')
10
+ Mongoid.load! '/home/mlz/projects/mongoid_acts_as_tree/config/mongoid.yml', :test
10
11
 
11
12
  Dir["#{File.dirname(__FILE__)}/models/*.rb"].each {|file| require file}
12
13
 
13
14
  class Test::Unit::TestCase
14
- # Drop all columns after each test case.
15
- def teardown
16
- Mongoid.database.collections.each do |coll|
17
- coll.remove
18
- end
19
- end
15
+ # Drop all columns after each test case.
16
+ def teardown
17
+ Mongoid::session(:default).collections.each do |coll|
18
+ coll.drop
19
+ end
20
+ end
20
21
 
21
- # Make sure that each test case has a teardown
22
- # method to clear the db after each test.
23
- def inherited(base)
24
- base.define_method teardown do
25
- super
26
- end
27
- end
22
+ # Make sure that each test case has a teardown
23
+ # method to clear the db after each test.
24
+ def inherited(base)
25
+ base.define_method teardown do
26
+ super
27
+ end
28
+ end
28
29
 
29
- def eql_arrays?(first, second)
30
- first.map{|i| i._id}.to_set == second.map{|i| i._id}.to_set
31
- end
30
+ def eql_arrays?(first, second)
31
+ first.map{|i| i._id}.to_set == second.map{|i| i._id}.to_set
32
+ end
32
33
  end
33
-
@@ -2,11 +2,10 @@ require "mongoid"
2
2
  require "mongoid_acts_as_tree"
3
3
 
4
4
  class Category
5
- include Mongoid::Document
6
- include Mongoid::Acts::Tree
5
+ include Mongoid::Document
6
+ include Mongoid::Acts::Tree
7
7
 
8
- field :name, :type => String
8
+ field :name, :type => String
9
9
 
10
- acts_as_tree
10
+ acts_as_tree
11
11
  end
12
-
@@ -1,3 +1,5 @@
1
+ require File.join File.dirname(__FILE__), 'category'
2
+
1
3
  class SubCategory < Category
2
4
 
3
5
  end
data/test/test_order.rb CHANGED
@@ -1,35 +1,34 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
  require 'set'
3
3
 
4
4
  class TestMongoidActsAsTree < Test::Unit::TestCase
5
- context "Ordered tree" do
6
- setup do
7
- @root_1 = OrderedCategory.create(:name => "Root 1", :value => 2)
8
- @child_1 = OrderedCategory.create(:name => "Child 1", :value => 1)
9
- @child_2 = OrderedCategory.create(:name => "Child 2", :value => 9)
10
- @child_2_1 = OrderedCategory.create(:name => "Child 2.1", :value => 2)
11
-
12
- @child_3 = OrderedCategory.create(:name => "Child 3", :value => 5)
13
- @root_2 = OrderedCategory.create(:name => "Root 2", :value => 1)
14
-
15
- @root_1.children << @child_1
16
- @root_1.children << @child_2
17
- @root_1.children << @child_3
18
-
19
- @child_2.children << @child_2_1
20
- end
21
-
22
- should "be in order" do
23
- assert_equal OrderedCategory.roots.to_a, [@root_2, @root_1]
24
- assert_equal @root_1.children, [@child_1, @child_3, @child_2]
25
-
26
- assert_equal @root_1.descendants, [@child_1, @child_2_1, @child_3, @child_2]
27
- assert_equal @root_1.self_and_descendants, [@root_1, @child_1, @child_2_1, @child_3, @child_2]
28
-
29
- assert_equal @child_2.siblings, [@child_1, @child_3]
30
- assert_equal @child_2.self_and_siblings, [@child_1, @child_3, @child_2]
31
- assert_equal @root_1.self_and_siblings, [@root_2, @root_1]
32
- end
33
- end
5
+ context "Ordered tree" do
6
+ setup do
7
+ @root_1 = OrderedCategory.create(:name => "Root 1", :value => 2)
8
+ @child_1 = OrderedCategory.create(:name => "Child 1", :value => 1)
9
+ @child_2 = OrderedCategory.create(:name => "Child 2", :value => 9)
10
+ @child_2_1 = OrderedCategory.create(:name => "Child 2.1", :value => 2)
11
+
12
+ @child_3 = OrderedCategory.create(:name => "Child 3", :value => 5)
13
+ @root_2 = OrderedCategory.create(:name => "Root 2", :value => 1)
14
+
15
+ @root_1.children << @child_1
16
+ @root_1.children << @child_2
17
+ @root_1.children << @child_3
18
+
19
+ @child_2.children << @child_2_1
20
+ end
21
+
22
+ should "be in order" do
23
+ assert_equal OrderedCategory.roots.to_a, [@root_2, @root_1]
24
+ assert_equal @root_1.children, [@child_1, @child_3, @child_2]
25
+
26
+ assert_equal @root_1.descendants, [@child_1, @child_2_1, @child_3, @child_2]
27
+ assert_equal @root_1.self_and_descendants, [@root_1, @child_1, @child_2_1, @child_3, @child_2]
28
+
29
+ assert_equal @child_2.siblings, [@child_1, @child_3]
30
+ assert_equal @child_2.self_and_siblings, [@child_1, @child_3, @child_2]
31
+ assert_equal @root_1.self_and_siblings, [@root_2, @root_1]
32
+ end
33
+ end
34
34
  end
35
-
data/test/test_tree.rb CHANGED
@@ -4,31 +4,31 @@ require 'set'
4
4
  $verbose = false
5
5
 
6
6
  class TestMongoidActsAsTree < Test::Unit::TestCase
7
- context "Tree" do
8
- setup do
9
- @root_1 = Category.create(:name => "Root 1")
10
- @child_1 = Category.create(:name => "Child 1")
11
- @child_2 = Category.create(:name => "Child 2")
12
- @child_2_1 = SubCategory.create(:name => "Child 2.1")
13
-
14
- @child_3 = SubCategory.create(:name => "Child 3")
15
- @root_2 = Category.create(:name => "Root 2")
16
-
17
- @root_1.children << @child_1
18
- @root_1.children << @child_2
19
- @root_1.children << @child_3
20
-
21
- @child_2.children << @child_2_1
22
- end
23
-
24
- should "add child via create or build" do
25
- @root_1.children.build :name => "Child 2.2"
26
- assert Category.where(:name => "Child 2.2").first.parent == @root_1
27
- end
28
-
29
- should "add child via <<" do
30
- child = Category.create(:name => "Child 2.2")
31
- @root_1.children << child
7
+ context "Tree" do
8
+ setup do
9
+ @root_1 = Category.create(:name => "Root 1")
10
+ @child_1 = Category.create(:name => "Child 1")
11
+ @child_2 = Category.create(:name => "Child 2")
12
+ @child_2_1 = SubCategory.create(:name => "Child 2.1")
13
+
14
+ @child_3 = SubCategory.create(:name => "Child 3")
15
+ @root_2 = Category.create(:name => "Root 2")
16
+
17
+ @root_1.children << @child_1
18
+ @root_1.children << @child_2
19
+ @root_1.children << @child_3
20
+
21
+ @child_2.children << @child_2_1
22
+ end
23
+
24
+ should "add child via create or build" do
25
+ @root_1.children.build :name => "Child 2.2"
26
+ assert Category.where(:name => "Child 2.2").first.parent == @root_1
27
+ end
28
+
29
+ should "add child via <<" do
30
+ child = Category.create(:name => "Child 2.2")
31
+ @root_1.children << child
32
32
  assert child.parent == @root_1
33
33
  end
34
34
 
@@ -54,9 +54,9 @@ class TestMongoidActsAsTree < Test::Unit::TestCase
54
54
  assert_equal([], @root_1.children)
55
55
  end
56
56
 
57
- should "have roots" do
58
- assert eql_arrays?(Category.roots, [@root_1, @root_2])
59
- end
57
+ should "have roots" do
58
+ assert eql_arrays?(Category.roots, [@root_1, @root_2])
59
+ end
60
60
 
61
61
  should "assign parent_id" do
62
62
  child = Category.create :name => 'child'
@@ -111,127 +111,126 @@ class TestMongoidActsAsTree < Test::Unit::TestCase
111
111
  assert_equal [], @child_1.path
112
112
  end
113
113
 
114
- context "node" do
115
- should "have a root" do
116
- assert_equal @root_1.root, @root_1
117
- assert_not_equal @root_1.root, @root_2.root
118
- assert_equal @root_1, @child_2_1.root
119
- end
120
-
121
- should "have ancestors" do
122
- assert_equal @root_1.ancestors, []
123
- assert_equal @child_2.ancestors, [@root_1]
124
- assert_equal @child_2_1.ancestors, [@root_1, @child_2]
125
- assert_equal @root_1.self_and_ancestors, [@root_1]
126
- assert_equal @child_2.self_and_ancestors, [@root_1, @child_2]
127
- assert_equal @child_2_1.self_and_ancestors, [@root_1, @child_2, @child_2_1]
128
- end
129
-
130
- should "have siblings" do
131
- assert eql_arrays?(@root_1.siblings, [@root_2])
132
- assert eql_arrays?(@child_2.siblings, [@child_1, @child_3])
133
- assert eql_arrays?(@child_2_1.siblings, [])
134
- assert eql_arrays?(@root_1.self_and_siblings, [@root_1, @root_2])
135
- assert eql_arrays?(@child_2.self_and_siblings, [@child_1, @child_2, @child_3])
136
- assert eql_arrays?(@child_2_1.self_and_siblings, [@child_2_1])
137
- end
138
-
139
- should "set depth" do
140
- assert_equal 0, @root_1.depth
141
- assert_equal 1, @child_1.depth
142
- assert_equal 2, @child_2_1.depth
143
- end
144
-
145
- should "have children" do
146
- assert @child_2_1.children.empty?
147
- assert eql_arrays?(@root_1.children, [@child_1, @child_2, @child_3])
148
- end
149
-
150
- should "have descendants" do
151
- assert eql_arrays?(@root_1.descendants, [@child_1, @child_2, @child_3, @child_2_1])
152
- assert eql_arrays?(@child_2.descendants, [@child_2_1])
153
- assert @child_2_1.descendants.empty?
154
- assert eql_arrays?(@root_1.self_and_descendants, [@root_1, @child_1, @child_2, @child_3, @child_2_1])
155
- assert eql_arrays?(@child_2.self_and_descendants, [@child_2, @child_2_1])
156
- assert eql_arrays?(@child_2_1.self_and_descendants, [@child_2_1])
157
- end
158
-
159
- should "be able to tell if ancestor" do
160
- assert @root_1.is_ancestor_of?(@child_1)
161
- assert !@root_2.is_ancestor_of?(@child_2_1)
162
- assert !@child_2.is_ancestor_of?(@child_2)
163
-
164
- assert @root_1.is_or_is_ancestor_of?(@child_1)
165
- assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
166
- assert @child_2.is_or_is_ancestor_of?(@child_2)
167
- end
168
-
169
- should "be able to tell if descendant" do
170
- assert !@root_1.is_descendant_of?(@child_1)
171
- assert @child_1.is_descendant_of?(@root_1)
172
- assert !@child_2.is_descendant_of?(@child_2)
173
-
174
- assert !@root_1.is_or_is_descendant_of?(@child_1)
175
- assert @child_1.is_or_is_descendant_of?(@root_1)
176
- assert @child_2.is_or_is_descendant_of?(@child_2)
177
- end
178
-
179
- should "be able to tell if sibling" do
180
- assert !@root_1.is_sibling_of?(@child_1)
181
- assert !@child_1.is_sibling_of?(@child_1)
182
- assert !@child_2.is_sibling_of?(@child_2)
183
-
184
- assert !@root_1.is_or_is_sibling_of?(@child_1)
185
- assert @child_1.is_or_is_sibling_of?(@child_2)
186
- assert @child_2.is_or_is_sibling_of?(@child_2)
187
- end
188
-
189
- context "when moving" do
190
- should "recalculate path and depth" do
114
+ context "node" do
115
+ should "have a root" do
116
+ assert_equal @root_1.root, @root_1
117
+ assert_not_equal @root_1.root, @root_2.root
118
+ assert_equal @root_1, @child_2_1.root
119
+ end
120
+
121
+ should "have ancestors" do
122
+ assert_equal @root_1.ancestors, []
123
+ assert_equal @child_2.ancestors.to_a, [@root_1]
124
+ assert_equal @child_2_1.ancestors.to_a, [@root_1, @child_2]
125
+ assert_equal @root_1.self_and_ancestors, [@root_1]
126
+ assert_equal @child_2.self_and_ancestors, [@root_1, @child_2]
127
+ assert_equal @child_2_1.self_and_ancestors, [@root_1, @child_2, @child_2_1]
128
+ end
129
+
130
+ should "have siblings" do
131
+ assert eql_arrays?(@root_1.siblings, [@root_2])
132
+ assert eql_arrays?(@child_2.siblings, [@child_1, @child_3])
133
+ assert eql_arrays?(@child_2_1.siblings, [])
134
+ assert eql_arrays?(@root_1.self_and_siblings, [@root_1, @root_2])
135
+ assert eql_arrays?(@child_2.self_and_siblings, [@child_1, @child_2, @child_3])
136
+ assert eql_arrays?(@child_2_1.self_and_siblings, [@child_2_1])
137
+ end
138
+
139
+ should "set depth" do
140
+ assert_equal 0, @root_1.depth
141
+ assert_equal 1, @child_1.depth
142
+ assert_equal 2, @child_2_1.depth
143
+ end
144
+
145
+ should "have children" do
146
+ assert @child_2_1.children.empty?
147
+ assert eql_arrays?(@root_1.children, [@child_1, @child_2, @child_3])
148
+ end
149
+
150
+ should "have descendants" do
151
+ assert eql_arrays?(@root_1.descendants, [@child_1, @child_2, @child_3, @child_2_1])
152
+ assert eql_arrays?(@child_2.descendants, [@child_2_1])
153
+ assert @child_2_1.descendants.empty?
154
+ assert eql_arrays?(@root_1.self_and_descendants, [@root_1, @child_1, @child_2, @child_3, @child_2_1])
155
+ assert eql_arrays?(@child_2.self_and_descendants, [@child_2, @child_2_1])
156
+ assert eql_arrays?(@child_2_1.self_and_descendants, [@child_2_1])
157
+ end
158
+
159
+ should "be able to tell if ancestor" do
160
+ assert @root_1.is_ancestor_of?(@child_1)
161
+ assert !@root_2.is_ancestor_of?(@child_2_1)
162
+ assert !@child_2.is_ancestor_of?(@child_2)
163
+
164
+ assert @root_1.is_or_is_ancestor_of?(@child_1)
165
+ assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
166
+ assert @child_2.is_or_is_ancestor_of?(@child_2)
167
+ end
168
+
169
+ should "be able to tell if descendant" do
170
+ assert !@root_1.is_descendant_of?(@child_1)
171
+ assert @child_1.is_descendant_of?(@root_1)
172
+ assert !@child_2.is_descendant_of?(@child_2)
173
+
174
+ assert !@root_1.is_or_is_descendant_of?(@child_1)
175
+ assert @child_1.is_or_is_descendant_of?(@root_1)
176
+ assert @child_2.is_or_is_descendant_of?(@child_2)
177
+ end
178
+
179
+ should "be able to tell if sibling" do
180
+ assert !@root_1.is_sibling_of?(@child_1)
181
+ assert !@child_1.is_sibling_of?(@child_1)
182
+ assert !@child_2.is_sibling_of?(@child_2)
183
+
184
+ assert !@root_1.is_or_is_sibling_of?(@child_1)
185
+ assert @child_1.is_or_is_sibling_of?(@child_2)
186
+ assert @child_2.is_or_is_sibling_of?(@child_2)
187
+ end
188
+
189
+ context "when moving" do
190
+ should "recalculate path and depth" do
191
191
  @child_2.children << @child_3
192
- @child_3.save
192
+ @child_3.save
193
193
 
194
- assert @child_2.is_or_is_ancestor_of?(@child_3)
195
- assert @child_3.is_or_is_descendant_of?(@child_2)
196
- assert @child_2.children.include?(@child_3)
197
- assert @child_2.descendants.include?(@child_3)
198
- assert @child_2_1.is_or_is_sibling_of?(@child_3)
199
- assert_equal 2, @child_3.depth
200
- end
194
+ assert @child_2.is_or_is_ancestor_of?(@child_3)
195
+ assert @child_3.is_or_is_descendant_of?(@child_2)
196
+ assert @child_2.children.include?(@child_3)
197
+ assert @child_2.descendants.include?(@child_3)
198
+ assert @child_2_1.is_or_is_sibling_of?(@child_3)
199
+ assert_equal 2, @child_3.depth
200
+ end
201
201
 
202
- should "move children on save" do
202
+ should "move children on save" do
203
203
  @root_2.children << @child_2
204
204
 
205
205
  @child_2_1.reload
206
206
 
207
- assert @root_2.is_or_is_ancestor_of?(@child_2_1)
208
- assert @child_2_1.is_or_is_descendant_of?(@root_2)
209
- assert @root_2.descendants.include?(@child_2_1)
210
- end
211
-
212
- should "check against cyclic graph" do
213
- @child_2_1.children << @root_1
214
- assert !@root_1.save
215
- end
216
- end
217
-
218
- should "destroy descendants when destroyed" do
219
- @child_2.destroy
220
- assert_nil Category.where(:id => @child_2_1._id).first
221
- end
222
- end
223
-
224
- context "root node" do
225
- should "not have a parent" do
226
- assert_nil @root_1.parent
227
- end
228
- end
229
-
230
- context "child_node" do
231
- should "have a parent" do
232
- assert_equal @child_2, @child_2_1.parent
233
- end
234
- end
235
- end
236
- end
207
+ assert @root_2.is_or_is_ancestor_of?(@child_2_1)
208
+ assert @child_2_1.is_or_is_descendant_of?(@root_2)
209
+ assert @root_2.descendants.include?(@child_2_1)
210
+ end
211
+
212
+ should "check against cyclic graph" do
213
+ @child_2_1.children << @root_1
214
+ assert !@root_1.save
215
+ end
216
+ end
217
+
218
+ should "destroy descendants when destroyed" do
219
+ @child_2.destroy
220
+ assert_nil Category.where(:id => @child_2_1._id).first
221
+ end
222
+ end
237
223
 
224
+ context "root node" do
225
+ should "not have a parent" do
226
+ assert_nil @root_1.parent
227
+ end
228
+ end
229
+
230
+ context "child_node" do
231
+ should "have a parent" do
232
+ assert_equal @child_2, @child_2_1.parent
233
+ end
234
+ end
235
+ end
236
+ end
metadata CHANGED
@@ -1,19 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_acts_as_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0.rc0
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jakob Vidmar, Aliaksandr Rahalevich
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &69860600 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongo
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bson
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bson_ext
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: shoulda
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mongoid
112
+ requirement: !ruby/object:Gem::Requirement
17
113
  none: false
18
114
  requirements:
19
115
  - - ! '>='
@@ -21,10 +117,15 @@ dependencies:
21
117
  version: 2.0.0
22
118
  type: :runtime
23
119
  prerelease: false
24
- version_requirements: *69860600
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 2.0.0
25
126
  - !ruby/object:Gem::Dependency
26
127
  name: bson
27
- requirement: &69860070 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
28
129
  none: false
29
130
  requirements:
30
131
  - - ! '>='
@@ -32,10 +133,15 @@ dependencies:
32
133
  version: 0.20.1
33
134
  type: :runtime
34
135
  prerelease: false
35
- version_requirements: *69860070
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 0.20.1
36
142
  - !ruby/object:Gem::Dependency
37
143
  name: shoulda
38
- requirement: &69859660 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
39
145
  none: false
40
146
  requirements:
41
147
  - - ! '>='
@@ -43,7 +149,12 @@ dependencies:
43
149
  version: 2.10.2
44
150
  type: :development
45
151
  prerelease: false
46
- version_requirements: *69859660
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 2.10.2
47
158
  description: Port of the old, venerable ActsAsTree with a bit of a twist
48
159
  email: saksmlz@gmail.com
49
160
  executables: []
@@ -53,7 +164,6 @@ extra_rdoc_files:
53
164
  - README.rdoc
54
165
  files:
55
166
  - .document
56
- - .gitignore
57
167
  - .rvmrc
58
168
  - CHANGELOG
59
169
  - Gemfile
@@ -62,6 +172,7 @@ files:
62
172
  - README.rdoc
63
173
  - Rakefile
64
174
  - VERSION
175
+ - config/mongoid.yml
65
176
  - lib/mongoid_acts_as_tree.rb
66
177
  - mongoid_acts_as_tree.gemspec
67
178
  - test/helper.rb
@@ -73,8 +184,7 @@ files:
73
184
  homepage: http://github.com/saks/mongoid_acts_as_tree
74
185
  licenses: []
75
186
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
187
+ rdoc_options: []
78
188
  require_paths:
79
189
  - lib
80
190
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -83,22 +193,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
193
  - - ! '>='
84
194
  - !ruby/object:Gem::Version
85
195
  version: '0'
196
+ segments:
197
+ - 0
198
+ hash: 1606393504334424851
86
199
  required_rubygems_version: !ruby/object:Gem::Requirement
87
200
  none: false
88
201
  requirements:
89
- - - ! '>='
202
+ - - ! '>'
90
203
  - !ruby/object:Gem::Version
91
- version: '0'
204
+ version: 1.3.1
92
205
  requirements: []
93
206
  rubyforge_project:
94
- rubygems_version: 1.8.10
207
+ rubygems_version: 1.8.24
95
208
  signing_key:
96
209
  specification_version: 3
97
210
  summary: ActsAsTree plugin for Mongoid
98
- test_files:
99
- - test/models/category.rb
100
- - test/models/ordered_category.rb
101
- - test/models/sub_category.rb
102
- - test/helper.rb
103
- - test/test_tree.rb
104
- - test/test_order.rb
211
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC