runo 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/README.rdoc +1 -118
  2. data/bin/runo +4 -29
  3. data/lib/dummy.rb +0 -0
  4. metadata +12 -278
  5. data/lib/_error.rb +0 -14
  6. data/lib/_field.rb +0 -260
  7. data/lib/_i18n.rb +0 -144
  8. data/lib/_parser.rb +0 -256
  9. data/lib/_path.rb +0 -86
  10. data/lib/_storage/_storage.rb +0 -215
  11. data/lib/_storage/file.rb +0 -201
  12. data/lib/_storage/sequel.rb +0 -174
  13. data/lib/_storage/temp.rb +0 -73
  14. data/lib/_widget/action_create.rb +0 -23
  15. data/lib/_widget/action_login.rb +0 -22
  16. data/lib/_widget/action_signup.rb +0 -16
  17. data/lib/_widget/action_update.rb +0 -16
  18. data/lib/_widget/crumb.rb +0 -24
  19. data/lib/_widget/done.rb +0 -16
  20. data/lib/_widget/login.rb +0 -25
  21. data/lib/_widget/me.rb +0 -31
  22. data/lib/_widget/message.rb +0 -51
  23. data/lib/_widget/navi.rb +0 -88
  24. data/lib/_widget/submit.rb +0 -49
  25. data/lib/_widget/view_ym.rb +0 -77
  26. data/lib/_workflow/_workflow.rb +0 -89
  27. data/lib/_workflow/attachment.rb +0 -50
  28. data/lib/_workflow/blog.rb +0 -28
  29. data/lib/_workflow/contact.rb +0 -23
  30. data/lib/_workflow/forum.rb +0 -26
  31. data/lib/_workflow/register.rb +0 -39
  32. data/lib/meta/_meta.rb +0 -20
  33. data/lib/meta/group.rb +0 -19
  34. data/lib/meta/id.rb +0 -59
  35. data/lib/meta/owner.rb +0 -21
  36. data/lib/meta/timestamp.rb +0 -118
  37. data/lib/runo.rb +0 -396
  38. data/lib/scalar/checkbox.rb +0 -68
  39. data/lib/scalar/file.rb +0 -144
  40. data/lib/scalar/img.rb +0 -112
  41. data/lib/scalar/password.rb +0 -58
  42. data/lib/scalar/radio.rb +0 -47
  43. data/lib/scalar/select.rb +0 -47
  44. data/lib/scalar/text.rb +0 -38
  45. data/lib/scalar/textarea.rb +0 -35
  46. data/lib/scalar/textarea_pre.rb +0 -14
  47. data/lib/scalar/textarea_wiki.rb +0 -173
  48. data/lib/set/_set.rb +0 -196
  49. data/lib/set/dynamic.rb +0 -177
  50. data/lib/set/static.rb +0 -102
  51. data/lib/set/static_folder.rb +0 -96
  52. data/locale/en/index.po +0 -242
  53. data/locale/index.pot +0 -243
  54. data/locale/ja/index.po +0 -242
  55. data/locale/lazy_parser.rb +0 -54
  56. data/skel/config.ru +0 -27
  57. data/skel/skin/_users/00000000_frank-avatar.jpg +0 -0
  58. data/skel/skin/_users/00000000_frank-avatar_small.jpg +0 -0
  59. data/skel/skin/_users/00000000_frank.yaml +0 -12
  60. data/skel/skin/_users/00000000_root-avatar.jpg +0 -0
  61. data/skel/skin/_users/00000000_root-avatar_small.jpg +0 -0
  62. data/skel/skin/_users/00000000_root.yaml +0 -11
  63. data/skel/skin/_users/css/users.css +0 -21
  64. data/skel/skin/_users/css/users.less +0 -25
  65. data/skel/skin/_users/done.html +0 -42
  66. data/skel/skin/_users/index.html +0 -46
  67. data/skel/skin/_users/index.yaml +0 -3
  68. data/skel/skin/_users/summary.html +0 -40
  69. data/skel/skin/css/base.css +0 -93
  70. data/skel/skin/css/base.less +0 -139
  71. data/skel/skin/css/coax.css +0 -199
  72. data/skel/skin/css/coax.less +0 -244
  73. data/skel/skin/examples/blog/20091214_0001.yaml +0 -8
  74. data/skel/skin/examples/blog/20100630_0001.yaml +0 -8
  75. data/skel/skin/examples/blog/20100630_0002.yaml +0 -14
  76. data/skel/skin/examples/blog/20100701_0001.yaml +0 -8
  77. data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f.jpg +0 -0
  78. data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f_small.jpg +0 -0
  79. data/skel/skin/examples/blog/20100701_0002.yaml +0 -19
  80. data/skel/skin/examples/blog/frank/20100701_0001.yaml +0 -10
  81. data/skel/skin/examples/blog/frank/index.yaml +0 -4
  82. data/skel/skin/examples/blog/index.html +0 -51
  83. data/skel/skin/examples/blog/rss.xml +0 -18
  84. data/skel/skin/examples/contact/20100701_0001-file.txt +0 -1
  85. data/skel/skin/examples/contact/20100701_0001.yaml +0 -15
  86. data/skel/skin/examples/contact/20100701_0002.yaml +0 -8
  87. data/skel/skin/examples/contact/20100701_0003.yaml +0 -9
  88. data/skel/skin/examples/contact/index.html +0 -47
  89. data/skel/skin/examples/contact/js/contact.js +0 -13
  90. data/skel/skin/examples/contact/summary.html +0 -54
  91. data/skel/skin/examples/forum/20100701_0001.yaml +0 -41
  92. data/skel/skin/examples/forum/20100701_0002.yaml +0 -25
  93. data/skel/skin/examples/forum/index.html +0 -68
  94. data/skel/skin/examples/forum/summary.html +0 -47
  95. data/skel/skin/examples/index.html +0 -73
  96. data/skel/skin/index.html +0 -39
  97. data/skel/skin/js/base.js +0 -50
  98. data/t/locale/de/index.po +0 -19
  99. data/t/locale/en-GB/index.po +0 -25
  100. data/t/locale/ja/index.po +0 -30
  101. data/t/skin/_users/00000000_test.yaml +0 -3
  102. data/t/skin/_users/index.html +0 -13
  103. data/t/skin/foo/20091120_0001.yaml +0 -7
  104. data/t/skin/foo/bar/20091120_0001.yaml +0 -5
  105. data/t/skin/foo/bar/index.yaml +0 -5
  106. data/t/skin/foo/baz/css/baz.css +0 -1
  107. data/t/skin/foo/css/foo.css +0 -1
  108. data/t/skin/foo/index.html +0 -14
  109. data/t/skin/foo/index.yaml +0 -7
  110. data/t/skin/foo/not_css/foo.css +0 -1
  111. data/t/skin/foo/qux/index.html +0 -8
  112. data/t/skin/foo/qux/moo/index.html +0 -6
  113. data/t/skin/foo/sub-20100306_0001.yaml +0 -3
  114. data/t/skin/index.yaml +0 -3
  115. data/t/skin/t_attachment/index.html +0 -13
  116. data/t/skin/t_contact/done.html +0 -6
  117. data/t/skin/t_contact/index.html +0 -9
  118. data/t/skin/t_file/index.html +0 -16
  119. data/t/skin/t_img/index.html +0 -14
  120. data/t/skin/t_img/test.jpg +0 -0
  121. data/t/skin/t_select/index.html +0 -9
  122. data/t/skin/t_store/index.html +0 -9
  123. data/t/skin/t_summary/20100326_0001.yaml +0 -3
  124. data/t/skin/t_summary/create.html +0 -9
  125. data/t/skin/t_summary/index.html +0 -9
  126. data/t/skin/t_summary/summary.html +0 -9
  127. data/t/t.rb +0 -27
  128. data/t/test_checkbox.rb +0 -273
  129. data/t/test_field.rb +0 -330
  130. data/t/test_file.rb +0 -900
  131. data/t/test_id.rb +0 -215
  132. data/t/test_img.rb +0 -328
  133. data/t/test_meta.rb +0 -57
  134. data/t/test_parser.rb +0 -1516
  135. data/t/test_password.rb +0 -188
  136. data/t/test_radio.rb +0 -226
  137. data/t/test_role.rb +0 -249
  138. data/t/test_runo.rb +0 -768
  139. data/t/test_runo_call.rb +0 -1281
  140. data/t/test_runo_i18n.rb +0 -325
  141. data/t/test_select.rb +0 -182
  142. data/t/test_set_complex.rb +0 -527
  143. data/t/test_set_dynamic.rb +0 -1504
  144. data/t/test_set_folder.rb +0 -515
  145. data/t/test_set_permit.rb +0 -246
  146. data/t/test_set_static.rb +0 -468
  147. data/t/test_storage.rb +0 -915
  148. data/t/test_text.rb +0 -125
  149. data/t/test_textarea.rb +0 -138
  150. data/t/test_timestamp.rb +0 -473
  151. data/t/test_workflow.rb +0 -367
