runo 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -118
- data/bin/runo +4 -29
- data/lib/dummy.rb +0 -0
- metadata +12 -278
- data/lib/_error.rb +0 -14
- data/lib/_field.rb +0 -260
- data/lib/_i18n.rb +0 -144
- data/lib/_parser.rb +0 -256
- data/lib/_path.rb +0 -86
- data/lib/_storage/_storage.rb +0 -215
- data/lib/_storage/file.rb +0 -201
- data/lib/_storage/sequel.rb +0 -174
- data/lib/_storage/temp.rb +0 -73
- data/lib/_widget/action_create.rb +0 -23
- data/lib/_widget/action_login.rb +0 -22
- data/lib/_widget/action_signup.rb +0 -16
- data/lib/_widget/action_update.rb +0 -16
- data/lib/_widget/crumb.rb +0 -24
- data/lib/_widget/done.rb +0 -16
- data/lib/_widget/login.rb +0 -25
- data/lib/_widget/me.rb +0 -31
- data/lib/_widget/message.rb +0 -51
- data/lib/_widget/navi.rb +0 -88
- data/lib/_widget/submit.rb +0 -49
- data/lib/_widget/view_ym.rb +0 -77
- data/lib/_workflow/_workflow.rb +0 -89
- data/lib/_workflow/attachment.rb +0 -50
- data/lib/_workflow/blog.rb +0 -28
- data/lib/_workflow/contact.rb +0 -23
- data/lib/_workflow/forum.rb +0 -26
- data/lib/_workflow/register.rb +0 -39
- data/lib/meta/_meta.rb +0 -20
- data/lib/meta/group.rb +0 -19
- data/lib/meta/id.rb +0 -59
- data/lib/meta/owner.rb +0 -21
- data/lib/meta/timestamp.rb +0 -118
- data/lib/runo.rb +0 -396
- data/lib/scalar/checkbox.rb +0 -68
- data/lib/scalar/file.rb +0 -144
- data/lib/scalar/img.rb +0 -112
- data/lib/scalar/password.rb +0 -58
- data/lib/scalar/radio.rb +0 -47
- data/lib/scalar/select.rb +0 -47
- data/lib/scalar/text.rb +0 -38
- data/lib/scalar/textarea.rb +0 -35
- data/lib/scalar/textarea_pre.rb +0 -14
- data/lib/scalar/textarea_wiki.rb +0 -173
- data/lib/set/_set.rb +0 -196
- data/lib/set/dynamic.rb +0 -177
- data/lib/set/static.rb +0 -102
- data/lib/set/static_folder.rb +0 -96
- data/locale/en/index.po +0 -242
- data/locale/index.pot +0 -243
- data/locale/ja/index.po +0 -242
- data/locale/lazy_parser.rb +0 -54
- data/skel/config.ru +0 -27
- data/skel/skin/_users/00000000_frank-avatar.jpg +0 -0
- data/skel/skin/_users/00000000_frank-avatar_small.jpg +0 -0
- data/skel/skin/_users/00000000_frank.yaml +0 -12
- data/skel/skin/_users/00000000_root-avatar.jpg +0 -0
- data/skel/skin/_users/00000000_root-avatar_small.jpg +0 -0
- data/skel/skin/_users/00000000_root.yaml +0 -11
- data/skel/skin/_users/css/users.css +0 -21
- data/skel/skin/_users/css/users.less +0 -25
- data/skel/skin/_users/done.html +0 -42
- data/skel/skin/_users/index.html +0 -46
- data/skel/skin/_users/index.yaml +0 -3
- data/skel/skin/_users/summary.html +0 -40
- data/skel/skin/css/base.css +0 -93
- data/skel/skin/css/base.less +0 -139
- data/skel/skin/css/coax.css +0 -199
- data/skel/skin/css/coax.less +0 -244
- data/skel/skin/examples/blog/20091214_0001.yaml +0 -8
- data/skel/skin/examples/blog/20100630_0001.yaml +0 -8
- data/skel/skin/examples/blog/20100630_0002.yaml +0 -14
- data/skel/skin/examples/blog/20100701_0001.yaml +0 -8
- data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f.jpg +0 -0
- data/skel/skin/examples/blog/20100701_0002-a-20100701_0001-f_small.jpg +0 -0
- data/skel/skin/examples/blog/20100701_0002.yaml +0 -19
- data/skel/skin/examples/blog/frank/20100701_0001.yaml +0 -10
- data/skel/skin/examples/blog/frank/index.yaml +0 -4
- data/skel/skin/examples/blog/index.html +0 -51
- data/skel/skin/examples/blog/rss.xml +0 -18
- data/skel/skin/examples/contact/20100701_0001-file.txt +0 -1
- data/skel/skin/examples/contact/20100701_0001.yaml +0 -15
- data/skel/skin/examples/contact/20100701_0002.yaml +0 -8
- data/skel/skin/examples/contact/20100701_0003.yaml +0 -9
- data/skel/skin/examples/contact/index.html +0 -47
- data/skel/skin/examples/contact/js/contact.js +0 -13
- data/skel/skin/examples/contact/summary.html +0 -54
- data/skel/skin/examples/forum/20100701_0001.yaml +0 -41
- data/skel/skin/examples/forum/20100701_0002.yaml +0 -25
- data/skel/skin/examples/forum/index.html +0 -68
- data/skel/skin/examples/forum/summary.html +0 -47
- data/skel/skin/examples/index.html +0 -73
- data/skel/skin/index.html +0 -39
- data/skel/skin/js/base.js +0 -50
- data/t/locale/de/index.po +0 -19
- data/t/locale/en-GB/index.po +0 -25
- data/t/locale/ja/index.po +0 -30
- data/t/skin/_users/00000000_test.yaml +0 -3
- data/t/skin/_users/index.html +0 -13
- data/t/skin/foo/20091120_0001.yaml +0 -7
- data/t/skin/foo/bar/20091120_0001.yaml +0 -5
- data/t/skin/foo/bar/index.yaml +0 -5
- data/t/skin/foo/baz/css/baz.css +0 -1
- data/t/skin/foo/css/foo.css +0 -1
- data/t/skin/foo/index.html +0 -14
- data/t/skin/foo/index.yaml +0 -7
- data/t/skin/foo/not_css/foo.css +0 -1
- data/t/skin/foo/qux/index.html +0 -8
- data/t/skin/foo/qux/moo/index.html +0 -6
- data/t/skin/foo/sub-20100306_0001.yaml +0 -3
- data/t/skin/index.yaml +0 -3
- data/t/skin/t_attachment/index.html +0 -13
- data/t/skin/t_contact/done.html +0 -6
- data/t/skin/t_contact/index.html +0 -9
- data/t/skin/t_file/index.html +0 -16
- data/t/skin/t_img/index.html +0 -14
- data/t/skin/t_img/test.jpg +0 -0
- data/t/skin/t_select/index.html +0 -9
- data/t/skin/t_store/index.html +0 -9
- data/t/skin/t_summary/20100326_0001.yaml +0 -3
- data/t/skin/t_summary/create.html +0 -9
- data/t/skin/t_summary/index.html +0 -9
- data/t/skin/t_summary/summary.html +0 -9
- data/t/t.rb +0 -27
- data/t/test_checkbox.rb +0 -273
- data/t/test_field.rb +0 -330
- data/t/test_file.rb +0 -900
- data/t/test_id.rb +0 -215
- data/t/test_img.rb +0 -328
- data/t/test_meta.rb +0 -57
- data/t/test_parser.rb +0 -1516
- data/t/test_password.rb +0 -188
- data/t/test_radio.rb +0 -226
- data/t/test_role.rb +0 -249
- data/t/test_runo.rb +0 -768
- data/t/test_runo_call.rb +0 -1281
- data/t/test_runo_i18n.rb +0 -325
- data/t/test_select.rb +0 -182
- data/t/test_set_complex.rb +0 -527
- data/t/test_set_dynamic.rb +0 -1504
- data/t/test_set_folder.rb +0 -515
- data/t/test_set_permit.rb +0 -246
- data/t/test_set_static.rb +0 -468
- data/t/test_storage.rb +0 -915
- data/t/test_text.rb +0 -125
- data/t/test_textarea.rb +0 -138
- data/t/test_timestamp.rb +0 -473
- data/t/test_workflow.rb +0 -367
data/t/test_runo_i18n.rb
DELETED
@@ -1,325 +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_I18n < Test::Unit::TestCase
|
9
|
-
|
10
|
-
include Runo::I18n
|
11
|
-
|
12
|
-
def setup
|
13
|
-
Runo::I18n.domain = 'index'
|
14
|
-
Runo::I18n.po_dir = './t/locale'
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_lang
|
21
|
-
Runo::I18n.lang = 'ja'
|
22
|
-
assert_instance_of(
|
23
|
-
Array,
|
24
|
-
Runo::I18n.lang,
|
25
|
-
'Runo::I18n.lang should return an array'
|
26
|
-
)
|
27
|
-
assert_equal(
|
28
|
-
['ja'],
|
29
|
-
Runo::I18n.lang,
|
30
|
-
'Runo::I18n.lang should return the current acceptable language-ranges'
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_lang_case
|
35
|
-
Runo::I18n.lang = 'JA-jp'
|
36
|
-
assert_equal(
|
37
|
-
['ja-JP'],
|
38
|
-
Runo::I18n.lang,
|
39
|
-
'Runo::I18n.lang should be properly downcase/upcased'
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_multiple_lang
|
44
|
-
Runo::I18n.lang = 'ja, de;q=0.5, en;q=0.8'
|
45
|
-
assert_equal(
|
46
|
-
['ja', 'en', 'de'],
|
47
|
-
Runo::I18n.lang,
|
48
|
-
'Runo::I18n.lang should sort the language-ranges by their quality values'
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_same_qvalues
|
53
|
-
Runo::I18n.lang = 'ja, de;q=0.5, en;q=0.5'
|
54
|
-
assert_equal(
|
55
|
-
['ja', 'de', 'en'],
|
56
|
-
Runo::I18n.lang,
|
57
|
-
'Runo::I18n.lang should be sorted by their original order if the qvalues are same'
|
58
|
-
)
|
59
|
-
Runo::I18n.lang = 'ja, de, en'
|
60
|
-
assert_equal(
|
61
|
-
['ja', 'de', 'en'],
|
62
|
-
Runo::I18n.lang,
|
63
|
-
'Runo::I18n.lang should be sorted by their original order if the qvalues are same'
|
64
|
-
)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_po_dir
|
68
|
-
Runo::I18n.po_dir = 'foo/bar'
|
69
|
-
assert_equal(
|
70
|
-
'foo/bar',
|
71
|
-
Runo::I18n.po_dir,
|
72
|
-
'Runo::I18n.po_dir should be return the path to po files'
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_domain
|
77
|
-
Runo::I18n.domain = 'foo'
|
78
|
-
assert_equal(
|
79
|
-
'foo',
|
80
|
-
Runo::I18n.domain,
|
81
|
-
'Runo::I18n.domain should be return the current domain'
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_bindtextdomain
|
86
|
-
Runo::I18n.bindtextdomain('foo', 'bar/baz')
|
87
|
-
assert_equal(
|
88
|
-
'foo',
|
89
|
-
Runo::I18n.domain,
|
90
|
-
'Runo::I18n.bindtextdomain should set the current domain'
|
91
|
-
)
|
92
|
-
assert_equal(
|
93
|
-
'bar/baz',
|
94
|
-
Runo::I18n.po_dir,
|
95
|
-
'Runo::I18n.bindtextdomain should set the path to po files'
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_msg
|
100
|
-
Runo::I18n.lang = 'ja'
|
101
|
-
assert_instance_of(
|
102
|
-
::Hash,
|
103
|
-
Runo::I18n.msg,
|
104
|
-
'Runo::I18n.msg should return a hash'
|
105
|
-
)
|
106
|
-
assert_equal(
|
107
|
-
{'color' => '色', 'one color' =>['%{n}色']},
|
108
|
-
Runo::I18n.msg.reject {|k, v| k == :plural },
|
109
|
-
'Runo::I18n.msg should return a hash containing {msgid => msgstr}'
|
110
|
-
)
|
111
|
-
assert_instance_of(
|
112
|
-
::Proc,
|
113
|
-
Runo::I18n.msg[:plural],
|
114
|
-
'Runo::I18n.msg[:plural] should return a proc'
|
115
|
-
)
|
116
|
-
|
117
|
-
Runo::I18n.lang = 'po'
|
118
|
-
assert_equal(
|
119
|
-
{},
|
120
|
-
Runo::I18n.msg,
|
121
|
-
'Runo::I18n.msg should be reset when the lang is updated'
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_merge_msg!
|
126
|
-
Runo::I18n.lang = 'no'
|
127
|
-
assert_equal({}, Runo::I18n.msg)
|
128
|
-
|
129
|
-
Runo::I18n.merge_msg!('color' => 'farge')
|
130
|
-
assert_equal(
|
131
|
-
{'color' => 'farge'},
|
132
|
-
Runo::I18n.msg,
|
133
|
-
'Runo::I18n.merge_msg! should dynamically merge a hash to the msg of the current thread'
|
134
|
-
)
|
135
|
-
|
136
|
-
Runo::I18n.merge_msg!(:plural => Proc.new { 123 })
|
137
|
-
assert_equal(
|
138
|
-
{'color' => 'farge'},
|
139
|
-
Runo::I18n.msg,
|
140
|
-
'Runo::I18n.merge_msg! should not merge :plural'
|
141
|
-
)
|
142
|
-
|
143
|
-
Runo::I18n.lang = 'no'
|
144
|
-
assert_equal(
|
145
|
-
{},
|
146
|
-
Runo::I18n.msg,
|
147
|
-
'Runo::I18n.merge_msg! should not affect anything other than the current thread'
|
148
|
-
)
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_rex_plural_expression_ok
|
152
|
-
src = <<'_eos'.split "\n"
|
153
|
-
"Plural-Forms: nplurals=1; plural=0;"
|
154
|
-
"Plural-Forms: nplurals=2; plural=n != 1;"
|
155
|
-
"Plural-Forms: nplurals=2; plural=n>1;"
|
156
|
-
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;"
|
157
|
-
"Plural-Forms: nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2;"
|
158
|
-
"Plural-Forms: nplurals=3; Plural=n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2;"
|
159
|
-
"Plural-Forms: nplurals=3; Plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;"
|
160
|
-
"Plural-Forms: nplurals=3; Plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;"
|
161
|
-
"Plural-Forms: nplurals=3; Plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;"
|
162
|
-
"Plural-Forms: nplurals=3; Plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;"
|
163
|
-
"Plural-Forms: nplurals=4; Plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;"
|
164
|
-
_eos
|
165
|
-
src.each {|s|
|
166
|
-
assert_match(
|
167
|
-
Runo::I18n::REX::PLURAL_EXPRESSION,
|
168
|
-
s,
|
169
|
-
'Runo::I18n::REX::PLURAL_EXPRESSION should match'
|
170
|
-
)
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_rex_plural_expression_ng
|
175
|
-
src = <<'_eos'.split "\n"
|
176
|
-
"Plural-Forms: nplurals=1; plural=rm '.';"
|
177
|
-
"Plural-Forms: nplurals=1; plural=Fileutils.rm_r('.');"
|
178
|
-
"Plural-Forms: nplurals=1; plural=Fileutils.rm_r '.';"
|
179
|
-
"Plural-Forms: nplurals=1; plural=Fileutils.rm_r ".";"
|
180
|
-
"Plural-Forms: nplurals=2; plural=n;"
|
181
|
-
"Plural-Forms: nplurals=2; plural=nn;"
|
182
|
-
"Plural-Forms: nplurals=3; plural=n();"
|
183
|
-
"Plural-Forms: nplurals=3; plural=n(123);"
|
184
|
-
"Plural-Forms: nplurals=3; plural=n 123;"
|
185
|
-
_eos
|
186
|
-
src.each {|s|
|
187
|
-
assert_no_match(
|
188
|
-
Runo::I18n::REX::PLURAL_EXPRESSION,
|
189
|
-
s,
|
190
|
-
'Runo::I18n::REX::PLURAL_EXPRESSION should not match malicious expressions'
|
191
|
-
)
|
192
|
-
}
|
193
|
-
end
|
194
|
-
|
195
|
-
def test__
|
196
|
-
Runo::I18n.lang = 'ja'
|
197
|
-
assert_equal(
|
198
|
-
'色',
|
199
|
-
_('color'),
|
200
|
-
'Runo::I18n#_() should return a string according to the msgid'
|
201
|
-
)
|
202
|
-
|
203
|
-
Runo::I18n.lang = 'en-GB'
|
204
|
-
assert_equal(
|
205
|
-
'colour',
|
206
|
-
_('color'),
|
207
|
-
'Runo::I18n#_() should return a string according to the msgid'
|
208
|
-
)
|
209
|
-
|
210
|
-
Runo::I18n.lang = 'no'
|
211
|
-
assert_equal(
|
212
|
-
'color',
|
213
|
-
_('color'),
|
214
|
-
'Runo::I18n#_() should return a msgid if the msgid is not existed in the msg'
|
215
|
-
)
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_n_
|
219
|
-
Runo::I18n.lang = 'ja'
|
220
|
-
assert_equal(
|
221
|
-
'%{n}色',
|
222
|
-
n_('one color', '%{n} colors', 1),
|
223
|
-
'Runo::I18n#n_() should return a string according to the msgid and the n'
|
224
|
-
)
|
225
|
-
assert_equal(
|
226
|
-
'%{n}色',
|
227
|
-
n_('one color', '%{n} colors', 2),
|
228
|
-
'Runo::I18n#n_() should return a string according to the msgid and the n'
|
229
|
-
)
|
230
|
-
|
231
|
-
Runo::I18n.lang = 'en-GB'
|
232
|
-
assert_equal(
|
233
|
-
'one colour',
|
234
|
-
n_('one color', '%{n} colors', 1),
|
235
|
-
'Runo::I18n#n_() should return a string according to the msgid and the n'
|
236
|
-
)
|
237
|
-
assert_equal(
|
238
|
-
'%{n} colours',
|
239
|
-
n_('one color', '%{n} colors', 2),
|
240
|
-
'Runo::I18n#n_() should return a string according to the msgid and the n'
|
241
|
-
)
|
242
|
-
|
243
|
-
Runo::I18n.lang = 'no'
|
244
|
-
assert_equal(
|
245
|
-
'one color',
|
246
|
-
n_('one color', '%{n} colors', 1),
|
247
|
-
'Runo::I18n#_() should return a msgid if the msgid is not existed in the msg'
|
248
|
-
)
|
249
|
-
assert_equal(
|
250
|
-
'%{n} colors',
|
251
|
-
n_('one color', '%{n} colors', 2),
|
252
|
-
'Runo::I18n#_() should return a msgid if the msgid is not existed in the msg'
|
253
|
-
)
|
254
|
-
end
|
255
|
-
|
256
|
-
def test__with_n_
|
257
|
-
Runo::I18n.lang = 'en-GB'
|
258
|
-
assert_equal(
|
259
|
-
'one colour',
|
260
|
-
_('one color'),
|
261
|
-
'Runo::I18n#_() should return msgstr[0] if the msgid refer to plural msgstrs'
|
262
|
-
)
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_n_with__
|
266
|
-
Runo::I18n.lang = 'en-GB'
|
267
|
-
assert_equal(
|
268
|
-
'color',
|
269
|
-
n_('color', '%{n} colors', 1),
|
270
|
-
'Runo::I18n#n_() should return msgid if the msgid refer to sigular msgstr'
|
271
|
-
)
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_msgstr
|
275
|
-
Runo::I18n.lang = 'en-GB'
|
276
|
-
|
277
|
-
assert_instance_of(
|
278
|
-
Runo::I18n::Msgstr,
|
279
|
-
_('color'),
|
280
|
-
'Runo::I18n#_() should return a instance of Runo::I18n::Msgstr'
|
281
|
-
)
|
282
|
-
|
283
|
-
s = n_('one color', '%{n} colors', 2)
|
284
|
-
assert_instance_of(
|
285
|
-
Runo::I18n::Msgstr,
|
286
|
-
s,
|
287
|
-
'Runo::I18n#n_() should return a instance of Runo::I18n::Msgstr'
|
288
|
-
)
|
289
|
-
assert_equal(
|
290
|
-
'2 colours',
|
291
|
-
s % {:n => 2},
|
292
|
-
'Runo::I18n::Msgstr#% should be able to proccess named variables'
|
293
|
-
)
|
294
|
-
assert_equal(
|
295
|
-
'2 colours',
|
296
|
-
s % [2],
|
297
|
-
"Runo::I18n::Msgstr#% should regard %{...} as '%s' if given an array"
|
298
|
-
)
|
299
|
-
assert_equal(
|
300
|
-
'2 colours',
|
301
|
-
s % 2,
|
302
|
-
"Runo::I18n::Msgstr#% should regard %{...} as '%s' if given a scalar"
|
303
|
-
)
|
304
|
-
|
305
|
-
s = n_('one foo', '%{n} foo %{bar}', 2)
|
306
|
-
assert_equal(
|
307
|
-
'2 foo selected',
|
308
|
-
s % [2, 'selected'],
|
309
|
-
"Runo::I18n::Msgstr#% should regard %{...} as '%s' if given an array"
|
310
|
-
)
|
311
|
-
|
312
|
-
s = n_('one color', '%{n} colors', 1)
|
313
|
-
assert_instance_of(
|
314
|
-
Runo::I18n::Msgstr,
|
315
|
-
s,
|
316
|
-
'Runo::I18n#n_() should return a instance of Runo::I18n::Msgstr'
|
317
|
-
)
|
318
|
-
assert_equal(
|
319
|
-
'one colour',
|
320
|
-
s % {:n => 1},
|
321
|
-
'Runo::I18n::Msgstr#% should work with msgstrs without a placeholder'
|
322
|
-
)
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
data/t/test_select.rb
DELETED
@@ -1,182 +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_Select < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
meta = nil
|
12
|
-
Runo::Parser.gsub_scalar("$(foo select 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
|
-
'Select#initialize should set :options from the csv token'
|
27
|
-
)
|
28
|
-
assert_equal(
|
29
|
-
true,
|
30
|
-
@f[:mandatory],
|
31
|
-
'Select#initialize should set :mandatory from the misc token'
|
32
|
-
)
|
33
|
-
assert_equal(
|
34
|
-
'baz',
|
35
|
-
@f[:default],
|
36
|
-
'Select#initialize should set :default from the token'
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_meta_options_from_range
|
41
|
-
meta = nil
|
42
|
-
Runo::Parser.gsub_scalar("$(foo select 1..5)") {|id, m|
|
43
|
-
meta = m
|
44
|
-
''
|
45
|
-
}
|
46
|
-
f = Runo::Field.instance meta
|
47
|
-
assert_equal(
|
48
|
-
['1', '2', '3', '4', '5'],
|
49
|
-
f[:options],
|
50
|
-
'Select#initialize should set :options from the range token'
|
51
|
-
)
|
52
|
-
|
53
|
-
meta = nil
|
54
|
-
Runo::Parser.gsub_scalar("$(foo select ..5)") {|id, m|
|
55
|
-
meta = m
|
56
|
-
''
|
57
|
-
}
|
58
|
-
f = Runo::Field.instance meta
|
59
|
-
assert_equal(
|
60
|
-
['0', '1', '2', '3', '4', '5'],
|
61
|
-
f[:options],
|
62
|
-
'Select#initialize should set :options from the range token'
|
63
|
-
)
|
64
|
-
|
65
|
-
meta = nil
|
66
|
-
Runo::Parser.gsub_scalar("$(foo select 1..)") {|id, m|
|
67
|
-
meta = m
|
68
|
-
''
|
69
|
-
}
|
70
|
-
f = Runo::Field.instance meta
|
71
|
-
assert_equal(
|
72
|
-
nil,
|
73
|
-
f[:options],
|
74
|
-
'Select#initialize should not refer to the range token if there is no maximum'
|
75
|
-
)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_val_cast
|
79
|
-
assert_equal(
|
80
|
-
'',
|
81
|
-
@f.val,
|
82
|
-
'Select#val_cast should cast the given val to String'
|
83
|
-
)
|
84
|
-
|
85
|
-
@f.load 123
|
86
|
-
assert_equal(
|
87
|
-
'123',
|
88
|
-
@f.val,
|
89
|
-
'Select#val_cast should cast the given val to String'
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_get
|
94
|
-
@f.load ''
|
95
|
-
assert_equal(
|
96
|
-
'',
|
97
|
-
@f.get,
|
98
|
-
'Select#get should return proper string'
|
99
|
-
)
|
100
|
-
assert_equal(
|
101
|
-
<<_html,
|
102
|
-
<span class="select">
|
103
|
-
<select name="">
|
104
|
-
<option value="">please select</option>
|
105
|
-
<option>bar</option>
|
106
|
-
<option>baz</option>
|
107
|
-
<option>qux</option>
|
108
|
-
</select>
|
109
|
-
</span>
|
110
|
-
_html
|
111
|
-
@f.get(:action => :create),
|
112
|
-
'Select#get should return proper string'
|
113
|
-
)
|
114
|
-
|
115
|
-
@f.load 'qux'
|
116
|
-
assert_equal(
|
117
|
-
'qux',
|
118
|
-
@f.get,
|
119
|
-
'Select#get should return proper string'
|
120
|
-
)
|
121
|
-
assert_equal(
|
122
|
-
<<_html,
|
123
|
-
<span class="select">
|
124
|
-
<select name="">
|
125
|
-
<option>bar</option>
|
126
|
-
<option>baz</option>
|
127
|
-
<option selected>qux</option>
|
128
|
-
</select>
|
129
|
-
</span>
|
130
|
-
_html
|
131
|
-
@f.get(:action => :update),
|
132
|
-
'Select#get should return proper string'
|
133
|
-
)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_get_escape
|
137
|
-
@f[:options] = ['foo', '<bar>']
|
138
|
-
@f.load '<bar>'
|
139
|
-
assert_equal(
|
140
|
-
'<bar>',
|
141
|
-
@f.get,
|
142
|
-
'Select#get should escape the special characters'
|
143
|
-
)
|
144
|
-
assert_equal(
|
145
|
-
<<_html,
|
146
|
-
<span class="select">
|
147
|
-
<select name="">
|
148
|
-
<option>foo</option>
|
149
|
-
<option selected><bar></option>
|
150
|
-
</select>
|
151
|
-
</span>
|
152
|
-
_html
|
153
|
-
@f.get(:action => :update),
|
154
|
-
'Select#get should escape the special characters'
|
155
|
-
)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_errors
|
159
|
-
@f.load ''
|
160
|
-
@f[:mandatory] = nil
|
161
|
-
assert_equal(
|
162
|
-
[],
|
163
|
-
@f.errors,
|
164
|
-
'Select#errors should return the errors of the current val'
|
165
|
-
)
|
166
|
-
@f[:mandatory] = true
|
167
|
-
assert_equal(
|
168
|
-
['mandatory'],
|
169
|
-
@f.errors,
|
170
|
-
'Select#errors should return the errors of the current val'
|
171
|
-
)
|
172
|
-
|
173
|
-
@f.load 'boo'
|
174
|
-
@f[:mandatory] = nil
|
175
|
-
assert_equal(
|
176
|
-
['no such option'],
|
177
|
-
@f.errors,
|
178
|
-
'Select#errors should return the errors of the current val'
|
179
|
-
)
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|