cuca 0.03 → 0.04
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +39 -0
- data/application_skeleton/conf/config.rb +24 -5
- data/application_skeleton/public/dispatch.cgi +2 -15
- data/application_skeleton/public/dispatch.fcgi +4 -15
- data/lib/cuca.rb +5 -1
- data/lib/cuca/app.rb +97 -170
- data/lib/cuca/cgi_emu.rb +9 -0
- data/lib/cuca/cgi_fix.rb +10 -0
- data/lib/cuca/config.rb +67 -0
- data/lib/cuca/const.rb +1 -1
- data/lib/cuca/controller.rb +67 -26
- data/lib/cuca/layout.rb +1 -0
- data/lib/cuca/session.rb +7 -3
- data/lib/cuca/sessionpage.rb +1 -0
- data/lib/cuca/stdlib/arform.rb +12 -1
- data/lib/cuca/stdlib/listwidget/dblist.rb +2 -1
- data/lib/cuca/stdlib/listwidget/list.rb +5 -4
- data/lib/cuca/test/helpers.rb +3 -1
- data/lib/cuca/urlmap-original.rb +324 -0
- data/lib/cuca/urlmap.rb +68 -13
- data/lib/cuca/urlmap2.rb +22 -0
- data/lib/cuca/widget.rb +6 -6
- data/tests/all.rb +8 -0
- data/tests/app.rb +37 -0
- data/tests/controller.rb +163 -0
- data/tests/generator_markaby.rb +123 -0
- data/tests/generator_view.rb +76 -0
- data/tests/mimetypes.rb +20 -0
- data/tests/test_app/README +1 -0
- data/tests/test_app/app/_views/test_template.rhtml +1 -0
- data/tests/test_app/app/agent/index.rb +0 -0
- data/tests/test_app/app/agent/list.rb +0 -0
- data/tests/test_app/app/user/__username/index.rb +0 -0
- data/tests/test_app/app/user/list.rb +0 -0
- data/tests/test_app/conf/config.rb +0 -0
- data/tests/test_app/conf/environment.rb +0 -0
- data/tests/test_app/log/messages +1 -0
- data/tests/urlmap.rb +96 -0
- data/tests/widget.rb +153 -0
- metadata +33 -4
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
$cuca_path = File.expand_path("#{File.dirname(__FILE__)}/test_app")
|
6
|
+
require 'cuca'
|
7
|
+
require 'cuca/generator/markaby'
|
8
|
+
|
9
|
+
# Outputs parameters
|
10
|
+
class TestMabAWidget < Cuca::Widget
|
11
|
+
include Cuca::Generator::Markaby
|
12
|
+
|
13
|
+
def output(param1='one', param2='two')
|
14
|
+
mab { b { param1}; b {param2}}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Outputs a markaby block
|
19
|
+
class TestMabBWidget < Cuca::Widget
|
20
|
+
include Cuca::Generator::Markaby
|
21
|
+
|
22
|
+
def output(&block)
|
23
|
+
mab { b { text capture(&block) } }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Takes intance variable @i and output's it
|
28
|
+
class TestMabCWidget < Cuca::Widget
|
29
|
+
include Cuca::Generator::Markaby
|
30
|
+
|
31
|
+
def output()
|
32
|
+
@i = 'test'
|
33
|
+
mab { text @i }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# takes instance variable from TestC and mab's it with 'i'
|
38
|
+
class TestMabDWidget < TestMabCWidget
|
39
|
+
include Cuca::Generator::Markaby
|
40
|
+
|
41
|
+
def output()
|
42
|
+
super
|
43
|
+
clear
|
44
|
+
mab { i { @i } }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# should produce 'onetwothree' - check multicall
|
49
|
+
class TestMabEWidget < TestMabCWidget
|
50
|
+
include Cuca::Generator::Markaby
|
51
|
+
|
52
|
+
def output()
|
53
|
+
mab { 'one' }
|
54
|
+
mab { 'two' }
|
55
|
+
s = mabtext { 'three' }
|
56
|
+
content << s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# uses instance methods as markaby reference, outputs '<b>TestMe</b>'
|
61
|
+
class TestMabFWidget < Cuca::Widget
|
62
|
+
include Cuca::Generator::Markaby
|
63
|
+
|
64
|
+
def testme
|
65
|
+
'TestMe'
|
66
|
+
end
|
67
|
+
|
68
|
+
def output
|
69
|
+
mab { b { testme } }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# G embedds F
|
74
|
+
class TestMabGWidget < Cuca::Widget
|
75
|
+
include Cuca::Generator::Markaby
|
76
|
+
|
77
|
+
def output
|
78
|
+
mab { i { TestMabF() }}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
class TestGeneratorMarkaby < Test::Unit::TestCase
|
85
|
+
|
86
|
+
def test_basic
|
87
|
+
t = TestMabAWidget.new
|
88
|
+
assert_equal '<b>one</b><b>two</b>', t.to_s
|
89
|
+
|
90
|
+
t = TestMabAWidget.new(:args => ['xxx', 'yyy'])
|
91
|
+
assert_equal '<b>xxx</b><b>yyy</b>', t.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_markabyblock
|
95
|
+
t = TestMabBWidget.new { i { 'abc' }}
|
96
|
+
assert_equal '<b><i>abc</i></b>', t.to_s
|
97
|
+
|
98
|
+
t = TestMabBWidget.new { h1 { 'cde' }}
|
99
|
+
assert_equal '<b><h1>cde</h1></b>', t.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_ivar
|
103
|
+
t = TestMabCWidget.new
|
104
|
+
assert_equal 'test', t.to_s
|
105
|
+
|
106
|
+
t2 = TestMabDWidget.new
|
107
|
+
assert_equal '<i>test</i>', t2.to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_multicall
|
111
|
+
assert_equal 'onetwothree', TestMabEWidget.new.to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_instancemethod
|
115
|
+
assert_equal '<b>TestMe</b>', TestMabFWidget.new.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_embedding_others
|
119
|
+
assert_equal '<i><b>TestMe</b></i>', TestMabGWidget.new.to_s
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
$cuca_path = File.expand_path("#{File.dirname(__FILE__)}/test_app")
|
6
|
+
require 'cuca'
|
7
|
+
require 'cuca/generator/view'
|
8
|
+
|
9
|
+
# Cuca::App.configure do |conf|
|
10
|
+
# conf.view_directory="#{$cuca_path}/app/_views"
|
11
|
+
# end
|
12
|
+
|
13
|
+
class TestViewAWidget < Cuca::Widget
|
14
|
+
include Cuca::Generator::View
|
15
|
+
|
16
|
+
def output
|
17
|
+
@test = 'TEST'
|
18
|
+
view('test_template.rhtml')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# test viewtext
|
23
|
+
class TestViewBWidget < Cuca::Widget
|
24
|
+
include Cuca::Generator::View
|
25
|
+
|
26
|
+
def output
|
27
|
+
@test = 'TEST'
|
28
|
+
@_content = viewtext('test_template.rhtml')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
class TestViewCWidget < Cuca::Widget
|
34
|
+
include Cuca::Generator::View
|
35
|
+
|
36
|
+
def output
|
37
|
+
@test = 'TEST'
|
38
|
+
view_p(templ)
|
39
|
+
end
|
40
|
+
|
41
|
+
def templ
|
42
|
+
return <<-'EOT'
|
43
|
+
<b><%= @test %></b>
|
44
|
+
EOT
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class TestViewDWidget < Cuca::Widget
|
49
|
+
include Cuca::Generator::View
|
50
|
+
|
51
|
+
def output
|
52
|
+
@test = 'TEST'
|
53
|
+
@_content = viewtext_p(templ)
|
54
|
+
end
|
55
|
+
|
56
|
+
def templ
|
57
|
+
return <<-'EOT'
|
58
|
+
<b><%= @test %></b>
|
59
|
+
EOT
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
class TestViewGenerator < Test::Unit::TestCase
|
65
|
+
|
66
|
+
def test_external_template
|
67
|
+
assert_equal '<p>TEST</p>', TestViewAWidget.new.to_s
|
68
|
+
assert_equal '<p>TEST</p>', TestViewBWidget.new.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_internal_template
|
72
|
+
assert_equal '<b>TEST</b>', TestViewCWidget.new.to_s.strip
|
73
|
+
assert_equal '<b>TEST</b>', TestViewDWidget.new.to_s.strip
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/tests/mimetypes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'cuca/mimetypes'
|
6
|
+
|
7
|
+
|
8
|
+
class TestMimeTypes < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_mimetypes
|
11
|
+
mt = Cuca::MimeTypes.new
|
12
|
+
# just check for frequently used extensions
|
13
|
+
assert_equal 'video/x-msvideo', mt['avi']
|
14
|
+
assert_equal 'text/javascript', mt['js']
|
15
|
+
assert_equal 'text/html', mt['html']
|
16
|
+
assert_equal 'audio/mpeg', mt['mp3']
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This directory is for the unit tests, it doesn't make sense for anything else.
|
@@ -0,0 +1 @@
|
|
1
|
+
<p><%= @test %></p>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Logfile created on Wed Jun 04 06:05:39 +0100 2008 by /
|
data/tests/urlmap.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
require 'cuca'
|
5
|
+
require 'cuca/urlmap'
|
6
|
+
|
7
|
+
|
8
|
+
Cuca::App.configure do |c|
|
9
|
+
c.magic_prefix = '__'
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# test/app
|
14
|
+
# /user
|
15
|
+
# list.rb
|
16
|
+
# /__username/
|
17
|
+
# index.rb
|
18
|
+
# /agent/
|
19
|
+
# index.rb
|
20
|
+
# list.rb
|
21
|
+
|
22
|
+
|
23
|
+
class URLMapTest < Test::Unit::TestCase
|
24
|
+
def path
|
25
|
+
File.expand_path("#{File.dirname(__FILE__)}/test_app/app")
|
26
|
+
# File.expand_path("#{__FILE__}/test_app/")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_user_list
|
30
|
+
map = ::Cuca::URLMap.new(path, '/user/list')
|
31
|
+
assert map.script.include?('/user/list.rb')
|
32
|
+
assert !map.subcall
|
33
|
+
assert_equal map.action, 'list'
|
34
|
+
assert map.script.include?(map.action_path) # action path must be part of script
|
35
|
+
assert map.script.include?(map.action_path_full)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_default_action
|
39
|
+
map = ::Cuca::URLMap.new(path, '/agent/')
|
40
|
+
assert_equal map.action, 'index'
|
41
|
+
|
42
|
+
assert_raise Cuca::RoutingError do
|
43
|
+
::Cuca::URLMap.new(path, '/') # no default index
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_user_list_subcall
|
48
|
+
map = ::Cuca::URLMap.new(path, '/user/-list-test')
|
49
|
+
assert map.subcall
|
50
|
+
assert_equal map.action, 'list'
|
51
|
+
assert map.script.include?('/user/list.rb')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_invalid_path
|
55
|
+
assert_raise Cuca::RoutingError do
|
56
|
+
::Cuca::URLMap.new(path, '/some/invalid/path')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_invalid_subcall
|
61
|
+
assert_raise Cuca::RoutingError do
|
62
|
+
map = ::Cuca::URLMap.new(path, '/user/-list')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_magic_path
|
67
|
+
map = ::Cuca::URLMap.new(path, '/user/martin/')
|
68
|
+
assert map.assigns.has_key?('username')
|
69
|
+
assert_equal map.assigns['username'], 'martin'
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_mount
|
73
|
+
Cuca::App.configure do |c|
|
74
|
+
c.mount = { '/user/__username/agent/' => "#{path}/agent/" }
|
75
|
+
end
|
76
|
+
|
77
|
+
map = ::Cuca::URLMap.new(path, '/user/martin/agent/index')
|
78
|
+
assert map.script.include?('/agent/index.rb')
|
79
|
+
|
80
|
+
Cuca::App.configure do |c|
|
81
|
+
c.mount = {}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_module
|
86
|
+
map = ::Cuca::URLMap.new(path, '/agent/index')
|
87
|
+
map2 = ::Cuca::URLMap.new(path, '/agent/list')
|
88
|
+
assert_equal map.action_module.object_id, map2.action_module.object_id
|
89
|
+
|
90
|
+
map2 = ::Cuca::URLMap.new(path, '/user/list')
|
91
|
+
|
92
|
+
assert !(map.action_module.object_id == map2.action_module.object_id)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
data/tests/widget.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
$cuca_path = File.expand_path("#{File.dirname(__FILE__)}/test_app")
|
6
|
+
require 'cuca'
|
7
|
+
require 'cuca/urlmap'
|
8
|
+
|
9
|
+
|
10
|
+
class TestAWidget < Cuca::Widget
|
11
|
+
def output(param1='one', param2='two')
|
12
|
+
content << "#{param1}-#{param2}"
|
13
|
+
@v1 = 'test1'
|
14
|
+
@v2 = 'test2'
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_ivar(var)
|
18
|
+
instance_variable_get(var)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TestBWidget < TestAWidget
|
23
|
+
def output(param1='one', param2='two')
|
24
|
+
super(param1, param2)
|
25
|
+
@_content = "(#{content})"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class TestCWidget < Cuca::Widget
|
30
|
+
def output(&block)
|
31
|
+
@_content = block.call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class TestBaseWidget < Cuca::Widget
|
37
|
+
class << self
|
38
|
+
def set_something(whatever)
|
39
|
+
define_attr_method 'something', whatever
|
40
|
+
end
|
41
|
+
|
42
|
+
def append_something(whatever)
|
43
|
+
s = run_attr_method('something') || []
|
44
|
+
s << whatever
|
45
|
+
define_attr_method 'something', s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class TestDWidget < TestBaseWidget
|
52
|
+
set_something 'stuff'
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestEWidget < TestBaseWidget
|
56
|
+
append_something 'a'
|
57
|
+
append_something 'b'
|
58
|
+
append_something 'c'
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class WidgetTest < Test::Unit::TestCase
|
63
|
+
|
64
|
+
def setup
|
65
|
+
@app = Cuca::App.new
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_content
|
69
|
+
w = Cuca::Widget.new
|
70
|
+
w.content = 'test'
|
71
|
+
assert_equal w.content, 'test'
|
72
|
+
w.clear
|
73
|
+
assert w.content == ''
|
74
|
+
|
75
|
+
t = TestAWidget.new
|
76
|
+
assert_equal t.to_s, 'one-two'
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_hints
|
80
|
+
w = Cuca::Widget.new
|
81
|
+
w.hints['hint1'] = 'h1'
|
82
|
+
w2 = Cuca::Widget.new
|
83
|
+
assert_equal w2.hints['hint1'], 'h1'
|
84
|
+
w2.hints['hint2'] = 'h2'
|
85
|
+
assert_equal w.hints['hint2'], 'h2'
|
86
|
+
|
87
|
+
Cuca::Widget::clear_hints
|
88
|
+
|
89
|
+
assert w.hints, {}
|
90
|
+
assert w2.hints, {}
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_external_accessors
|
94
|
+
w = Cuca::Widget.new
|
95
|
+
assert w.app.instance_of?(Cuca::App)
|
96
|
+
assert w.log.instance_of?(Logger)
|
97
|
+
|
98
|
+
# these two are nil because we didn't run from cgi or from controller
|
99
|
+
assert w.cgi.nil?
|
100
|
+
# assert w.controller.nil? # we can't test on this
|
101
|
+
|
102
|
+
require 'cuca/cgi_emu'
|
103
|
+
@app.cgicall(CGIEmu.new('PATH_INFO' => '/'))
|
104
|
+
|
105
|
+
assert w.cgi.kind_of?(CGI)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_assigns
|
109
|
+
w = Cuca::Widget.new(:assigns => { 'p1' => 'test1', 'p2' => 'test2' })
|
110
|
+
|
111
|
+
assert w.get_assigns['p1'] == 'test1'
|
112
|
+
|
113
|
+
w = TestAWidget.new(:assigns => { 'p1' => 'test1', 'p2' => 'test2' } )
|
114
|
+
assert w.get_assigns['p1'] == 'test1'
|
115
|
+
assert w.get_assigns['p2'] == 'test2'
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_params
|
119
|
+
t = TestAWidget.new(:args => ['x', 'z'])
|
120
|
+
assert_equal 'x-z', t.to_s
|
121
|
+
t = TestAWidget.new(:args => ['three'])
|
122
|
+
assert_equal 'three-two', t.to_s
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_subclass
|
126
|
+
t = TestBWidget.new
|
127
|
+
assert_equal '(one-two)', t.to_s
|
128
|
+
t = TestBWidget.new(:args=> ['a', 'b'])
|
129
|
+
assert_equal '(a-b)', t.to_s
|
130
|
+
assert_equal 'test2', t.get_assigns['v2']
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_widget_with_block
|
134
|
+
w = TestCWidget.new { "BLOCK" }
|
135
|
+
assert_equal "BLOCK", w.to_s
|
136
|
+
|
137
|
+
w = TestCWidget.new { "BLOCK2" }
|
138
|
+
assert_equal "BLOCK2", w.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_attr_method
|
142
|
+
assert_equal 'stuff', TestDWidget.run_attr_method('something')
|
143
|
+
|
144
|
+
a = TestEWidget.run_attr_method('something')
|
145
|
+
assert a.instance_of?(Array)
|
146
|
+
assert_equal 3, a.length
|
147
|
+
assert a.include?('a')
|
148
|
+
assert a.include?('b')
|
149
|
+
assert a.include?('c')
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
end
|