crudtree 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +46 -0
- data/lib/crudtree.rb +3 -0
- data/lib/crudtree/generator.rb +87 -0
- data/lib/crudtree/helper.rb +19 -0
- data/lib/crudtree/interface.rb +14 -0
- data/lib/crudtree/interface/usher.rb +43 -0
- data/lib/crudtree/interface/usher/rack.rb +40 -0
- data/lib/crudtree/tree.rb +3 -0
- data/lib/crudtree/tree/endnode.rb +44 -0
- data/lib/crudtree/tree/master.rb +20 -0
- data/lib/crudtree/tree/node.rb +129 -0
- data/test/helper/suite/lib/generator.rb +44 -0
- data/test/helper/suite/lib/integration.rb +9 -0
- data/test/helper/suite/lib/interface/blackbox.rb +36 -0
- data/test/setup.rb +6 -0
- data/test/suite/lib/generator.rb +244 -0
- data/test/suite/lib/integration.rb +33 -0
- data/test/suite/lib/interface/blackbox.rb +132 -0
- data/test/suite/lib/interface/usher.rb +55 -0
- data/test/suite/lib/interface/usher/rack.rb +90 -0
- data/test/suite/lib/tree/endnode.rb +27 -0
- data/test/suite/lib/tree/master.rb +9 -0
- data/test/suite/lib/tree/node.rb +91 -0
- metadata +77 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'crudtree/interface/usher'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module CRUDtree::Interface::Usher
|
5
|
+
public :compile_subnode, :compile_node
|
6
|
+
extend self
|
7
|
+
end
|
8
|
+
|
9
|
+
BareTest.suite "CRUDtree" do
|
10
|
+
|
11
|
+
suite "interface" do
|
12
|
+
|
13
|
+
suite "usher" do
|
14
|
+
|
15
|
+
suite "#compile_subnode" do
|
16
|
+
|
17
|
+
setup :subnode, "Node" do
|
18
|
+
@pre_path = "/foo"
|
19
|
+
@subnode = Node.new(nil, klass: Object, paths: "foo", model: Object) {:foo}
|
20
|
+
CRUDtree::Interface::Usher.expects(:compile_node).with("/foo/:id", @subnode).returns(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
setup :subnode, "EndNode" do
|
24
|
+
@pre_path = ""
|
25
|
+
@subnode = EndNode.allocate
|
26
|
+
CRUDtree::Interface::Usher.expects(:compile_subnode).with(@pre_path, @subnode).returns(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
assert "Compilation with a :subnode as subnode" do
|
30
|
+
CRUDtree::Interface::Usher.compile_subnode(@pre_path, @subnode)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
suite "#compile_node" do
|
36
|
+
|
37
|
+
setup do
|
38
|
+
@subnode = Object.new
|
39
|
+
@pre_path = "/baz"
|
40
|
+
@node = OpenStruct.new(paths: ["foo", "bar"], subnodes: [@subnode])
|
41
|
+
CRUDtree::Interface::Usher.expects(:compile_subnode).with("/baz/foo", @subnode).returns(true)
|
42
|
+
CRUDtree::Interface::Usher.expects(:compile_subnode).with("/baz/bar", @subnode).returns(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
assert "compilation" do
|
46
|
+
CRUDtree::Interface::Usher.compile_node(@pre_path, @node)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'crudtree/interface/usher/rack'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
BareTest.suite "CRUDtree" do
|
7
|
+
|
8
|
+
suite "interface" do
|
9
|
+
|
10
|
+
suite "usher" do
|
11
|
+
|
12
|
+
suite "rack" do
|
13
|
+
|
14
|
+
setup do
|
15
|
+
module CRUDtree::Interface::Usher::Rack
|
16
|
+
public :compile_path
|
17
|
+
extend self
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestObj < Object; end
|
21
|
+
class TestObj2 < Object; end
|
22
|
+
class Cont1 < Object; end
|
23
|
+
class Cont2 < Object; end
|
24
|
+
end
|
25
|
+
|
26
|
+
suite "#compile_path" do
|
27
|
+
|
28
|
+
setup :subnode, "a simple member subnode" do
|
29
|
+
@pre_path = ""
|
30
|
+
@node = OpenStruct.new(klass: TestObj, identifier: :id, paths: "testobj")
|
31
|
+
@subnode = EndNode.new(@node, type: :member, call: :foo, name: "foo")
|
32
|
+
@path = "/testobj/:id/foo"
|
33
|
+
@params = {conditions: {}}
|
34
|
+
@send = [:foo]
|
35
|
+
@master_params = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
setup :subnode, "a more complex collection subnode" do
|
39
|
+
@pre_path = "/bar"
|
40
|
+
@node = OpenStruct.new(klass: TestObj, identifier: :id, paths: "testobj")
|
41
|
+
@subnode = EndNode.new(@node, type: :collection, call: :foo, name: "foo")
|
42
|
+
@path = "/bar/testobj/foo"
|
43
|
+
@params = {conditions: {}}
|
44
|
+
@send = [:dispatcher, :foo]
|
45
|
+
@master_params = {rango: true}
|
46
|
+
end
|
47
|
+
|
48
|
+
setup :subnode, "a nested collection subnode" do
|
49
|
+
@pre_path = ""
|
50
|
+
@node1 = Node.new(nil, klass: Cont1, identifier: :id, paths: "cont1", model: Object){:foo}
|
51
|
+
@node2 = Node.new(@node1, klass: TestObj, model: Object){:foo}
|
52
|
+
@subnode = EndNode.new(@node2, type: :collection, call: :foo, name: "foo", model: Object)
|
53
|
+
@path = "/cont1/:id/testobj/foo"
|
54
|
+
@params = {conditions: {}}
|
55
|
+
@send = [:dispatcher, :foo]
|
56
|
+
@master_params = {rango: true}
|
57
|
+
end
|
58
|
+
|
59
|
+
setup :subnode, "a nested member subnode" do
|
60
|
+
@pre_path = ""
|
61
|
+
@node1 = Node.new(nil, klass: Cont1, identifier: :id, paths: "cont1", model: Object){:foo}
|
62
|
+
@node2 = Node.new(@node1, klass: TestObj, model: Object){:foo}
|
63
|
+
@subnode = EndNode.new(@node2, type: :member, call: :foo, name: "foo")
|
64
|
+
@path = "/cont1/:id/testobj/:id/foo"
|
65
|
+
@params = {conditions: {}}
|
66
|
+
@send = [:foo]
|
67
|
+
@master_params = {}
|
68
|
+
end
|
69
|
+
|
70
|
+
setup :foo, "Foo" do
|
71
|
+
TestObj.expects(:send).with(*@send).returns(:yeah)
|
72
|
+
TestObj2.any_instance.expects(:to).with(:yeah)
|
73
|
+
CRUDtree::Interface::Usher::Rack.expects(:master_params).returns(@master_params)
|
74
|
+
CRUDtree::Interface::Usher::Rack.expects(:path).with(@path, @params).returns(TestObj2.new)
|
75
|
+
end
|
76
|
+
|
77
|
+
assert "compilaton with :subnode" do
|
78
|
+
CRUDtree::Interface::Usher::Rack.compile_path(@pre_path, @subnode)
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
BareTest.suite "CRUDtree" do
|
2
|
+
|
3
|
+
suite "tree" do
|
4
|
+
|
5
|
+
suite "EndNode" do
|
6
|
+
|
7
|
+
suite "initialize" do
|
8
|
+
|
9
|
+
assert ":type should only accept :member or :collection" do
|
10
|
+
raises(ArgumentError) {EndNode.new(nil, type: :foo, call: :foo)}
|
11
|
+
end
|
12
|
+
|
13
|
+
assert ":call should not accept an empty argument" do
|
14
|
+
raises(ArgumentError) {EndNode.new(nil, type: :member, path: "/foo")}
|
15
|
+
end
|
16
|
+
|
17
|
+
assert ":path should default to :call" do
|
18
|
+
EndNode.new(nil, type: :member, call: :foo, name: :foo).path == "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
BareTest.suite "CRUDtree" do
|
2
|
+
|
3
|
+
suite "tree" do
|
4
|
+
|
5
|
+
suite "node" do
|
6
|
+
|
7
|
+
suite "initialize" do
|
8
|
+
|
9
|
+
suite "paths" do
|
10
|
+
|
11
|
+
assert "defaults to the name of the class" do
|
12
|
+
Node.new(nil, klass: Node, model: Object){:foo}.paths == ["node"]
|
13
|
+
end
|
14
|
+
|
15
|
+
assert "raises if no path is given" do
|
16
|
+
raises(ArgumentError) {Node.new(nil, foo: :bar){:foo}}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
assert "raises if no block is given" do
|
22
|
+
raises(ArgumentError) {Node.new(nil, foo: :bar)}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
suite "extended subnodes" do
|
28
|
+
|
29
|
+
setup :method, "#member" do
|
30
|
+
@method = :member
|
31
|
+
end
|
32
|
+
|
33
|
+
setup :method, "#collection" do
|
34
|
+
@method = :collection
|
35
|
+
end
|
36
|
+
|
37
|
+
setup :node, "node" do
|
38
|
+
@node = Node.allocate
|
39
|
+
@params = {foo: :bar}
|
40
|
+
@result = @params.merge({type: @method})
|
41
|
+
@node.expects(:endnode).with(@result)
|
42
|
+
end
|
43
|
+
|
44
|
+
assert ":method" do
|
45
|
+
case @method
|
46
|
+
when :member
|
47
|
+
@node.member @params
|
48
|
+
when :collection
|
49
|
+
@node.collection @params
|
50
|
+
end
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
suite "tree walking" do
|
57
|
+
|
58
|
+
setup :master, "a simple master" do
|
59
|
+
@master = Master.new
|
60
|
+
@node = @master.node(klass: Object, model: Object){:foo}
|
61
|
+
@parents = []
|
62
|
+
@children = {}
|
63
|
+
end
|
64
|
+
|
65
|
+
suite "#parents" do
|
66
|
+
|
67
|
+
setup :master, "a more complex master" do
|
68
|
+
@master = Master.new
|
69
|
+
@master.node(klass: Object, model: Object){
|
70
|
+
node(klass: Object, model: Object){
|
71
|
+
node(klass: Object, model: Object){:foo}
|
72
|
+
node(klass: Object, model: Object){:foo}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
@node = @master.nodes.first.nodes.first.nodes.first
|
76
|
+
@parents = [@master.nodes.first.nodes.first,@master.nodes.first]
|
77
|
+
end
|
78
|
+
|
79
|
+
assert "it find the parents in :master" do
|
80
|
+
equal(@node.parents, @parents)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crudtree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Hafner aka Tass
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
date: 2010-02-15 00:00:00 +01:00
|
12
|
+
default_executable:
|
13
|
+
dependencies: []
|
14
|
+
|
15
|
+
description: ""
|
16
|
+
email: hafnersimon@gmail.com
|
17
|
+
executables: []
|
18
|
+
|
19
|
+
extensions: []
|
20
|
+
|
21
|
+
extra_rdoc_files: []
|
22
|
+
|
23
|
+
files:
|
24
|
+
- lib/crudtree/generator.rb
|
25
|
+
- lib/crudtree/helper.rb
|
26
|
+
- lib/crudtree/interface/usher/rack.rb
|
27
|
+
- lib/crudtree/interface/usher.rb
|
28
|
+
- lib/crudtree/interface.rb
|
29
|
+
- lib/crudtree/tree/endnode.rb
|
30
|
+
- lib/crudtree/tree/master.rb
|
31
|
+
- lib/crudtree/tree/node.rb
|
32
|
+
- lib/crudtree/tree.rb
|
33
|
+
- lib/crudtree.rb
|
34
|
+
- test/helper/suite/lib/generator.rb
|
35
|
+
- test/helper/suite/lib/integration.rb
|
36
|
+
- test/helper/suite/lib/interface/blackbox.rb
|
37
|
+
- test/setup.rb
|
38
|
+
- test/suite/lib/generator.rb
|
39
|
+
- test/suite/lib/integration.rb
|
40
|
+
- test/suite/lib/interface/blackbox.rb
|
41
|
+
- test/suite/lib/interface/usher/rack.rb
|
42
|
+
- test/suite/lib/interface/usher.rb
|
43
|
+
- test/suite/lib/tree/endnode.rb
|
44
|
+
- test/suite/lib/tree/master.rb
|
45
|
+
- test/suite/lib/tree/node.rb
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/Tass/CRUDtree
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "1.9"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A resource helper mainly for usher, but may be adapted for other routers as well.
|
76
|
+
test_files: []
|
77
|
+
|