runo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.rdoc +120 -0
- data/bin/runo +35 -0
- data/lib/_error.rb +14 -0
- data/lib/_field.rb +260 -0
- data/lib/_i18n.rb +141 -0
- data/lib/_parser.rb +243 -0
- data/lib/_path.rb +86 -0
- data/lib/_storage/_storage.rb +213 -0
- data/lib/_storage/file.rb +200 -0
- data/lib/_storage/sequel.rb +174 -0
- data/lib/_storage/temp.rb +73 -0
- data/lib/_widget/action_create.rb +23 -0
- data/lib/_widget/action_login.rb +22 -0
- data/lib/_widget/action_signup.rb +16 -0
- data/lib/_widget/action_update.rb +16 -0
- data/lib/_widget/crumb.rb +24 -0
- data/lib/_widget/done.rb +16 -0
- data/lib/_widget/login.rb +25 -0
- data/lib/_widget/me.rb +31 -0
- data/lib/_widget/message.rb +51 -0
- data/lib/_widget/navi.rb +88 -0
- data/lib/_widget/submit.rb +49 -0
- data/lib/_widget/view_ym.rb +77 -0
- data/lib/_workflow/_workflow.rb +89 -0
- data/lib/_workflow/attachment.rb +50 -0
- data/lib/_workflow/blog.rb +28 -0
- data/lib/_workflow/contact.rb +23 -0
- data/lib/_workflow/forum.rb +26 -0
- data/lib/_workflow/register.rb +39 -0
- data/lib/meta/_meta.rb +20 -0
- data/lib/meta/group.rb +19 -0
- data/lib/meta/id.rb +59 -0
- data/lib/meta/owner.rb +21 -0
- data/lib/meta/timestamp.rb +118 -0
- data/lib/runo.rb +396 -0
- data/lib/scalar/checkbox.rb +68 -0
- data/lib/scalar/file.rb +144 -0
- data/lib/scalar/img.rb +112 -0
- data/lib/scalar/password.rb +58 -0
- data/lib/scalar/radio.rb +47 -0
- data/lib/scalar/select.rb +47 -0
- data/lib/scalar/text.rb +38 -0
- data/lib/scalar/textarea.rb +35 -0
- data/lib/scalar/textarea_pre.rb +14 -0
- data/lib/scalar/textarea_wiki.rb +173 -0
- data/lib/set/_set.rb +195 -0
- data/lib/set/dynamic.rb +177 -0
- data/lib/set/static.rb +102 -0
- data/lib/set/static_folder.rb +96 -0
- data/locale/en/index.po +242 -0
- data/locale/index.pot +243 -0
- data/locale/ja/index.po +242 -0
- data/locale/lazy_parser.rb +54 -0
- data/skel/config.ru +27 -0
- 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 +12 -0
- 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 +11 -0
- data/skel/skin/_users/css/users.css +21 -0
- data/skel/skin/_users/css/users.less +25 -0
- data/skel/skin/_users/done.html +42 -0
- data/skel/skin/_users/index.html +46 -0
- data/skel/skin/_users/index.yaml +3 -0
- data/skel/skin/_users/summary.html +40 -0
- data/skel/skin/css/base.css +93 -0
- data/skel/skin/css/base.less +139 -0
- data/skel/skin/css/coax.css +199 -0
- data/skel/skin/css/coax.less +244 -0
- data/skel/skin/examples/blog/20091214_0001.yaml +8 -0
- data/skel/skin/examples/blog/20100630_0001.yaml +8 -0
- data/skel/skin/examples/blog/20100630_0002.yaml +14 -0
- data/skel/skin/examples/blog/20100701_0001.yaml +8 -0
- 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 +19 -0
- data/skel/skin/examples/blog/frank/20100701_0001.yaml +10 -0
- data/skel/skin/examples/blog/frank/index.yaml +4 -0
- data/skel/skin/examples/blog/index.html +51 -0
- data/skel/skin/examples/blog/rss.xml +18 -0
- data/skel/skin/examples/contact/20100701_0001-file.txt +1 -0
- data/skel/skin/examples/contact/20100701_0001.yaml +15 -0
- data/skel/skin/examples/contact/20100701_0002.yaml +8 -0
- data/skel/skin/examples/contact/20100701_0003.yaml +9 -0
- data/skel/skin/examples/contact/index.html +47 -0
- data/skel/skin/examples/contact/js/contact.js +13 -0
- data/skel/skin/examples/contact/summary.html +54 -0
- data/skel/skin/examples/forum/20100701_0001.yaml +41 -0
- data/skel/skin/examples/forum/20100701_0002.yaml +25 -0
- data/skel/skin/examples/forum/index.html +68 -0
- data/skel/skin/examples/forum/summary.html +47 -0
- data/skel/skin/examples/index.html +75 -0
- data/skel/skin/index.html +41 -0
- data/skel/skin/js/base.js +50 -0
- data/t/locale/de/index.po +19 -0
- data/t/locale/en-GB/index.po +25 -0
- data/t/locale/ja/index.po +30 -0
- data/t/skin/_users/00000000_test.yaml +3 -0
- data/t/skin/_users/index.html +13 -0
- data/t/skin/foo/20091120_0001.yaml +7 -0
- data/t/skin/foo/bar/20091120_0001.yaml +5 -0
- data/t/skin/foo/bar/index.yaml +5 -0
- data/t/skin/foo/baz/css/baz.css +1 -0
- data/t/skin/foo/css/foo.css +1 -0
- data/t/skin/foo/index.html +14 -0
- data/t/skin/foo/index.yaml +7 -0
- data/t/skin/foo/not_css/foo.css +1 -0
- data/t/skin/foo/sub-20100306_0001.yaml +3 -0
- data/t/skin/index.yaml +3 -0
- data/t/skin/t_attachment/index.html +13 -0
- data/t/skin/t_contact/done.html +6 -0
- data/t/skin/t_contact/index.html +9 -0
- data/t/skin/t_file/index.html +16 -0
- data/t/skin/t_img/index.html +14 -0
- data/t/skin/t_img/test.jpg +0 -0
- data/t/skin/t_select/index.html +9 -0
- data/t/skin/t_store/index.html +9 -0
- data/t/skin/t_summary/20100326_0001.yaml +3 -0
- data/t/skin/t_summary/create.html +9 -0
- data/t/skin/t_summary/index.html +9 -0
- data/t/skin/t_summary/summary.html +9 -0
- data/t/t.rb +27 -0
- data/t/test_checkbox.rb +273 -0
- data/t/test_field.rb +330 -0
- data/t/test_file.rb +900 -0
- data/t/test_id.rb +215 -0
- data/t/test_img.rb +328 -0
- data/t/test_meta.rb +57 -0
- data/t/test_parser.rb +1266 -0
- data/t/test_password.rb +188 -0
- data/t/test_radio.rb +226 -0
- data/t/test_role.rb +249 -0
- data/t/test_runo.rb +742 -0
- data/t/test_runo_call.rb +1286 -0
- data/t/test_runo_i18n.rb +318 -0
- data/t/test_select.rb +182 -0
- data/t/test_set_complex.rb +527 -0
- data/t/test_set_dynamic.rb +1504 -0
- data/t/test_set_folder.rb +515 -0
- data/t/test_set_permit.rb +246 -0
- data/t/test_set_static.rb +445 -0
- data/t/test_storage.rb +915 -0
- data/t/test_text.rb +125 -0
- data/t/test_textarea.rb +138 -0
- data/t/test_timestamp.rb +473 -0
- data/t/test_workflow.rb +367 -0
- metadata +345 -0
data/t/test_text.rb
ADDED
@@ -0,0 +1,125 @@
|
|
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_Text < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
meta = nil
|
12
|
+
Runo::Parser.gsub_scalar('$(foo text 3 1..5)') {|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
|
+
3,
|
25
|
+
@f[:size],
|
26
|
+
'Text#initialize should set :size from the token'
|
27
|
+
)
|
28
|
+
assert_equal(
|
29
|
+
1,
|
30
|
+
@f[:min],
|
31
|
+
'Text#initialize should set :min from the range token'
|
32
|
+
)
|
33
|
+
assert_equal(
|
34
|
+
5,
|
35
|
+
@f[:max],
|
36
|
+
'Text#initialize should set :max from the range token'
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_val_cast
|
41
|
+
assert_equal(
|
42
|
+
'',
|
43
|
+
@f.val,
|
44
|
+
'Text#val_cast should cast the given val to String'
|
45
|
+
)
|
46
|
+
|
47
|
+
@f.load 123
|
48
|
+
assert_equal(
|
49
|
+
'123',
|
50
|
+
@f.val,
|
51
|
+
'Text#val_cast should cast the given val to String'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_get
|
56
|
+
@f.load 'bar'
|
57
|
+
assert_equal(
|
58
|
+
'bar',
|
59
|
+
@f.get,
|
60
|
+
'Text#get should return proper string'
|
61
|
+
)
|
62
|
+
assert_equal(
|
63
|
+
'<span class="text"><input type="text" name="" value="bar" size="3" /></span>',
|
64
|
+
@f.get(:action => :update),
|
65
|
+
'Text#get should return proper string'
|
66
|
+
)
|
67
|
+
|
68
|
+
@f.load '<bar>'
|
69
|
+
assert_equal(
|
70
|
+
'<bar>',
|
71
|
+
@f.get,
|
72
|
+
'Text#get should escape the special characters'
|
73
|
+
)
|
74
|
+
assert_equal(
|
75
|
+
'<span class="text"><input type="text" name="" value="<bar>" size="3" /></span>',
|
76
|
+
@f.get(:action => :update),
|
77
|
+
'Text#get should escape the special characters'
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_errors
|
82
|
+
@f.load ''
|
83
|
+
@f[:min] = 0
|
84
|
+
assert_equal(
|
85
|
+
[],
|
86
|
+
@f.errors,
|
87
|
+
'Text#errors should return the errors of the current val'
|
88
|
+
)
|
89
|
+
@f[:min] = 1
|
90
|
+
assert_equal(
|
91
|
+
['mandatory'],
|
92
|
+
@f.errors,
|
93
|
+
'Text#errors should return the errors of the current val'
|
94
|
+
)
|
95
|
+
|
96
|
+
@f.load 'a'
|
97
|
+
@f[:min] = 1
|
98
|
+
assert_equal(
|
99
|
+
[],
|
100
|
+
@f.errors,
|
101
|
+
'Text#errors should return the errors of the current val'
|
102
|
+
)
|
103
|
+
@f[:min] = 2
|
104
|
+
assert_equal(
|
105
|
+
['too short: 2 characters minimum'],
|
106
|
+
@f.errors,
|
107
|
+
'Text#errors should return the errors of the current val'
|
108
|
+
)
|
109
|
+
|
110
|
+
@f.load 'abcde'
|
111
|
+
@f[:max] = 5
|
112
|
+
assert_equal(
|
113
|
+
[],
|
114
|
+
@f.errors,
|
115
|
+
'Text#errors should return the errors of the current val'
|
116
|
+
)
|
117
|
+
@f[:max] = 4
|
118
|
+
assert_equal(
|
119
|
+
['too long: 4 characters maximum'],
|
120
|
+
@f.errors,
|
121
|
+
'Text#errors should return the errors of the current val'
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
data/t/test_textarea.rb
ADDED
@@ -0,0 +1,138 @@
|
|
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_Textarea < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
meta = nil
|
12
|
+
Runo::Parser.gsub_scalar('$(foo textarea 76*8 1..1024)') {|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
|
+
76,
|
25
|
+
@f[:width],
|
26
|
+
'Textarea#initialize should set :width from the dimension token'
|
27
|
+
)
|
28
|
+
assert_equal(
|
29
|
+
8,
|
30
|
+
@f[:height],
|
31
|
+
'Textarea#initialize should set :height from the dimension token'
|
32
|
+
)
|
33
|
+
assert_equal(
|
34
|
+
1,
|
35
|
+
@f[:min],
|
36
|
+
'Text#initialize should set :min from the range token'
|
37
|
+
)
|
38
|
+
assert_equal(
|
39
|
+
1024,
|
40
|
+
@f[:max],
|
41
|
+
'Text#initialize should set :max from the range token'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_val_cast
|
46
|
+
assert_equal(
|
47
|
+
'',
|
48
|
+
@f.val,
|
49
|
+
'Textarea#val_cast should cast the given val to String'
|
50
|
+
)
|
51
|
+
|
52
|
+
@f.load 123
|
53
|
+
assert_equal(
|
54
|
+
'123',
|
55
|
+
@f.val,
|
56
|
+
'Textarea#val_cast should cast the given val to String'
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_get
|
61
|
+
@f.load 'bar'
|
62
|
+
assert_equal(
|
63
|
+
'bar',
|
64
|
+
@f.get,
|
65
|
+
'Textarea#get should return proper string'
|
66
|
+
)
|
67
|
+
assert_equal(
|
68
|
+
<<'_html',
|
69
|
+
<span class="textarea">
|
70
|
+
<textarea name="" cols="76" rows="8">bar</textarea>
|
71
|
+
</span>
|
72
|
+
_html
|
73
|
+
@f.get(:action => :update),
|
74
|
+
'Textarea#get should return proper string'
|
75
|
+
)
|
76
|
+
|
77
|
+
@f.load '<bar>'
|
78
|
+
assert_equal(
|
79
|
+
'<bar>',
|
80
|
+
@f.get,
|
81
|
+
'Textarea#get should escape the special characters'
|
82
|
+
)
|
83
|
+
assert_equal(
|
84
|
+
<<'_html',
|
85
|
+
<span class="textarea">
|
86
|
+
<textarea name="" cols="76" rows="8"><bar></textarea>
|
87
|
+
</span>
|
88
|
+
_html
|
89
|
+
@f.get(:action => :update),
|
90
|
+
'Textarea#get should escape the special characters'
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_errors
|
95
|
+
@f.load ''
|
96
|
+
@f[:min] = 0
|
97
|
+
assert_equal(
|
98
|
+
[],
|
99
|
+
@f.errors,
|
100
|
+
'Text#errors should return the errors of the current val'
|
101
|
+
)
|
102
|
+
@f[:min] = 1
|
103
|
+
assert_equal(
|
104
|
+
['mandatory'],
|
105
|
+
@f.errors,
|
106
|
+
'Text#errors should return the errors of the current val'
|
107
|
+
)
|
108
|
+
|
109
|
+
@f.load 'a'
|
110
|
+
@f[:min] = 1
|
111
|
+
assert_equal(
|
112
|
+
[],
|
113
|
+
@f.errors,
|
114
|
+
'Text#errors should return the errors of the current val'
|
115
|
+
)
|
116
|
+
@f[:min] = 2
|
117
|
+
assert_equal(
|
118
|
+
['too short: 2 characters minimum'],
|
119
|
+
@f.errors,
|
120
|
+
'Text#errors should return the errors of the current val'
|
121
|
+
)
|
122
|
+
|
123
|
+
@f.load 'abcde'
|
124
|
+
@f[:max] = 5
|
125
|
+
assert_equal(
|
126
|
+
[],
|
127
|
+
@f.errors,
|
128
|
+
'Text#errors should return the errors of the current val'
|
129
|
+
)
|
130
|
+
@f[:max] = 4
|
131
|
+
assert_equal(
|
132
|
+
['too long: 4 characters maximum'],
|
133
|
+
@f.errors,
|
134
|
+
'Text#errors should return the errors of the current val'
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
data/t/test_timestamp.rb
ADDED
@@ -0,0 +1,473 @@
|
|
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_Timestamp < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
meta = nil
|
12
|
+
Runo::Parser.gsub_scalar('$(foo meta-timestamp 16)') {|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
|
+
meta = nil
|
24
|
+
Runo::Parser.gsub_scalar('$(foo meta-timestamp can_edit)') {|id, m|
|
25
|
+
meta = m
|
26
|
+
''
|
27
|
+
}
|
28
|
+
f = Runo::Field.instance meta
|
29
|
+
assert_equal(
|
30
|
+
true,
|
31
|
+
f[:can_edit],
|
32
|
+
'Timestamp#initialize should set :can_edit from the tokens'
|
33
|
+
)
|
34
|
+
|
35
|
+
meta = nil
|
36
|
+
Runo::Parser.gsub_scalar('$(foo meta-timestamp can_update)') {|id, m|
|
37
|
+
meta = m
|
38
|
+
''
|
39
|
+
}
|
40
|
+
f = Runo::Field.instance meta
|
41
|
+
assert_equal(
|
42
|
+
true,
|
43
|
+
f[:can_update],
|
44
|
+
'Timestamp#initialize should set :can_update from the tokens'
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_val_cast
|
49
|
+
v = nil
|
50
|
+
assert_equal(
|
51
|
+
{},
|
52
|
+
@f.send(:val_cast, v),
|
53
|
+
'Timestamp#val_cast should return an empty hash if the val is not a hash nor a string'
|
54
|
+
)
|
55
|
+
|
56
|
+
v = {
|
57
|
+
'created' => Time.local(2010, 4, 1),
|
58
|
+
'updated' => Time.local(2010, 4, 3),
|
59
|
+
'published' => Time.local(2010, 4, 2),
|
60
|
+
}
|
61
|
+
assert_equal(
|
62
|
+
v,
|
63
|
+
@f.send(:val_cast, v),
|
64
|
+
'Timestamp#val_cast should pass through if the val is a hash'
|
65
|
+
)
|
66
|
+
|
67
|
+
v = 'true'
|
68
|
+
assert_equal(
|
69
|
+
{'published' => :same_as_updated},
|
70
|
+
@f.send(:val_cast, v),
|
71
|
+
"Timestamp#val_cast should set v['published'] to :same_as_updated if the val is 'true'"
|
72
|
+
)
|
73
|
+
|
74
|
+
v = '2010/4/26'
|
75
|
+
assert_equal(
|
76
|
+
{'published' => Time.local(2010, 4, 26)},
|
77
|
+
@f.send(:val_cast, v),
|
78
|
+
"Timestamp#val_cast should cast the val to v['published'] if the val represents a date"
|
79
|
+
)
|
80
|
+
v = '2010-4-26'
|
81
|
+
assert_equal(
|
82
|
+
{'published' => Time.local(2010, 4, 26)},
|
83
|
+
@f.send(:val_cast, v),
|
84
|
+
"Timestamp#val_cast should cast the val to v['published'] if the val represents a date"
|
85
|
+
)
|
86
|
+
v = '2010-4-26 20:14'
|
87
|
+
assert_equal(
|
88
|
+
{'published' => Time.local(2010, 4, 26, 20, 14)},
|
89
|
+
@f.send(:val_cast, v),
|
90
|
+
"Timestamp#val_cast should cast the val to v['published'] if the val represents a date"
|
91
|
+
)
|
92
|
+
v = '2010-4-26 20:14:45'
|
93
|
+
assert_equal(
|
94
|
+
{'published' => Time.local(2010, 4, 26, 20, 14, 45)},
|
95
|
+
@f.send(:val_cast, v),
|
96
|
+
"Timestamp#val_cast should cast the val to v['published'] if the val represents a date"
|
97
|
+
)
|
98
|
+
|
99
|
+
v = '2010-4-89'
|
100
|
+
assert_equal(
|
101
|
+
{},
|
102
|
+
@f.send(:val_cast, v),
|
103
|
+
'Timestamp#val_cast should return an empty hash if the given date is out of range'
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_get
|
108
|
+
@f.load(
|
109
|
+
'created' => Time.local(2010, 4, 25),
|
110
|
+
'updated' => Time.local(2010, 4, 27),
|
111
|
+
'published' => Time.local(2010, 4, 26, 20, 14, 45)
|
112
|
+
)
|
113
|
+
assert_equal(
|
114
|
+
'2010-04-26T20:14:45',
|
115
|
+
@f.get,
|
116
|
+
'Timestamp#get should return proper string'
|
117
|
+
)
|
118
|
+
assert_equal(
|
119
|
+
'2010-04-25T00:00:00',
|
120
|
+
@f.get(:action => :created),
|
121
|
+
'Timestamp#get should return proper string'
|
122
|
+
)
|
123
|
+
assert_equal(
|
124
|
+
'2010-04-27T00:00:00',
|
125
|
+
@f.get(:action => :updated),
|
126
|
+
'Timestamp#get should return proper string'
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_get_rfc2822
|
131
|
+
@f.load(
|
132
|
+
'created' => Time.local(2010, 4, 25),
|
133
|
+
'updated' => Time.local(2010, 4, 27),
|
134
|
+
'published' => Time.local(2010, 4, 26, 20, 14, 45)
|
135
|
+
)
|
136
|
+
assert_match(
|
137
|
+
/^Mon, 26 Apr 2010 20:14:45 [\+\-]\d{4}$/,
|
138
|
+
@f.get(:action => :rfc2822),
|
139
|
+
'Timestamp#get should return proper string'
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_get_create
|
144
|
+
@f.load_default
|
145
|
+
|
146
|
+
@f[:can_edit] = nil
|
147
|
+
@f[:can_update] = nil
|
148
|
+
assert_nil(
|
149
|
+
@f.get(:action => :create),
|
150
|
+
'Timestamp#_g_create should return nil unless [:can_edit]'
|
151
|
+
)
|
152
|
+
|
153
|
+
@f[:can_edit] = true
|
154
|
+
@f[:can_update] = nil
|
155
|
+
assert_equal(
|
156
|
+
'<span class="meta-timestamp"><input type="text" name="" value="" size="16" /></span>',
|
157
|
+
@f.get(:action => :create),
|
158
|
+
'Timestamp#_g_create should return proper string'
|
159
|
+
)
|
160
|
+
|
161
|
+
@f[:can_edit] = nil
|
162
|
+
@f[:can_update] = true
|
163
|
+
assert_nil(
|
164
|
+
@f.get(:action => :create),
|
165
|
+
'Timestamp#_g_create should return nil if [:can_update]'
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_get_update
|
170
|
+
@f.load_default
|
171
|
+
|
172
|
+
@f[:can_edit] = nil
|
173
|
+
@f[:can_update] = nil
|
174
|
+
assert_nil(
|
175
|
+
@f.get(:action => :update),
|
176
|
+
'Timestamp#_g_update should return nil unless [:can_edit] or [:can_update]'
|
177
|
+
)
|
178
|
+
|
179
|
+
@f[:can_edit] = true
|
180
|
+
@f[:can_update] = nil
|
181
|
+
assert_equal(
|
182
|
+
'<span class="meta-timestamp"><input type="text" name="" value="" size="16" /></span>',
|
183
|
+
@f.get(:action => :update),
|
184
|
+
'Timestamp#_g_update should return proper string'
|
185
|
+
)
|
186
|
+
|
187
|
+
@f[:can_edit] = nil
|
188
|
+
@f[:can_update] = true
|
189
|
+
assert_equal(
|
190
|
+
<<'_html',
|
191
|
+
<span class="meta-timestamp">
|
192
|
+
<input type="checkbox" id="timestamp_" name="" value="true" />
|
193
|
+
<label for="timestamp_">update the timestamp</label>
|
194
|
+
</span>
|
195
|
+
_html
|
196
|
+
@f.get(:action => :update),
|
197
|
+
'Timestamp#_g_update should return proper string'
|
198
|
+
)
|
199
|
+
|
200
|
+
@f[:can_edit] = true
|
201
|
+
@f[:can_update] = nil
|
202
|
+
@f.load('published' => Time.local(2010, 4, 25))
|
203
|
+
assert_equal(
|
204
|
+
'<span class="meta-timestamp"><input type="text" name="" value="2010-04-25 00:00:00" size="16" /></span>',
|
205
|
+
@f.get(:action => :update),
|
206
|
+
'Timestamp#_g_update should return proper string'
|
207
|
+
)
|
208
|
+
@f.update '2010-4-89'
|
209
|
+
assert_equal(
|
210
|
+
<<'_html'.chomp,
|
211
|
+
<span class="meta-timestamp error"><input type="text" name="" value="2010-4-89" size="16" /><span class="error_message">out of range</span>
|
212
|
+
</span>
|
213
|
+
_html
|
214
|
+
@f.get(:action => :update),
|
215
|
+
'Timestamp#_g_update should return proper string'
|
216
|
+
)
|
217
|
+
|
218
|
+
@f.update '<2010-4-9>'
|
219
|
+
assert_equal(
|
220
|
+
<<'_html'.chomp,
|
221
|
+
<span class="meta-timestamp error"><input type="text" name="" value="<2010-4-9>" size="16" /><span class="error_message">wrong format</span>
|
222
|
+
</span>
|
223
|
+
_html
|
224
|
+
@f.get(:action => :update),
|
225
|
+
'Timestamp#_g_update should escape the special chars'
|
226
|
+
)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_errors
|
230
|
+
@f.load nil
|
231
|
+
assert_equal(
|
232
|
+
[],
|
233
|
+
@f.errors,
|
234
|
+
'Timestamp#errors should return the errors of the current val'
|
235
|
+
)
|
236
|
+
@f.load ''
|
237
|
+
assert_equal(
|
238
|
+
[],
|
239
|
+
@f.errors,
|
240
|
+
'Timestamp#errors should return the errors of the current val'
|
241
|
+
)
|
242
|
+
@f.load '2010-4-26 20:14:45'
|
243
|
+
assert_equal(
|
244
|
+
[],
|
245
|
+
@f.errors,
|
246
|
+
'Timestamp#errors should return the errors of the current val'
|
247
|
+
)
|
248
|
+
|
249
|
+
@f.load 'someday'
|
250
|
+
assert_equal(
|
251
|
+
['wrong format'],
|
252
|
+
@f.errors,
|
253
|
+
'Timestamp#errors should return the errors of the current val'
|
254
|
+
)
|
255
|
+
@f.load '2010-4-89'
|
256
|
+
assert_equal(
|
257
|
+
['out of range'],
|
258
|
+
@f.errors,
|
259
|
+
'Timestamp#errors should return the errors of the current val'
|
260
|
+
)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_load
|
264
|
+
@f.load(
|
265
|
+
'created' => Time.local(2010, 4, 1),
|
266
|
+
'updated' => Time.local(2010, 4, 3),
|
267
|
+
'published' => Time.local(2010, 4, 2)
|
268
|
+
)
|
269
|
+
assert_equal(
|
270
|
+
{
|
271
|
+
'created' => Time.local(2010, 4, 1),
|
272
|
+
'updated' => Time.local(2010, 4, 3),
|
273
|
+
'published' => Time.local(2010, 4, 2)
|
274
|
+
},
|
275
|
+
@f.val,
|
276
|
+
'Timestamp#load should load the given val like a normal field'
|
277
|
+
)
|
278
|
+
assert_nil(
|
279
|
+
@f.action,
|
280
|
+
'Timestamp#load should not set @action'
|
281
|
+
)
|
282
|
+
assert_equal(
|
283
|
+
:load,
|
284
|
+
@f.result,
|
285
|
+
'Timestamp#load should set @result like a normal field'
|
286
|
+
)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_create
|
290
|
+
@f.create nil
|
291
|
+
assert_equal(
|
292
|
+
@f.val['updated'],
|
293
|
+
@f.val['created'],
|
294
|
+
'Timestamp#create should set the default vals'
|
295
|
+
)
|
296
|
+
assert_equal(
|
297
|
+
@f.val['published'],
|
298
|
+
@f.val['created'],
|
299
|
+
'Timestamp#create should set the default vals'
|
300
|
+
)
|
301
|
+
assert_nil(
|
302
|
+
@f.action,
|
303
|
+
"Timestamp#create should not set @action without v['published']"
|
304
|
+
)
|
305
|
+
assert_nil(
|
306
|
+
@f.result,
|
307
|
+
'Timestamp#create should not set @result'
|
308
|
+
)
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_create_with_date
|
312
|
+
@f[:can_edit] = true
|
313
|
+
@f.create '2010/4/26'
|
314
|
+
assert_equal(
|
315
|
+
@f.val['updated'],
|
316
|
+
@f.val['created'],
|
317
|
+
'Timestamp#create should set the default vals'
|
318
|
+
)
|
319
|
+
assert_equal(
|
320
|
+
Time.local(2010, 4, 26),
|
321
|
+
@f.val['published'],
|
322
|
+
"Timestamp#create should set @val['published'] if v['published'] is a date"
|
323
|
+
)
|
324
|
+
assert_equal(
|
325
|
+
:create,
|
326
|
+
@f.action,
|
327
|
+
"Timestamp#create should set @action if v['published'] is a date"
|
328
|
+
)
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_create_with_check
|
332
|
+
@f[:can_update] = true
|
333
|
+
@f.create 'true'
|
334
|
+
assert_equal(
|
335
|
+
@f.val['updated'],
|
336
|
+
@f.val['created'],
|
337
|
+
'Timestamp#create should set the default vals'
|
338
|
+
)
|
339
|
+
assert_equal(
|
340
|
+
@f.val['published'],
|
341
|
+
@f.val['created'],
|
342
|
+
'Timestamp#create should set the default vals'
|
343
|
+
)
|
344
|
+
assert_nil(
|
345
|
+
@f.action,
|
346
|
+
"Timestamp#create should not set @action if v['published'] is not a date"
|
347
|
+
)
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_update
|
351
|
+
@f.load(
|
352
|
+
'created' => Time.local(2010, 4, 1),
|
353
|
+
'updated' => Time.local(2010, 4, 3),
|
354
|
+
'published' => Time.local(2010, 4, 2)
|
355
|
+
)
|
356
|
+
|
357
|
+
@f.update nil
|
358
|
+
assert_equal(
|
359
|
+
Time.local(2010, 4, 1),
|
360
|
+
@f.val['created'],
|
361
|
+
"Timestamp#update should keep @val['created']"
|
362
|
+
)
|
363
|
+
assert_not_equal(
|
364
|
+
Time.local(2010, 4, 3),
|
365
|
+
@f.val['updated'],
|
366
|
+
"Timestamp#update should updated @val['updated']"
|
367
|
+
)
|
368
|
+
assert_equal(
|
369
|
+
Time.local(2010, 4, 2),
|
370
|
+
@f.val['published'],
|
371
|
+
"Timestamp#update should keep @val['published']"
|
372
|
+
)
|
373
|
+
assert_nil(
|
374
|
+
@f.action,
|
375
|
+
"Timestamp#update should not set @action without v['published']"
|
376
|
+
)
|
377
|
+
assert_nil(
|
378
|
+
@f.result,
|
379
|
+
'Timestamp#update should not set @result'
|
380
|
+
)
|
381
|
+
end
|
382
|
+
|
383
|
+
def test_update_with_date
|
384
|
+
@f[:can_edit] = true
|
385
|
+
@f.load(
|
386
|
+
'created' => Time.local(2010, 4, 1),
|
387
|
+
'updated' => Time.local(2010, 4, 3),
|
388
|
+
'published' => Time.local(2010, 4, 2)
|
389
|
+
)
|
390
|
+
|
391
|
+
@f.update '2010/4/26'
|
392
|
+
assert_equal(
|
393
|
+
Time.local(2010, 4, 1),
|
394
|
+
@f.val['created'],
|
395
|
+
"Timestamp#update should keep @val['created']"
|
396
|
+
)
|
397
|
+
assert_not_equal(
|
398
|
+
Time.local(2010, 4, 3),
|
399
|
+
@f.val['updated'],
|
400
|
+
"Timestamp#update should updated @val['updated']"
|
401
|
+
)
|
402
|
+
assert_equal(
|
403
|
+
Time.local(2010, 4, 26),
|
404
|
+
@f.val['published'],
|
405
|
+
"Timestamp#update should set @val['published'] if v['published'] is a date"
|
406
|
+
)
|
407
|
+
assert_equal(
|
408
|
+
:update,
|
409
|
+
@f.action,
|
410
|
+
"Timestamp#update should set @action if v['published'] is a date"
|
411
|
+
)
|
412
|
+
assert_nil(
|
413
|
+
@f.result,
|
414
|
+
'Timestamp#update should not set @result'
|
415
|
+
)
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_update_can_not_edit
|
419
|
+
@f[:can_edit] = false
|
420
|
+
@f.load(
|
421
|
+
'created' => Time.local(2010, 4, 1),
|
422
|
+
'updated' => Time.local(2010, 4, 3),
|
423
|
+
'published' => Time.local(2010, 4, 2)
|
424
|
+
)
|
425
|
+
|
426
|
+
@f.update '2010/4/26'
|
427
|
+
assert_equal(
|
428
|
+
Time.local(2010, 4, 2),
|
429
|
+
@f.val['published'],
|
430
|
+
"Timestamp#update should not set @val['published'] unless my[:can_edit]"
|
431
|
+
)
|
432
|
+
assert_nil(
|
433
|
+
@f.action,
|
434
|
+
"Timestamp#update should not set @action unless my[:can_edit]"
|
435
|
+
)
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_update_with_check
|
439
|
+
@f[:can_update] = true
|
440
|
+
@f.load(
|
441
|
+
'created' => Time.local(2010, 4, 1),
|
442
|
+
'updated' => Time.local(2010, 4, 3),
|
443
|
+
'published' => Time.local(2010, 4, 2)
|
444
|
+
)
|
445
|
+
|
446
|
+
@f.update 'true'
|
447
|
+
assert_equal(
|
448
|
+
Time.local(2010, 4, 1),
|
449
|
+
@f.val['created'],
|
450
|
+
"Timestamp#update should keep @val['created']"
|
451
|
+
)
|
452
|
+
assert_not_equal(
|
453
|
+
Time.local(2010, 4, 3),
|
454
|
+
@f.val['updated'],
|
455
|
+
"Timestamp#update should updated @val['updated']"
|
456
|
+
)
|
457
|
+
assert_equal(
|
458
|
+
@f.val['updated'],
|
459
|
+
@f.val['published'],
|
460
|
+
"Timestamp#update should updated @val['published'] if v['published'] is :same_as_updated"
|
461
|
+
)
|
462
|
+
assert_equal(
|
463
|
+
:update,
|
464
|
+
@f.action,
|
465
|
+
"Timestamp#update should set @action if v['published'] is :same_as_updated"
|
466
|
+
)
|
467
|
+
assert_nil(
|
468
|
+
@f.result,
|
469
|
+
'Timestamp#update should not set @result'
|
470
|
+
)
|
471
|
+
end
|
472
|
+
|
473
|
+
end
|