runo 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.
Files changed (149) hide show
  1. data/LICENSE +19 -0
  2. data/README.rdoc +120 -0
  3. data/bin/runo +35 -0
  4. data/lib/_error.rb +14 -0
  5. data/lib/_field.rb +260 -0
  6. data/lib/_i18n.rb +141 -0
  7. data/lib/_parser.rb +243 -0
  8. data/lib/_path.rb +86 -0
  9. data/lib/_storage/_storage.rb +213 -0
  10. data/lib/_storage/file.rb +200 -0
  11. data/lib/_storage/sequel.rb +174 -0
  12. data/lib/_storage/temp.rb +73 -0
  13. data/lib/_widget/action_create.rb +23 -0
  14. data/lib/_widget/action_login.rb +22 -0
  15. data/lib/_widget/action_signup.rb +16 -0
  16. data/lib/_widget/action_update.rb +16 -0
  17. data/lib/_widget/crumb.rb +24 -0
  18. data/lib/_widget/done.rb +16 -0
  19. data/lib/_widget/login.rb +25 -0
  20. data/lib/_widget/me.rb +31 -0
  21. data/lib/_widget/message.rb +51 -0
  22. data/lib/_widget/navi.rb +88 -0
  23. data/lib/_widget/submit.rb +49 -0
  24. data/lib/_widget/view_ym.rb +77 -0
  25. data/lib/_workflow/_workflow.rb +89 -0
  26. data/lib/_workflow/attachment.rb +50 -0
  27. data/lib/_workflow/blog.rb +28 -0
  28. data/lib/_workflow/contact.rb +23 -0
  29. data/lib/_workflow/forum.rb +26 -0
  30. data/lib/_workflow/register.rb +39 -0
  31. data/lib/meta/_meta.rb +20 -0
  32. data/lib/meta/group.rb +19 -0
  33. data/lib/meta/id.rb +59 -0
  34. data/lib/meta/owner.rb +21 -0
  35. data/lib/meta/timestamp.rb +118 -0
  36. data/lib/runo.rb +396 -0
  37. data/lib/scalar/checkbox.rb +68 -0
  38. data/lib/scalar/file.rb +144 -0
  39. data/lib/scalar/img.rb +112 -0
  40. data/lib/scalar/password.rb +58 -0
  41. data/lib/scalar/radio.rb +47 -0
  42. data/lib/scalar/select.rb +47 -0
  43. data/lib/scalar/text.rb +38 -0
  44. data/lib/scalar/textarea.rb +35 -0
  45. data/lib/scalar/textarea_pre.rb +14 -0
  46. data/lib/scalar/textarea_wiki.rb +173 -0
  47. data/lib/set/_set.rb +195 -0
  48. data/lib/set/dynamic.rb +177 -0
  49. data/lib/set/static.rb +102 -0
  50. data/lib/set/static_folder.rb +96 -0
  51. data/locale/en/index.po +242 -0
  52. data/locale/index.pot +243 -0
  53. data/locale/ja/index.po +242 -0
  54. data/locale/lazy_parser.rb +54 -0
  55. data/skel/config.ru +27 -0
  56. data/skel/skin/_users/00000000_frank-avatar.jpg +0 -0
  57. data/skel/skin/_users/00000000_frank-avatar_small.jpg +0 -0
  58. data/skel/skin/_users/00000000_frank.yaml +12 -0
  59. data/skel/skin/_users/00000000_root-avatar.jpg +0 -0
  60. data/skel/skin/_users/00000000_root-avatar_small.jpg +0 -0
  61. data/skel/skin/_users/00000000_root.yaml +11 -0
  62. data/skel/skin/_users/css/users.css +21 -0
  63. data/skel/skin/_users/css/users.less +25 -0
  64. data/skel/skin/_users/done.html +42 -0
  65. data/skel/skin/_users/index.html +46 -0
  66. data/skel/skin/_users/index.yaml +3 -0
  67. data/skel/skin/_users/summary.html +40 -0
  68. data/skel/skin/css/base.css +93 -0
  69. data/skel/skin/css/base.less +139 -0
  70. data/skel/skin/css/coax.css +199 -0
  71. data/skel/skin/css/coax.less +244 -0
  72. data/skel/skin/examples/blog/20091214_0001.yaml +8 -0
  73. data/skel/skin/examples/blog/20100630_0001.yaml +8 -0
  74. data/skel/skin/examples/blog/20100630_0002.yaml +14 -0
  75. data/skel/skin/examples/blog/20100701_0001.yaml +8 -0
  76. data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f.jpg +0 -0
  77. data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f_small.jpg +0 -0
  78. data/skel/skin/examples/blog/20100701_0002.yaml +19 -0
  79. data/skel/skin/examples/blog/frank/20100701_0001.yaml +10 -0
  80. data/skel/skin/examples/blog/frank/index.yaml +4 -0
  81. data/skel/skin/examples/blog/index.html +51 -0
  82. data/skel/skin/examples/blog/rss.xml +18 -0
  83. data/skel/skin/examples/contact/20100701_0001-file.txt +1 -0
  84. data/skel/skin/examples/contact/20100701_0001.yaml +15 -0
  85. data/skel/skin/examples/contact/20100701_0002.yaml +8 -0
  86. data/skel/skin/examples/contact/20100701_0003.yaml +9 -0
  87. data/skel/skin/examples/contact/index.html +47 -0
  88. data/skel/skin/examples/contact/js/contact.js +13 -0
  89. data/skel/skin/examples/contact/summary.html +54 -0
  90. data/skel/skin/examples/forum/20100701_0001.yaml +41 -0
  91. data/skel/skin/examples/forum/20100701_0002.yaml +25 -0
  92. data/skel/skin/examples/forum/index.html +68 -0
  93. data/skel/skin/examples/forum/summary.html +47 -0
  94. data/skel/skin/examples/index.html +75 -0
  95. data/skel/skin/index.html +41 -0
  96. data/skel/skin/js/base.js +50 -0
  97. data/t/locale/de/index.po +19 -0
  98. data/t/locale/en-GB/index.po +25 -0
  99. data/t/locale/ja/index.po +30 -0
  100. data/t/skin/_users/00000000_test.yaml +3 -0
  101. data/t/skin/_users/index.html +13 -0
  102. data/t/skin/foo/20091120_0001.yaml +7 -0
  103. data/t/skin/foo/bar/20091120_0001.yaml +5 -0
  104. data/t/skin/foo/bar/index.yaml +5 -0
  105. data/t/skin/foo/baz/css/baz.css +1 -0
  106. data/t/skin/foo/css/foo.css +1 -0
  107. data/t/skin/foo/index.html +14 -0
  108. data/t/skin/foo/index.yaml +7 -0
  109. data/t/skin/foo/not_css/foo.css +1 -0
  110. data/t/skin/foo/sub-20100306_0001.yaml +3 -0
  111. data/t/skin/index.yaml +3 -0
  112. data/t/skin/t_attachment/index.html +13 -0
  113. data/t/skin/t_contact/done.html +6 -0
  114. data/t/skin/t_contact/index.html +9 -0
  115. data/t/skin/t_file/index.html +16 -0
  116. data/t/skin/t_img/index.html +14 -0
  117. data/t/skin/t_img/test.jpg +0 -0
  118. data/t/skin/t_select/index.html +9 -0
  119. data/t/skin/t_store/index.html +9 -0
  120. data/t/skin/t_summary/20100326_0001.yaml +3 -0
  121. data/t/skin/t_summary/create.html +9 -0
  122. data/t/skin/t_summary/index.html +9 -0
  123. data/t/skin/t_summary/summary.html +9 -0
  124. data/t/t.rb +27 -0
  125. data/t/test_checkbox.rb +273 -0
  126. data/t/test_field.rb +330 -0
  127. data/t/test_file.rb +900 -0
  128. data/t/test_id.rb +215 -0
  129. data/t/test_img.rb +328 -0
  130. data/t/test_meta.rb +57 -0
  131. data/t/test_parser.rb +1266 -0
  132. data/t/test_password.rb +188 -0
  133. data/t/test_radio.rb +226 -0
  134. data/t/test_role.rb +249 -0
  135. data/t/test_runo.rb +742 -0
  136. data/t/test_runo_call.rb +1286 -0
  137. data/t/test_runo_i18n.rb +318 -0
  138. data/t/test_select.rb +182 -0
  139. data/t/test_set_complex.rb +527 -0
  140. data/t/test_set_dynamic.rb +1504 -0
  141. data/t/test_set_folder.rb +515 -0
  142. data/t/test_set_permit.rb +246 -0
  143. data/t/test_set_static.rb +445 -0
  144. data/t/test_storage.rb +915 -0
  145. data/t/test_text.rb +125 -0
  146. data/t/test_textarea.rb +138 -0
  147. data/t/test_timestamp.rb +473 -0
  148. data/t/test_workflow.rb +367 -0
  149. metadata +345 -0