@@ -1,768 +0,0 @@
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_Runo < Test::Unit::TestCase
9
-
10
- def setup
11
- end
12
-
13
- def teardown
14
- end
15
-
16
- def test_session
17
- assert(
18
- Runo.session.respond_to?(:[]),
19
- 'Runo.session should be a Session or Hash'
20
- )
21
- end
22
-
23
- def test_client
24
- Runo.client = nil
25
- assert_equal(
26
- 'nobody',
27
- Runo.client,
28
- 'Runo.client should return nobody before login'
29
- )
30
-
31
- Runo.client = 'frank'
32
- assert_equal(
33
- 'frank',
34
- Runo.client,
35
- 'Runo.client should return the user who logged in'
36
- )
37
-
38
- Runo.client = nil
39
- assert_equal(
40
- 'nobody',
41
- Runo.client,
42
- 'Runo.client should return nobody after logout'
43
- )
44
- end
45
-
46
- def test_rebuild_params
47
- runo = Runo.new
48
-
49
- hash = runo.instance_eval {
50
- rebuild_params(
51
- '.action' => 'update'
52
- )
53
- }
54
- assert_equal(
55
- {:action => :update},
56
- hash,
57
- 'Runo#rebuild_params should be able to rebuild special symbols'
58
- )
59
-
60
- hash = runo.instance_eval {
61
- rebuild_params(
62
- '.action-update' => 'submit'
63
- )
64
- }
65
- assert_equal(
66
- {:action => :update},
67
- hash,
68
- 'Runo#rebuild_params should be able to rebuild special symbols'
69
- )
70
-
71
- hash = runo.instance_eval {
72
- rebuild_params(
73
- 'noo' => 'what?',
74
- 'noo.action-update' => 'submit',
75
- 'noo.conds-id' => '4567'
76
- )
77
- }
78
- assert_equal(
79
- {
80
- 'noo' => {
81
- :self => 'what?',
82
- :action => :update,
83
- :conds => {:id => '4567'},
84
- },
85
- },
86
- hash,
87
- 'Runo#rebuild_params should rebuild both the special symbols and regular items'
88
- )
89
-
90
- hash = runo.instance_eval {
91
- rebuild_params(
92
- 'moo.conds-p' => '9',
93
- 'moo-4567-addr.conds-zip-upper' => '110'
94
- )
95
- }
96
- assert_equal(
97
- {
98
- 'moo' => {
99
- :conds => {:p => '9'},
100
- '4567' => {
101
- 'addr' => {
102
- :conds => {:'zip-upper' => '110'},
103
- },
104
- },
105
- },
106
- },
107
- hash,
108
- 'Runo#rebuild_params should be able to rebuild any combination of symbols and items'
109
- )
110
-
111
- hash = runo.instance_eval {
112
- rebuild_params(
113
- 'foo-bar.conds-id' => '1234',
114
- 'foo-bar.conds-p' => ['42'],
115
- 'foo-bar.action' => 'update',
116
- 'foo-baz' => ['boo', 'bee'],
117
- 'foo' => 'oops',
118
- 'qux.action-create' => 'submit',
119
- 'qux.status-public' => 'oops'
120
- )
121
- }
122
- assert_equal(
123
- {
124
- 'foo' => {
125
- :self => 'oops',
126
- 'bar' => {
127
- :action => :update,
128
- :conds => {
129
- :id => '1234',
130
- :p => ['42'],
131
- },
132
- },
133
- 'baz' => ['boo', 'bee'],
134
- },
135
- 'qux' => {
136
- :action => :create,
137
- :status => :public,
138
- },
139
- },
140
- hash,
141
- 'Runo#rebuild_params should be able to rebuild any combination of symbols and items'
142
- )
143
- end
144
-
145
- def test_steps_of
146
- assert_equal(
147
- ['foo', 'bar'],
148
- Runo::Path.steps_of('/foo/bar/'),
149
- 'Runo::Path.steps_of should be able to extract item steps from path_info'
150
- )
151
- assert_equal(
152
- ['foo', 'bar'],
153
- Runo::Path.steps_of('/foo/bar/create.html'),
154
- 'Runo::Path.steps_of should ignore the pseudo-filename'
155
- )
156
- assert_equal(
157
- ['foo'],
158
- Runo::Path.steps_of('/foo/bar'),
159
- 'Runo::Path.steps_of should ignore the last step without a following slash'
160
- )
161
- assert_equal(
162
- ['foo', 'bar'],
163
- Runo::Path.steps_of('/foo//bar/baz=123/'),
164
- 'Runo::Path.steps_of should distinguish item steps from conds'
165
- )
166
- assert_equal(
167
- ['foo', 'bar'],
168
- Runo::Path.steps_of('/1234567890.123456/foo/bar/'),
169
- 'Runo::Path.steps_of should distinguish item steps from a tid'
170
- )
171
- end
172
-
173
- def test_steps_of_with_empty_steps
174
- assert_equal(
175
- [],
176
- Runo::Path.steps_of(''),
177
- 'Runo::Path.steps_of should return empty array when there is no item steps'
178
- )
179
- assert_equal(
180
- [],
181
- Runo::Path.steps_of('/'),
182
- 'Runo::Path.steps_of should return empty array when there is no item steps'
183
- )
184
- assert_equal(
185
- [],
186
- Runo::Path.steps_of('/index.html'),
187
- 'Runo::Path.steps_of should return empty array when there is no item steps'
188
- )
189
- end
190
-
191
- def test_steps_of_with_cond_d
192
- assert_equal(
193
- ['foo', 'bar'],
194
- Runo::Path.steps_of('/foo/bar/2009/'),
195
- 'Runo::Path.steps_of should distinguish item steps from ambiguous conds[:d]'
196
- )
197
- assert_equal(
198
- ['foo', 'bar'],
199
- Runo::Path.steps_of('/foo/bar/1970/'),
200
- 'Runo::Path.steps_of should distinguish item steps from ambiguous conds[:d]'
201
- )
202
- assert_equal(
203
- ['foo', 'bar', '3001'],
204
- Runo::Path.steps_of('/foo/bar/3001/'),
205
- 'Runo::Path.steps_of should be patched in the next millennium :-)'
206
- )
207
- end
208
-
209
- def test_conds_of
210
- assert_equal(
211
- {},
212
- Runo::Path.conds_of('/foo/bar/'),
213
- 'Runo::Path.conds_of should return empty hash when there is no conds'
214
- )
215
- assert_equal(
216
- {
217
- :baz => '123',
218
- :qux => '456',
219
- },
220
- Runo::Path.conds_of('/foo/bar/baz=123/qux=456/'),
221
- 'Runo::Path.conds_of should be able to extract conds from path_info'
222
- )
223
- assert_equal(
224
- {
225
- :baz => '123',
226
- :qux => '456',
227
- },
228
- Runo::Path.conds_of('/foo/bar/baz=123/qux=456/create.html'),
229
- 'Runo::Path.conds_of should ignore the pseudo-filename'
230
- )
231
- assert_equal(
232
- {
233
- :baz => '1234',
234
- },
235
- Runo::Path.conds_of('/foo/bar//baz=1234//qux=4567'),
236
- 'Runo::Path.conds_of should ignore the item steps and the last step without a slash'
237
- )
238
- end
239
-
240
- def test_conds_of_with_empty_conds
241
- assert_equal(
242
- {},
243
- Runo::Path.conds_of(''),
244
- 'Runo::Path.conds_of should return empty hash when there is no conds'
245
- )
246
- assert_equal(
247
- {},
248
- Runo::Path.conds_of('/'),
249
- 'Runo::Path.conds_of should return empty hash when there is no conds'
250
- )
251
- assert_equal(
252
- {},
253
- Runo::Path.conds_of('/index.html'),
254
- 'Runo::Path.conds_of should return empty hash when there is no conds'
255
- )
256
- end
257
-
258
- def test_conds_of_with_cond_d
259
- assert_equal(
260
- {
261
- :d => '200911',
262
- :baz => '1234',
263
- :qux => '4567',
264
- },
265
- Runo::Path.conds_of('/foo/bar/200911/baz=1234/qux=4567/'),
266
- 'Runo::Path.conds_of should be able to distinguish ambiguous conds[:d]'
267
- )
268
- assert_equal(
269
- {
270
- :baz => '1234',
271
- :qux => '4567',
272
- },
273
- Runo::Path.conds_of('/foo/bar/20091129_0001/baz=1234/qux=4567/'),
274
- 'Runo::Path.conds_of should ignore the full-formatted id'
275
- )
276
- end
277
-
278
- def test_conds_of_with_cond_id
279
- assert_equal(
280
- ['foo', 'bar'],
281
- Runo::Path.steps_of('/foo/bar/20091205/9/baz=1234/qux=4567/'),
282
- 'Runo::Path.steps_of should ignore conds[:id]'
283
- )
284
- assert_equal(
285
- {
286
- :id => '20091205_0009',
287
- :baz => '1234',
288
- :qux => '4567',
289
- },
290
- Runo::Path.conds_of('/foo/bar/20091205/9/baz=1234/qux=4567/'),
291
- 'Runo::Path.conds_of should extract conds[:id] from the path sequence'
292
- )
293
- end
294
-
295
- def test_action_of
296
- assert_equal(
297
- :create,
298
- Runo::Path.action_of('/foo/bar/create.html'),
299
- 'Runo::Path.action_of should extract the action from path_info'
300
- )
301
-
302
- assert_nil(
303
- Runo::Path.action_of('/foo/bar/index.html'),
304
- 'Runo::Path.action_of should return nil if the pseudo-filename is index.*'
305
- )
306
- assert_nil(
307
- Runo::Path.action_of('/foo/bar/'),
308
- 'Runo::Path.action_of should return nil if no pseudo-filename is given'
309
- )
310
- assert_nil(
311
- Runo::Path.action_of('/foo/bar/_detail.html'),
312
- "Runo::Path.action_of should return nil if the pseudo-filename begins with '_'"
313
- )
314
- end
315
-
316
- def test_sub_action_of
317
- assert_equal(
318
- :detail,
319
- Runo::Path.sub_action_of('/foo/bar/read_detail.html'),
320
- 'Runo::Path.sub_action_of should extract the sub_action from path_info'
321
- )
322
- assert_nil(
323
- Runo::Path.sub_action_of('/foo/bar/read.html'),
324
- "Runo::Path.sub_action_of should return nil if the pseudo-filename does not include '_'"
325
- )
326
- end
327
-
328
- def test_base_of
329
- sd = Runo::Path.base_of '/foo/bar/main/index.html'
330
- assert_instance_of(
331
- Runo::Set::Dynamic,
332
- sd,
333
- 'Runo::Path.base_of should return a set_dynamic'
334
- )
335
- assert_equal(
336
- '-foo-bar-main',
337
- sd[:full_name],
338
- 'Runo::Path.base_of should return a set_dynamic at the bottom of the given steps'
339
- )
340
-
341
- sd = Runo::Path.base_of '/foo/bar/index.html'
342
- assert_instance_of(
343
- Runo::Set::Dynamic,
344
- sd,
345
- 'Runo::Path.base_of should return a set_dynamic'
346
- )
347
- assert_equal(
348
- '-foo-bar-main',
349
- sd[:full_name],
350
- "Runo::Path.base_of should return the item('main') if the given steps point at a folder"
351
- )
352
-
353
- sd = Runo::Path.base_of '/foo/qux/index.html'
354
- assert_instance_of(
355
- Runo::Set::Dynamic,
356
- sd,
357
- "Runo::Path.base_of should return an available set_dynamic if there is no 'main' in the folder"
358
- )
359
- assert_equal(
360
- '-foo-qux-abc',
361
- sd[:full_name],
362
- "Runo::Path.base_of should return the first set_dynamic if there is no 'main' in the folder"
363
- )
364
-
365
- sd = Runo::Path.base_of '/foo/bar/20091120_0001/comment/index.html'
366
- assert_instance_of(
367
- Runo::Text,
368
- sd,
369
- 'Runo::Path.base_of should return a text if designated'
370
- )
371
-
372
- sd = Runo::Path.base_of '/foo/bar/20091120_0001/files/index.html'
373
- assert_instance_of(
374
- Runo::Set::Dynamic,
375
- sd,
376
- 'Runo::Path.base_of should return a set_dynamic'
377
- )
378
- assert_equal(
379
- '-foo-bar-main-20091120_0001-files',
380
- sd[:full_name],
381
- "Runo::Path.base_of should be able to dive into any depth from the folder"
382
- )
383
-
384
- sd = Runo::Path.base_of '/foo/bar/20091120_0002/files/index.html'
385
- assert_nil(
386
- sd,
387
- 'Runo::Path.base_of should return nil if there is no set_dynamic at the steps'
388
- )
389
- end
390
-
391
- def test_base_of_empty_folder
392
- f = Runo::Path.base_of '/foo/qux/moo/index.html'
393
- assert_instance_of(
394
- Runo::Set::Static::Folder,
395
- f,
396
- 'Runo::Path.base_of should return an folder if there is no SD in it'
397
- )
398
- assert_equal(
399
- '-foo-qux-moo',
400
- f[:full_name],
401
- 'Runo::Path.base_of should return an folder if there is no SD in it'
402
- )
403
- end
404
-
405
- def test_path_of
406
- assert_equal(
407
- '20091224/123/',
408
- Runo::Path.path_of(:id => '20091224_0123'),
409
- 'Runo::Path.path_of should return a special combination of pseudo-steps for conds[:id]'
410
- )
411
- assert_equal(
412
- '20091224/123/',
413
- Runo::Path.path_of(:d => '2009', :id => '20091224_0123'),
414
- 'Runo::Path.path_of should ignore the other conds if there is conds[:id]'
415
- )
416
-
417
- assert_equal(
418
- '20091224/123/',
419
- Runo::Path.path_of(:id => ['20091224_0123']),
420
- 'Runo::Path.path_of should return a special combination of pseudo-steps for conds[:id]'
421
- )
422
- assert_equal(
423
- 'id=20091224_0123,20100222_1234/',
424
- Runo::Path.path_of(:id => ['20091224_0123', '20100222_1234']),
425
- 'Runo::Path.path_of should return multiple ids as a comma-separated form'
426
- )
427
- assert_equal(
428
- '',
429
- Runo::Path.path_of(:id => []),
430
- 'Runo::Path.path_of should return an empty string when given an empty conds[:id]'
431
- )
432
-
433
- assert_equal(
434
- 'id=carl/',
435
- Runo::Path.path_of(:id => '00000000_carl'),
436
- "Runo::Path.path_of should use '/id=xxx/' form for a short id"
437
- )
438
- assert_equal(
439
- 'id=20091224_0123,carl/',
440
- Runo::Path.path_of(:id => ['20091224_0123', '00000000_carl']),
441
- "Runo::Path.path_of should use short ids in a comma-separated form"
442
- )
443
-
444
- assert_equal(
445
- 'foo=bar/',
446
- Runo::Path.path_of(:foo => 'bar'),
447
- 'Runo::Path.path_of should return a path of which steps represent the conds'
448
- )
449
- assert_equal(
450
- 'foo=bar/p=123/',
451
- Runo::Path.path_of(:p => 123, :foo => 'bar'),
452
- 'Runo::Path.path_of should return the step for conds[:p] at the tail end'
453
- )
454
- assert_equal(
455
- 'foo=bar/order=desc/p=123/',
456
- Runo::Path.path_of(:p => 123, :order =>'desc', :foo => 'bar'),
457
- 'Runo::Path.path_of should return the step for conds[:order] at the tail end'
458
- )
459
-
460
- assert_equal(
461
- 'foo=bar/',
462
- Runo::Path.path_of(:p => 1, :foo => 'bar'),
463
- 'Runo::Path.path_of should omit the step for conds[:p] when conds[:p] == 1'
464
- )
465
- assert_equal(
466
- 'p=1/',
467
- Runo::Path.path_of(:p => 1),
468
- 'Runo::Path.path_of should not omit the step for conds[:p] when there is no other conds'
469
- )
470
-
471
- assert_equal(
472
- 'foo=1,2,3/',
473
- Runo::Path.path_of(:foo => [1, 2, 3]),
474
- 'Runo::Path.path_of should return multiple values as a comma-separated form'
475
- )
476
- end
477
-
478
- def test_params_from_request
479
- runo = Runo.new
480
-
481
- env = Rack::MockRequest.env_for(
482
- 'http://example.com/foo/bar/main/qux=456/read_detail.html?acorn=round',
483
- {
484
- :method => 'post',
485
- :script_name => '',
486
- :input => 'coax=true&some-doors=open',
487
- }
488
- )
489
- req = Rack::Request.new env
490
- params = runo.instance_eval {
491
- params_from_request req
492
- }
493
- assert_equal(
494
- {
495
- :conds => {:qux => '456'},
496
- :action => :read,
497
- :sub_action => :detail,
498
- 'acorn' => 'round',
499
- 'coax' => 'true',
500
- 'some' => {'doors' => 'open'},
501
- },
502
- params,
503
- 'Runo#params_from_request should build params from req.path_info and req.params'
504
- )
505
-
506
- env = Rack::MockRequest.env_for(
507
- 'http://example.com/foo/bar/qux=456/index.html?acorn=round',
508
- {
509
- :method => 'post',
510
- :script_name => '',
511
- :input => 'coax=true&some-doors=open',
512
- }
513
- )
514
- req = Rack::Request.new env
515
- params = runo.instance_eval {
516
- params_from_request req
517
- }
518
- assert_equal(
519
- {
520
- :conds => {:qux => '456'},
521
- :action => nil,
522
- :sub_action => nil,
523
- 'acorn' => 'round',
524
- 'coax' => 'true',
525
- 'some' => {'doors' => 'open'},
526
- },
527
- params,
528
- 'Runo#params_from_request should build params from req.path_info and req.params'
529
- )
530
-
531
- env = Rack::MockRequest.env_for(
532
- 'http://example.com/foo/bar/20091120_0001/files/qux=456/index.html?acorn=round',
533
- {
534
- :method => 'post',
535
- :script_name => '',
536
- :input => 'coax=true&some-doors=open',
537
- }
538
- )
539
- req = Rack::Request.new env
540
- params = runo.instance_eval {
541
- params_from_request req
542
- }
543
- assert_equal(
544
- {
545
- :conds => {:qux => '456'},
546
- :action => nil,
547
- :sub_action => nil,
548
- 'acorn' => 'round',
549
- 'coax' => 'true',
550
- 'some' => {'doors' => 'open'},
551
- },
552
- params,
553
- 'Runo#params_from_request should attach the params from path_info to the base SD'
554
- )
555
-
556
- env = Rack::MockRequest.env_for(
557
- 'http://example.com/foo/bar/qux=456/index.html?acorn=round',
558
- {
559
- :method => 'post',
560
- :script_name => '',
561
- :input => 'some-doors=open&some.action-open=submit',
562
- }
563
- )
564
- req = Rack::Request.new env
565
- params = runo.instance_eval {
566
- params_from_request req
567
- }
568
- assert_equal(
569
- {
570
- :conds => {:qux => '456'},
571
- :action => nil,
572
- :sub_action => nil,
573
- 'acorn' => 'round',
574
- 'some' => {'doors' => 'open', :action => :open},
575
- },
576
- params,
577
- 'Runo#params_from_request should build params from req.path_info and req.params'
578
- )
579
-
580
- env = Rack::MockRequest.env_for(
581
- 'http://example.com/foo/bar/update.html',
582
- {
583
- :method => 'post',
584
- :script_name => '',
585
- :input => '.action=open_sesami',
586
- }
587
- )
588
- req = Rack::Request.new env
589
- params = runo.instance_eval {
590
- params_from_request req
591
- }
592
- assert_equal(
593
- {
594
- :conds => {},
595
- :action => :open,
596
- :sub_action => :sesami,
597
- },
598
- params,
599
- 'Runo#params_from_request should override path_info by :input'
600
- )
601
-
602
- env = Rack::MockRequest.env_for(
603
- 'http://example.com/foo/bar/update.html',
604
- {
605
- :method => 'post',
606
- :script_name => '',
607
- :input => '.action-open_sesami=submit',
608
- }
609
- )
610
- req = Rack::Request.new env
611
- params = runo.instance_eval {
612
- params_from_request req
613
- }
614
- assert_equal(
615
- {
616
- :conds => {},
617
- :action => :open,
618
- :sub_action => :sesami,
619
- },
620
- params,
621
- 'Runo#params_from_request should override path_info by :input'
622
- )
623
- end
624
-
625
- def test_current
626
- Runo.current[:foo] = 'main foo'
627
- main_current = Runo.current
628
-
629
- t = Thread.new {
630
- assert_not_equal(
631
- main_current,
632
- Runo.current,
633
- 'Runo.current should be unique per a thread'
634
- )
635
- assert_not_equal(
636
- 'main foo',
637
- Runo.current[:foo],
638
- 'Runo.current should be unique per a thread'
639
- )
640
- Runo.current[:foo] = 'child foo'
641
- }
642
- t.join
643
-
644
- assert_equal(
645
- 'main foo',
646
- Runo.current[:foo],
647
- 'Runo.current should be unique per a thread'
648
- )
649
- end
650
-
651
- def test_login
652
- Runo.client = nil
653
- res = Runo.new.send(
654
- :login,
655
- Runo::Set::Static::Folder.root.item('foo', 'main'),
656
- {'id' => 'test', 'pw' => 'test', :conds => {:id => '20100222_0123'}, 'dest_action' => 'update'}
657
- )
658
- assert_equal(
659
- 'test',
660
- Runo.client,
661
- 'Runo#login should set Runo.client given a valid pair of user/password'
662
- )
663
- assert_match(
664
- %r{/foo/20100222/123/update.html},
665
- res[1]['Location'],
666
- 'Runo#login should return a proper location header'
667
- )
668
- end
669
-
670
- def test_login_default_action
671
- Runo.client = nil
672
- res = Runo.new.send(
673
- :login,
674
- Runo::Set::Static::Folder.root.item('foo', 'main'),
675
- {'id' => 'test', 'pw' => 'test', :conds => {:id => '20100222_0123'}}
676
- )
677
- assert_match(
678
- %r{/foo/20100222/123/index.html},
679
- res[1]['Location'],
680
- "Runo#login should set 'index' as the default action of a location"
681
- )
682
- end
683
-
684
- def test_login_with_wrong_account
685
- Runo.client = nil
686
-
687
- assert_raise(
688
- Runo::Error::Forbidden,
689
- 'Runo#login should raise Error::Forbidden given a non-existent user'
690
- ) {
691
- Runo.new.send(
692
- :login,
693
- Runo::Set::Static::Folder.root.item('foo', 'main'),
694
- {'id' => 'non-existent', 'pw' => 'test'}
695
- )
696
- }
697
- assert_equal(
698
- 'nobody',
699
- Runo.client,
700
- 'Runo#login should not set Runo.client with a non-existent user'
701
- )
702
-
703
- assert_raise(
704
- Runo::Error::Forbidden,
705
- 'Runo#login should raise Error::Forbidden given a empty password'
706
- ) {
707
- Runo.new.send(
708
- :login,
709
- Runo::Set::Static::Folder.root.item('foo', 'main'),
710
- {'id' => 'test', 'pw' => nil}
711
- )
712
- }
713
- assert_equal(
714
- 'nobody',
715
- Runo.client,
716
- 'Runo#login should not set Runo.client with an empty password'
717
- )
718
-
719
- assert_raise(
720
- Runo::Error::Forbidden,
721
- 'Runo#login should raise Error::Forbidden given a wrong password'
722
- ) {
723
- res = Runo.new.send(
724
- :login,
725
- Runo::Set::Static::Folder.root.item('foo', 'main'),
726
- {
727
- 'id' => 'test',
728
- 'pw' => 'wrong',
729
- :conds => {:id => '20100222_0123'},
730
- 'dest_action' => 'update'
731
- }
732
- )
733
- }
734
- assert_equal(
735
- 'nobody',
736
- Runo.client,
737
- 'Runo#login should not set Runo.client with a wrong password'
738
- )
739
- end
740
-
741
- def test_logout
742
- Runo.client = 'frank'
743
- res = Runo.new.send(
744
- :logout,
745
- Runo::Set::Static::Folder.root.item('foo', 'main'),
746
- {'id' => 'test', 'pw' => 'test', :conds => {:id => '20100222_0123'}}
747
- )
748
- assert_equal(
749
- 'nobody',
750
- Runo.client,
751
- 'Runo#logout should clear Runo.client'
752
- )
753
- assert_match(
754
- %r{/foo/20100222/123/index.html},
755
- res[1]['Location'],
756
- 'Runo#logout should return a proper location header'
757
- )
758
- end
759
-
760
- def test_libdir
761
- assert_match(
762
- %r{^.*/lib$},
763
- Runo.libdir,
764
- 'Runo#libdir should return the lib/ directory where the runo.rb is in'
765
- )
766
- end
767
-
768
- end