mm_tree 0.1.0
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/.gitignore +1 -0
- data/README.rdoc +9 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/test/schema.rb +11 -0
- data/test/test_helper.rb +10 -0
- data/test/traversal_test.rb +36 -0
- data/test/tree_test.rb +27 -0
- metadata +63 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |g|
|
9
|
+
g.name = 'mm_tree'
|
10
|
+
g.summary = %(acts_as_tree port for MongoMapper)
|
11
|
+
g.description = %(acts_as_tree port for MongoMapper)
|
12
|
+
g.email = 'signalstatic@gmail.com'
|
13
|
+
g.homepage = 'http://github.com/twoism/mm_tree'
|
14
|
+
g.authors = %w(twoism)
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts 'Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com'
|
19
|
+
end
|
20
|
+
|
21
|
+
Rake::TestTask.new do |t|
|
22
|
+
t.libs = %w(test)
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/test/schema.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'mongo_mapper'
|
8
|
+
require 'mm_tree'
|
9
|
+
require 'schema'
|
10
|
+
begin; require 'redgreen'; rescue LoadError; end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TraversalTest < Test::Unit::TestCase
|
4
|
+
context 'A tree instance' do
|
5
|
+
setup do
|
6
|
+
Doc.destroy_all
|
7
|
+
@root = Doc.create(:name=>"root")
|
8
|
+
10.times do |n|
|
9
|
+
d = n.zero? ? @root : Doc.find_by_name("doc #{n-1}")
|
10
|
+
d.children << Doc.create(:name=>"doc #{n}")
|
11
|
+
d.children << Doc.create(:name=>"sibling for doc #{n}")
|
12
|
+
d.children << Doc.create(:name=>"sibling 2 for doc #{n}")
|
13
|
+
d.save
|
14
|
+
end
|
15
|
+
@root= Doc.find_by_name("root")
|
16
|
+
@last = Doc.find_by_name("doc 9")
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have children" do
|
20
|
+
assert @root.children.count > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
should "find root" do
|
24
|
+
assert_equal(@root, @last.root)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have corrent number of ancestors" do
|
28
|
+
assert_equal 10, @last.ancestors.count
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have siblings" do
|
32
|
+
assert_equal("sibling for doc 9", @last.siblings.first.name)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/test/tree_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TraversalTest < Test::Unit::TestCase
|
4
|
+
context 'A tree instance' do
|
5
|
+
setup do
|
6
|
+
Doc.destroy_all
|
7
|
+
@doc = Doc.create(:name=>"Hoge")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have 0 depth" do
|
11
|
+
assert_equal 0, @doc.depth
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have the correct assoc" do
|
15
|
+
assert_not_nil Doc.associations["parent"]
|
16
|
+
end
|
17
|
+
|
18
|
+
should "belong to parent" do
|
19
|
+
assert_equal :belongs_to, Doc.associations["parent"].type
|
20
|
+
end
|
21
|
+
|
22
|
+
should "respond to" do
|
23
|
+
[:ancestors,:children,:root,:root?].each {|m| assert @doc.respond_to?(m) }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mm_tree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- twoism
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-18 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: acts_as_tree port for MongoMapper
|
17
|
+
email: signalstatic@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- test/schema.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/twoism/tree
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: acts_as_tree port for MongoMapper
|
59
|
+
test_files:
|
60
|
+
- test/schema.rb
|
61
|
+
- test/test_helper.rb
|
62
|
+
- test/traversal_test.rb
|
63
|
+
- test/tree_test.rb
|