Binary file
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head><title>@(label)</title></head>
3
+ <body>
4
+ <h1>@(label)</h1>
5
+ <ul id="main" class="runo-blog">
6
+ <li>$(name = text 32 1..32 :'foo'): $(comment = text 64 1..64 :'bar!')</li>
7
+ </ul>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head><title>@(label)</title></head>
3
+ <body>
4
+ <h1>@(label)</h1>
5
+ <ul id="main" class="runo-blog">
6
+ <li>$(name = text 32 1..32 :'foo'): $(comment = text 64 1..64 :'bar!')</li>
7
+ </ul>
8
+ </body>
9
+ </html>
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: frank
3
+ comment: hi.
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head><title>create</title></head>
3
+ <body>
4
+ <h1>create</h1>
5
+ <ul id="main" class="runo-blog">
6
+ <li>main-create</li>
7
+ </ul>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head><title>index</title></head>
3
+ <body>
4
+ <h1>index</h1>
5
+ <ul id="main" class="runo-blog">
6
+ <li>$(name = text 32 1..32 :'foo'): $(comment = text 64 1..64 :'bar!')</li>
7
+ </ul>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head><title>summary</title></head>
3
+ <body>
4
+ <h1>summary</h1>
5
+ <table id="main" class="runo-blog">
6
+ <tr><td>$(name)</td><td>$(comment)</td></tr>
7
+ </table>
8
+ </body>
9
+ </html>
data/t/t.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Author:: Akira FUNAI
5
+ # Copyright:: Copyright (c) 2009 Akira FUNAI
6
+
7
+ require 'test/unit'
8
+ require 'rubygems'
9
+ require 'mocha'
10
+ require 'rack'
11
+
12
+ t_dir = ::File.dirname __FILE__
13
+
14
+ $LOAD_PATH.unshift t_dir
15
+ $LOAD_PATH.unshift(::File.expand_path('../lib', t_dir))
16
+ require 'runo'
17
+
18
+ Runo.config(
19
+ 'skin_dir' => './t/skin',
20
+ 'storage' => {
21
+ 'default' => 'File',
22
+ 'File' => {'data_dir' => './t/data'},
23
+ 'Sequel' => {'uri' => 'sqlite:/'},
24
+ }
25
+ )
26
+
27
+ Runo::I18n.bindtextdomain('index', ::File.join(t_dir, 'locale'))
@@ -0,0 +1,273 @@
1
+ # encoding: UTF-8
2
+
3
+ # Author:: Akira FUNAI
4
+ # Copyright:: Copyright (c) 2009 Akira FUNAI
5
+
6
+ require "#{::File.dirname __FILE__}/t"
7
+
8
+ class TC_Checkbox < Test::Unit::TestCase
9
+
10
+ def setup
11
+ meta = nil
12
+ Runo::Parser.gsub_scalar("$(foo checkbox bar, baz, qux :'baz' mandatory)") {|id, m|
13
+ meta = m
14
+ ''
15
+ }
16
+ @f = Runo::Field.instance meta
17
+ end
18
+
19
+ def teardown
20
+ end
21
+
22
+ def test_meta
23
+ assert_equal(
24
+ ['bar', 'baz', 'qux'],
25
+ @f[:options],
26
+ 'Checkbox#initialize should set :options from the csv token'
27
+ )
28
+ assert_equal(
29
+ true,
30
+ @f[:mandatory],
31
+ 'Checkbox#initialize should set :mandatory from the misc token'
32
+ )
33
+ assert_equal(
34
+ 'baz',
35
+ @f[:default],
36
+ 'Checkbox#initialize should set :default from the token'
37
+ )
38
+ end
39
+
40
+ def test_meta_single_option
41
+ meta = nil
42
+ Runo::Parser.gsub_scalar("$(foo checkbox baz :on mandatory)") {|id, m|
43
+ meta = m
44
+ ''
45
+ }
46
+ f = Runo::Field.instance meta
47
+
48
+ assert_equal(
49
+ ['baz'],
50
+ f[:options],
51
+ 'Checkbox#initialize should set :options from the misc token if csv is not provided'
52
+ )
53
+ assert_equal(
54
+ false,
55
+ f[:mandatory],
56
+ 'Checkbox#initialize should not set :mandatory if there is only one option'
57
+ )
58
+ assert_equal(
59
+ 'baz',
60
+ f[:default],
61
+ 'Checkbox#initialize should set :default to the first option if the token is provided'
62
+ )
63
+ end
64
+
65
+ def test_meta_no_options
66
+ meta = nil
67
+ Runo::Parser.gsub_scalar("$(foo checkbox :yes mandatory)") {|id, m|
68
+ meta = m
69
+ ''
70
+ }
71
+ f = Runo::Field.instance meta
72
+
73
+ assert_equal(
74
+ ['_on'],
75
+ f[:options],
76
+ 'Checkbox#initialize should set :options from the misc token if csv is not provided'
77
+ )
78
+ assert_equal(
79
+ false,
80
+ f[:mandatory],
81
+ 'Checkbox#initialize should not set :mandatory if there is only one option'
82
+ )
83
+ assert_equal(
84
+ '_on',
85
+ f[:default],
86
+ 'Checkbox#initialize should set :default to the first option if the token is provided'
87
+ )
88
+ end
89
+
90
+ def test_val_cast
91
+ assert_equal(
92
+ [],
93
+ @f.val,
94
+ 'Checkbox#val_cast should cast the given val to String'
95
+ )
96
+
97
+ @f.load 123
98
+ assert_equal(
99
+ ['123'],
100
+ @f.val,
101
+ 'Checkbox#val_cast should cast the given val to String'
102
+ )
103
+
104
+ @f.load ['', 123, 456]
105
+ assert_equal(
106
+ ['123', '456'],
107
+ @f.val,
108
+ 'Checkbox#val_cast should ignore empty vals'
109
+ )
110
+ end
111
+
112
+ def test_get
113
+ @f.load ''
114
+ assert_equal(
115
+ '',
116
+ @f.get,
117
+ 'Checkbox#get should return proper string'
118
+ )
119
+ assert_equal(
120
+ <<_html,
121
+ <span class="checkbox">
122
+ <input type="hidden" name="[]" value="" />
123
+ <span class="item">
124
+ <input type="checkbox" id="checkbox_-bar" name="[]" value="bar" />
125
+ <label for="checkbox_-bar">bar</label>
126
+ </span>
127
+ <span class="item">
128
+ <input type="checkbox" id="checkbox_-baz" name="[]" value="baz" />
129
+ <label for="checkbox_-baz">baz</label>
130
+ </span>
131
+ <span class="item">
132
+ <input type="checkbox" id="checkbox_-qux" name="[]" value="qux" />
133
+ <label for="checkbox_-qux">qux</label>
134
+ </span>
135
+ </span>
136
+ _html
137
+ @f.get(:action => :create),
138
+ 'Checkbox#get should return proper string'
139
+ )
140
+
141
+ @f.load ['baz', 'qux']
142
+ assert_equal(
143
+ 'baz, qux',
144
+ @f.get,
145
+ 'Checkbox#get should return proper string'
146
+ )
147
+ assert_equal(
148
+ <<_html,
149
+ <span class="checkbox">
150
+ <input type="hidden" name="[]" value="" />
151
+ <span class="item">
152
+ <input type="checkbox" id="checkbox_-bar" name="[]" value="bar" />
153
+ <label for="checkbox_-bar">bar</label>
154
+ </span>
155
+ <span class="item">
156
+ <input type="checkbox" id="checkbox_-baz" name="[]" value="baz" checked />
157
+ <label for="checkbox_-baz">baz</label>
158
+ </span>
159
+ <span class="item">
160
+ <input type="checkbox" id="checkbox_-qux" name="[]" value="qux" checked />
161
+ <label for="checkbox_-qux">qux</label>
162
+ </span>
163
+ </span>
164
+ _html
165
+ @f.get(:action => :update),
166
+ 'Checkbox#get should return proper string'
167
+ )
168
+
169
+ @f.load 'non-exist'
170
+ assert_equal(
171
+ <<_html,
172
+ <span class="checkbox error">
173
+ <input type="hidden" name="[]" value="" />
174
+ <span class="item">
175
+ <input type="checkbox" id="checkbox_-bar" name="[]" value="bar" />
176
+ <label for="checkbox_-bar">bar</label>
177
+ </span>
178
+ <span class="item">
179
+ <input type="checkbox" id="checkbox_-baz" name="[]" value="baz" />
180
+ <label for="checkbox_-baz">baz</label>
181
+ </span>
182
+ <span class="item">
183
+ <input type="checkbox" id="checkbox_-qux" name="[]" value="qux" />
184
+ <label for="checkbox_-qux">qux</label>
185
+ </span>
186
+ <span class=\"error_message\">no such option</span>
187
+ </span>
188
+ _html
189
+ @f.get(:action => :update),
190
+ 'Checkbox#get should return proper string'
191
+ )
192
+ end
193
+
194
+ def test_get_single_option
195
+ meta = nil
196
+ Runo::Parser.gsub_scalar("$(foo checkbox 'ok?' mandatory)") {|id, m|
197
+ meta = m
198
+ ''
199
+ }
200
+ f = Runo::Field.instance meta
201
+
202
+ f.load ''
203
+ assert_equal(
204
+ '',
205
+ f.get,
206
+ 'Checkbox#get should return proper string'
207
+ )
208
+ assert_equal(
209
+ <<_html,
210
+ <span class="checkbox">
211
+ <input type="hidden" name="[]" value="" />
212
+ <span class="item">
213
+ <input type="checkbox" id="checkbox_-ok?" name="[]" value="ok?" />
214
+ <label for="checkbox_-ok?">ok?</label>
215
+ </span>
216
+ </span>
217
+ _html
218
+ f.get(:action => :create),
219
+ 'Checkbox#get should not include the label if no options is defined'
220
+ )
221
+ end
222
+
223
+ def test_get_no_options
224
+ meta = nil
225
+ Runo::Parser.gsub_scalar("$(foo checkbox :yes mandatory)") {|id, m|
226
+ meta = m
227
+ ''
228
+ }
229
+ f = Runo::Field.instance meta
230
+
231
+ f.load ''
232
+ assert_equal(
233
+ '',
234
+ f.get,
235
+ 'Checkbox#get should return proper string'
236
+ )
237
+ assert_equal(
238
+ <<_html,
239
+ <span class="checkbox">
240
+ <input type="hidden" name="[]" value="" />
241
+ <input type="checkbox" name="[]" value="_on" />
242
+ </span>
243
+ _html
244
+ f.get(:action => :create),
245
+ 'Checkbox#get should not include the label if no options is defined'
246
+ )
247
+ end
248
+
249
+ def test_errors
250
+ @f.load ''
251
+ @f[:mandatory] = nil
252
+ assert_equal(
253
+ [],
254
+ @f.errors,
255
+ 'Checkbox#errors should return the errors of the current val'
256
+ )
257
+ @f[:mandatory] = true
258
+ assert_equal(
259
+ ['mandatory'],
260
+ @f.errors,
261
+ 'Checkbox#errors should return the errors of the current val'
262
+ )
263
+
264
+ @f.load 'non-exist'
265
+ @f[:mandatory] = nil
266
+ assert_equal(
267
+ ['no such option'],
268
+ @f.errors,
269
+ 'Checkbox#errors should return the errors of the current val'
270
+ )
271
+ end
272
+
273
+ end
@@ -0,0 +1,330 @@
1
+ # encoding: UTF-8
2
+
3
+ # Author:: Akira FUNAI
4
+ # Copyright:: Copyright (c) 2009 Akira FUNAI
5
+
6
+ require "#{::File.dirname __FILE__}/t"
7
+
8
+ class Runo::Foo < Runo::Field
9
+ DEFAULT_META = {:foo => 'foo foo'}
10
+ class Bar < Runo::Field
11
+ def _g_test(arg)
12
+ 'just a test.'
13
+ end
14
+ end
15
+ end
16
+
17
+ class TC_Field < Test::Unit::TestCase
18
+
19
+ def setup
20
+ @f = Runo::Field.instance(
21
+ :klass => 'foo-bar',
22
+ :baz => 1234,
23
+ :default => 'bar bar'
24
+ )
25
+ end
26
+
27
+ def teardown
28
+ end
29
+
30
+ def test_instance
31
+ assert_instance_of(
32
+ Runo::Foo::Bar,
33
+ @f,
34
+ 'Field#instance should return an instance of the class specified by :klass'
35
+ )
36
+ end
37
+
38
+ def test_wrong_instance
39
+ assert_nil(
40
+ Runo::Field.instance(:klass => 'set'),
41
+ 'Field#instance should not return an instance of other than Field'
42
+ )
43
+ assert_nil(
44
+ Runo::Field.instance(:klass => 'storage'),
45
+ 'Field#instance should not return an instance of other than Field'
46
+ )
47
+ end
48
+
49
+ def test_meta
50
+ assert_equal(
51
+ {:klass => 'foo-bar', :baz => 1234, :default => 'bar bar'},
52
+ @f.instance_variable_get(:@meta),
53
+ 'Field#instance should load @meta of the instance'
54
+ )
55
+ assert_nothing_raised('Field#[]= should set the item in @meta') {
56
+ @f[:baz] = 'new value'
57
+ }
58
+ assert_equal(
59
+ 'new value',
60
+ @f[:baz],
61
+ 'Field#[] should get the item in @meta'
62
+ )
63
+ end
64
+
65
+ def test_meta_name
66
+ item = Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')
67
+ assert_equal(
68
+ 'main',
69
+ item[:name],
70
+ 'Field#[:name] should return the path name from the nearest folder'
71
+ )
72
+ item = Runo::Set::Static::Folder.root.item('foo', 'bar')
73
+ assert_equal(
74
+ 'bar',
75
+ item[:name],
76
+ 'Field#[:name] should return the path name from the nearest folder'
77
+ )
78
+ end
79
+
80
+ def test_meta_full_name
81
+ item = Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')
82
+ assert_equal(
83
+ '-foo-bar-main',
84
+ item[:full_name],
85
+ 'Field#[:full_name] should return the path name from the root folder'
86
+ )
87
+ item = Runo::Set::Static::Folder.root.item('foo', 'bar')
88
+ assert_equal(
89
+ '-foo-bar',
90
+ item[:full_name],
91
+ 'Field#[:full_name] should return the path name from the root folder'
92
+ )
93
+ end
94
+
95
+ def test_meta_short_name
96
+ item = Runo::Set::Static::Folder.root.item(
97
+ 'foo', 'bar', 'main', '20091120_0001', 'replies', '20091208_0001', 'reply'
98
+ )
99
+
100
+ Runo.current[:base] = nil
101
+ assert_equal(
102
+ 'reply',
103
+ item[:short_name],
104
+ 'Field#[:short_name] should return [:id] if no base SD is defined'
105
+ )
106
+
107
+ Runo.current[:base] = Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')
108
+ assert_equal(
109
+ '20091120_0001-replies-20091208_0001-reply',
110
+ item[:short_name],
111
+ 'Field#[:short_name] should return the path name from the base SD'
112
+ )
113
+
114
+ Runo.current[:base] = Runo::Set::Static::Folder.root.item(
115
+ 'foo', 'bar', 'main', '20091120_0001', 'replies'
116
+ )
117
+ assert_equal(
118
+ '20091208_0001-reply',
119
+ item[:short_name],
120
+ 'Field#[:short_name] should return the path name from the base SD'
121
+ )
122
+
123
+ Runo.current[:base] = Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')
124
+ assert_equal(
125
+ '',
126
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')[:short_name],
127
+ 'Field#[:short_name] should return empty string for the base SD itself'
128
+ )
129
+ end
130
+
131
+ def test_meta_sd
132
+ sd = Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')
133
+ assert_equal(
134
+ sd,
135
+ sd[:sd],
136
+ 'Field#[:sd] should return the nearest set_dynamic'
137
+ )
138
+ assert_equal(
139
+ sd,
140
+ sd.item('20091120_0001')[:sd],
141
+ 'Field#[:sd] should return the nearest set_dynamic'
142
+ )
143
+ assert_equal(
144
+ sd,
145
+ sd.item('20091120_0001', 'name')[:sd],
146
+ 'Field#[:sd] should return the nearest set_dynamic'
147
+ )
148
+ assert_nil(
149
+ Runo::Set::Static::Folder.root[:sd],
150
+ 'Field#[:sd] should return nil if there is no set_dynamic in the ancestors'
151
+ )
152
+ end
153
+
154
+ def test_meta_client
155
+ Runo.client = 'frank'
156
+ assert_equal(
157
+ 'frank',
158
+ Runo::Field.new[:client],
159
+ 'Field#[:client] should return the client of the current thread'
160
+ )
161
+ end
162
+
163
+ def test_empty?
164
+ @f.load 'foo'
165
+ assert(
166
+ !@f.empty?,
167
+ 'Field#empty? should return false if the field has a value'
168
+ )
169
+
170
+ @f.load nil
171
+ assert(
172
+ @f.empty?,
173
+ 'Field#empty? should return true if the field has no value'
174
+ )
175
+ end
176
+
177
+ def test_default_meta
178
+ f = Runo::Field.instance(:klass => 'foo')
179
+ assert_equal(
180
+ 'foo foo',
181
+ f[:foo],
182
+ 'Field#[] should look for the default value in DEFAULT_META'
183
+ )
184
+
185
+ f = Runo::Field.instance(:klass => 'foo', :foo => 'bar')
186
+ assert_equal(
187
+ 'bar',
188
+ f[:foo],
189
+ 'Field.DEFAULT_META should be eclipsed by @meta'
190
+ )
191
+
192
+ f = Runo::Field.instance(:klass => 'foo')
193
+ def f.meta_foo
194
+ 'abc'
195
+ end
196
+ assert_equal(
197
+ 'abc',
198
+ f[:foo],
199
+ 'Field.DEFAULT_META should be eclipsed by meta_*()'
200
+ )
201
+ end
202
+
203
+ def test_get
204
+ @f.instance_variable_set(:@val, 'hello')
205
+ assert_equal(
206
+ 'hello',
207
+ @f.get,
208
+ 'Field#get should return @val by default'
209
+ )
210
+
211
+ assert_equal(
212
+ 'just a test.',
213
+ @f.get(:action => :test),
214
+ 'Field#get should relay the result of _g_*()'
215
+ )
216
+
217
+ @f[:tmpl] = {:foo => 'foo foo'}
218
+ assert_equal(
219
+ 'hello',
220
+ @f.get(:action => :foo),
221
+ 'Field#get should not use [:tmpl][*]'
222
+ )
223
+ end
224
+
225
+ def test_post
226
+ @f.post(:create, 999)
227
+ assert_equal(
228
+ 999,
229
+ @f.val,
230
+ 'Field#post should set @val'
231
+ )
232
+ assert_equal(
233
+ :create,
234
+ @f.action,
235
+ 'Field#post should set @action'
236
+ )
237
+
238
+ @f.commit
239
+ assert_equal(
240
+ :create,
241
+ @f.result,
242
+ 'Field#commit should set @result'
243
+ )
244
+
245
+ @f.post(:update, 111)
246
+ assert_nil(
247
+ @f.result,
248
+ 'Field#post should reset @result'
249
+ )
250
+ assert_equal(
251
+ 111,
252
+ @f.val,
253
+ 'Field#post should set @val'
254
+ )
255
+ assert_equal(
256
+ :update,
257
+ @f.action,
258
+ 'Field#post should set @action'
259
+ )
260
+ end
261
+
262
+ def test_load_default
263
+ @f.load_default
264
+ assert_equal(
265
+ 'bar bar',
266
+ @f.val,
267
+ 'Field#load_default should set @val to [:default]'
268
+ )
269
+ assert_nil(
270
+ @f.action,
271
+ 'Field#load_default should not set @action'
272
+ )
273
+ end
274
+
275
+ def test_load
276
+ @f.load 'baz baz'
277
+ assert_equal(
278
+ 'baz baz',
279
+ @f.val,
280
+ 'Field#load should set @val'
281
+ )
282
+ assert_nil(
283
+ @f.action,
284
+ 'Field#load should not set @action'
285
+ )
286
+ end
287
+
288
+ def test_create
289
+ @f.create 'baz baz'
290
+ assert_equal(
291
+ 'baz baz',
292
+ @f.val,
293
+ 'Field#create should set @val'
294
+ )
295
+ assert_equal(
296
+ :create,
297
+ @f.action,
298
+ 'Field#create should set @action'
299
+ )
300
+ end
301
+
302
+ def test_update
303
+ @f.update 'baz baz'
304
+ assert_equal(
305
+ 'baz baz',
306
+ @f.val,
307
+ 'Field#update should set @val'
308
+ )
309
+ assert_equal(
310
+ :update,
311
+ @f.action,
312
+ 'Field#update should set @action'
313
+ )
314
+ end
315
+
316
+ def test_delete
317
+ @f.delete
318
+ assert_equal(
319
+ nil,
320
+ @f.val,
321
+ 'Field#delete should not set @val'
322
+ )
323
+ assert_equal(
324
+ :delete,
325
+ @f.action,
326
+ 'Field#delete should set @action'
327
+ )
328
+ end
329
+
330
+ end