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
@@ -0,0 +1,188 @@
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_Password < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @f = Runo::Field.instance(
12
+ :klass => 'password',
13
+ :default => 'secret',
14
+ :size => 16
15
+ )
16
+ end
17
+
18
+ def teardown
19
+ end
20
+
21
+ def test_get
22
+ @f.instance_variable_set(:@val, 'hello')
23
+
24
+ assert_equal(
25
+ '*****',
26
+ @f.get(:action => :read),
27
+ 'Password#get should not return anything other than a dummy string'
28
+ )
29
+ assert_equal(
30
+ <<'_html'.chomp,
31
+ <span class="password"><input type="password" name="" value="" size="16" /></span>
32
+ _html
33
+ @f.get(:action => :create),
34
+ 'Password#get(:action => :create) should return an empty form'
35
+ )
36
+
37
+ @f.update 'abcdefg'
38
+ assert_equal(
39
+ '*******',
40
+ @f.get(:action => :read),
41
+ 'Password#get should refer to @size as a length of the dummy string'
42
+ )
43
+ assert_equal(
44
+ <<'_html'.chomp,
45
+ <span class="password"><input type="password" name="" value="" size="16" /></span>
46
+ _html
47
+ @f.get(:action => :update),
48
+ 'Password#get(:action => :update) should return an empty form'
49
+ )
50
+ end
51
+
52
+ def test_load_default
53
+ @f.load_default
54
+ assert_nil(
55
+ @f.val,
56
+ 'Password#load_default should not load any value'
57
+ )
58
+ end
59
+
60
+ def test_load
61
+ @f.load 'foobar'
62
+ assert_equal(
63
+ 'foobar',
64
+ @f.val,
65
+ 'Password#load should not alter the loaded value'
66
+ )
67
+ end
68
+
69
+ def test_create
70
+ @f.create 'foobar'
71
+ assert_not_equal(
72
+ 'foobar',
73
+ @f.val,
74
+ 'Password#create should store the value as a crypted string'
75
+ )
76
+ end
77
+
78
+ def test_create_empty
79
+ @f.create nil
80
+ assert_equal(
81
+ :create,
82
+ @f.action,
83
+ 'Password#create should set @action even if the val is empty'
84
+ )
85
+ end
86
+
87
+ def test_update
88
+ @f.load 'original'
89
+
90
+ @f.update nil
91
+ assert_equal(
92
+ 'original',
93
+ @f.val,
94
+ 'Password#update should not update with nil'
95
+ )
96
+
97
+ @f.update ''
98
+ assert_equal(
99
+ 'original',
100
+ @f.val,
101
+ 'Password#update should not update with an empty string'
102
+ )
103
+
104
+ @f.update 'updated'
105
+ assert_not_equal(
106
+ 'original',
107
+ @f.val,
108
+ 'Password#update should update with a non-empty string'
109
+ )
110
+ assert_not_equal(
111
+ 'updated',
112
+ @f.val,
113
+ 'Password#update should store the value as a crypted string'
114
+ )
115
+ end
116
+
117
+ def test_errors_on_load
118
+ Runo.client = 'root'
119
+
120
+ @f[:min] = 1
121
+ @f.load ''
122
+ assert_equal(
123
+ [],
124
+ @f.errors,
125
+ 'Password#errors should not return the errors of a loaded val'
126
+ )
127
+ end
128
+
129
+ def test_errors
130
+ @f.create nil
131
+ @f[:min] = 1
132
+ assert_equal(
133
+ ['mandatory'],
134
+ @f.errors,
135
+ 'Password#errors should return the errors of the current val'
136
+ )
137
+
138
+ @f.create nil
139
+ assert_equal(
140
+ ['mandatory'],
141
+ @f.errors,
142
+ 'Password#errors should keep the errors of the previous non-empty update'
143
+ )
144
+
145
+ @f.create 'a'
146
+ @f[:min] = 1
147
+ assert_equal(
148
+ [],
149
+ @f.errors,
150
+ 'Password#errors should return the errors of the current val'
151
+ )
152
+ @f[:min] = 2
153
+ assert_equal(
154
+ ['too short: 2 characters minimum'],
155
+ @f.errors,
156
+ 'Password#errors should return the errors of the current val'
157
+ )
158
+
159
+ @f.update 'abcde'
160
+ @f[:max] = 5
161
+ assert_equal(
162
+ [],
163
+ @f.errors,
164
+ 'Password#errors should return the errors of the current val'
165
+ )
166
+ @f[:max] = 4
167
+ assert_equal(
168
+ ['too long: 4 characters maximum'],
169
+ @f.errors,
170
+ 'Password#errors should return the errors of the current val'
171
+ )
172
+
173
+ @f.update nil
174
+ assert_equal(
175
+ ['too long: 4 characters maximum'],
176
+ @f.errors,
177
+ 'Password#errors should keep the errors of the previous non-empty update'
178
+ )
179
+
180
+ @f.update 'abc'
181
+ assert_equal(
182
+ [],
183
+ @f.errors,
184
+ 'Password#errors should return the errors of the current val'
185
+ )
186
+ end
187
+
188
+ end
@@ -0,0 +1,226 @@
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_Radio < Test::Unit::TestCase
9
+
10
+ def setup
11
+ meta = nil
12
+ Runo::Parser.gsub_scalar("$(foo radio 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
+ 'Radio#initialize should set :options from the csv token'
27
+ )
28
+ assert_equal(
29
+ true,
30
+ @f[:mandatory],
31
+ 'Radio#initialize should set :mandatory from the misc token'
32
+ )
33
+ assert_equal(
34
+ 'baz',
35
+ @f[:default],
36
+ 'Radio#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 radio 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
+ 'Radio#initialize should set :options from the range token'
51
+ )
52
+
53
+ meta = nil
54
+ Runo::Parser.gsub_scalar("$(foo radio ..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
+ 'Radio#initialize should set :options from the range token'
63
+ )
64
+
65
+ meta = nil
66
+ Runo::Parser.gsub_scalar("$(foo radio 1..)") {|id, m|
67
+ meta = m
68
+ ''
69
+ }
70
+ f = Runo::Field.instance meta
71
+ assert_equal(
72
+ nil,
73
+ f[:options],
74
+ 'Radio#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
+ 'Radio#val_cast should cast the given val to String'
83
+ )
84
+
85
+ @f.load 123
86
+ assert_equal(
87
+ '123',
88
+ @f.val,
89
+ 'Radio#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
+ 'Radio#get should return proper string'
99
+ )
100
+ assert_equal(
101
+ <<_html,
102
+ <span class="radio">
103
+ <input type="hidden" name="" value="" />
104
+ <span class="item">
105
+ <input type="radio" id="radio_-bar" name="" value="bar" />
106
+ <label for="radio_-bar">bar</label>
107
+ </span>
108
+ <span class="item">
109
+ <input type="radio" id="radio_-baz" name="" value="baz" />
110
+ <label for="radio_-baz">baz</label>
111
+ </span>
112
+ <span class="item">
113
+ <input type="radio" id="radio_-qux" name="" value="qux" />
114
+ <label for="radio_-qux">qux</label>
115
+ </span>
116
+ </span>
117
+ _html
118
+ @f.get(:action => :create),
119
+ 'Radio#get should return proper string'
120
+ )
121
+
122
+ @f.load 'qux'
123
+ assert_equal(
124
+ 'qux',
125
+ @f.get,
126
+ 'Radio#get should return proper string'
127
+ )
128
+ assert_equal(
129
+ <<_html,
130
+ <span class="radio">
131
+ <input type="hidden" name="" value="" />
132
+ <span class="item">
133
+ <input type="radio" id="radio_-bar" name="" value="bar" />
134
+ <label for="radio_-bar">bar</label>
135
+ </span>
136
+ <span class="item">
137
+ <input type="radio" id="radio_-baz" name="" value="baz" />
138
+ <label for="radio_-baz">baz</label>
139
+ </span>
140
+ <span class="item">
141
+ <input type="radio" id="radio_-qux" name="" value="qux" checked />
142
+ <label for="radio_-qux">qux</label>
143
+ </span>
144
+ </span>
145
+ _html
146
+ @f.get(:action => :update),
147
+ 'Radio#get should return proper string'
148
+ )
149
+
150
+ @f.load 'non-exist'
151
+ assert_equal(
152
+ <<_html,
153
+ <span class="radio error">
154
+ <input type="hidden" name="" value="" />
155
+ <span class="item">
156
+ <input type="radio" id="radio_-bar" name="" value="bar" />
157
+ <label for="radio_-bar">bar</label>
158
+ </span>
159
+ <span class="item">
160
+ <input type="radio" id="radio_-baz" name="" value="baz" />
161
+ <label for="radio_-baz">baz</label>
162
+ </span>
163
+ <span class="item">
164
+ <input type="radio" id="radio_-qux" name="" value="qux" />
165
+ <label for="radio_-qux">qux</label>
166
+ </span>
167
+ <span class=\"error_message\">no such option</span>
168
+ </span>
169
+ _html
170
+ @f.get(:action => :update),
171
+ 'Radio#get should return proper string'
172
+ )
173
+ end
174
+
175
+ def test_get_escape
176
+ @f[:options] = ['foo', '<bar>']
177
+ @f.load '<bar>'
178
+ assert_equal(
179
+ '&lt;bar&gt;',
180
+ @f.get,
181
+ 'Radio#get should escape the special characters'
182
+ )
183
+ assert_equal(
184
+ <<_html,
185
+ <span class="radio">
186
+ <input type="hidden" name="" value="" />
187
+ <span class="item">
188
+ <input type="radio" id="radio_-foo" name="" value="foo" />
189
+ <label for="radio_-foo">foo</label>
190
+ </span>
191
+ <span class="item">
192
+ <input type="radio" id="radio_-&lt;bar&gt;" name="" value="&lt;bar&gt;" checked />
193
+ <label for="radio_-&lt;bar&gt;">&lt;bar&gt;</label>
194
+ </span>
195
+ </span>
196
+ _html
197
+ @f.get(:action => :update),
198
+ 'Radio#get should escape the special characters'
199
+ )
200
+ end
201
+
202
+ def test_errors
203
+ @f.load ''
204
+ @f[:mandatory] = nil
205
+ assert_equal(
206
+ [],
207
+ @f.errors,
208
+ 'Radio#errors should return the errors of the current val'
209
+ )
210
+ @f[:mandatory] = true
211
+ assert_equal(
212
+ ['mandatory'],
213
+ @f.errors,
214
+ 'Radio#errors should return the errors of the current val'
215
+ )
216
+
217
+ @f.load 'non-exist'
218
+ @f[:mandatory] = nil
219
+ assert_equal(
220
+ ['no such option'],
221
+ @f.errors,
222
+ 'Radio#errors should return the errors of the current val'
223
+ )
224
+ end
225
+
226
+ end
@@ -0,0 +1,249 @@
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_Role < Test::Unit::TestCase
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_owner
17
+ assert_equal(
18
+ 'root',
19
+ Runo::Set::Static::Folder.root[:owner],
20
+ "Field#[:owner] should return 'root' for the root folder"
21
+ )
22
+
23
+ assert_equal(
24
+ 'frank',
25
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:owner],
26
+ 'Field#[:owner] should return @meta[:owner] if available'
27
+ )
28
+ assert_equal(
29
+ 'frank',
30
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001', 'replies')[:owner],
31
+ 'Field#[:owner] should return parent[:owner] if @meta[:owner] is nil'
32
+ )
33
+ assert_equal(
34
+ 'carl',
35
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001', 'replies', '20091201_0001')[:owner],
36
+ 'Field#[:owner] should return @meta[:owner] if available'
37
+ )
38
+
39
+ assert_equal(
40
+ 'root',
41
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:owner],
42
+ 'Field#[:owner] should return parent[:owner] if @meta[:owner] is nil'
43
+ )
44
+ assert_equal(
45
+ 'root',
46
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')[:owner],
47
+ 'Field#[:owner] should return parent[:owner] if @meta[:owner] is nil'
48
+ )
49
+ assert_equal(
50
+ 'carl',
51
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main', '20091120_0001')[:owner],
52
+ 'Field#[:owner] should return @meta[:owner] if available'
53
+ )
54
+ assert_equal(
55
+ 'carl',
56
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main', '20091120_0001', 'name')[:owner],
57
+ 'Field#[:owner] should return parent[:owner] if @meta[:owner] is nil'
58
+ )
59
+ end
60
+
61
+ def test_owners
62
+ assert_equal(
63
+ ['root'],
64
+ Runo::Set::Static::Folder.root[:owners],
65
+ "Field#[:owners] should return ['root'] for the root folder"
66
+ )
67
+ assert_equal(
68
+ ['root'],
69
+ Runo::Set::Static::Folder.root.item('foo')[:owners],
70
+ 'Field#[:owners] should return all the owners of the ancestor fields'
71
+ )
72
+ assert_equal(
73
+ ['root'],
74
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')[:owners],
75
+ 'Field#[:owners] should return all the owners of the ancestor fields'
76
+ )
77
+ assert_equal(
78
+ ['root', 'carl'],
79
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main', '20091120_0001')[:owners],
80
+ 'Field#[:owners] should return all the owners of the ancestor fields'
81
+ )
82
+ end
83
+
84
+ def test_admins
85
+ assert_equal(
86
+ ['root'],
87
+ Runo::Set::Static::Folder.root[:admins],
88
+ "Field#[:admins] should return ['root'] for the root folder"
89
+ )
90
+ assert_equal(
91
+ ['root', 'frank'],
92
+ Runo::Set::Static::Folder.root.item('foo')[:admins],
93
+ 'Field#[:admins] should include @meta[:admin] if available'
94
+ )
95
+ assert_equal(
96
+ ['root', 'frank'],
97
+ Runo::Set::Static::Folder.root.item('foo', 'main')[:admins],
98
+ 'Field#[:admins] should return parent[:admins] if @meta[:admin] is nil'
99
+ )
100
+ assert_equal(
101
+ ['root', 'frank'],
102
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:admins],
103
+ 'Field#[:admins] should return parent[:admins] if @meta[:admin] is nil'
104
+ )
105
+
106
+ assert_equal(
107
+ ['root', 'frank'],
108
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:admins],
109
+ 'Field#[:admins] should return parent[:admins] if @meta[:admin] is nil'
110
+ )
111
+ assert_equal(
112
+ ['root', 'frank'],
113
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')[:admins],
114
+ 'Field#[:admins] should return parent[:admins] if @meta[:admin] is nil'
115
+ )
116
+ assert_equal(
117
+ ['root', 'frank'],
118
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main', '20091120_0001')[:admins],
119
+ 'Field#[:admins] should return @meta[:admins] if available'
120
+ )
121
+ assert_equal(
122
+ ['root', 'frank'],
123
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main', '20091120_0001', 'name')[:admins],
124
+ 'Field#[:admins] should return @meta[:admins] if available'
125
+ )
126
+ end
127
+
128
+ def test_group
129
+ assert_equal(
130
+ [],
131
+ Runo::Set::Static::Folder.root[:group],
132
+ "Field#[:group] should return [] for the root folder"
133
+ )
134
+ assert_equal(
135
+ ['roy', 'jim'],
136
+ Runo::Set::Static::Folder.root.item('foo')[:group],
137
+ 'Field#[:group] should return @meta[:group] if available'
138
+ )
139
+ assert_equal(
140
+ ['roy', 'jim'],
141
+ Runo::Set::Static::Folder.root.item('foo', 'main')[:group],
142
+ 'Field#[:group] should return @meta[:group] of the nearest folder'
143
+ )
144
+ assert_equal(
145
+ ['roy', 'jim'],
146
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:group],
147
+ 'Field#[:group] should return @meta[:group] of the nearest folder'
148
+ )
149
+
150
+ assert_equal(
151
+ ['carl', 'don'],
152
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:group],
153
+ 'Field#[:group] should return @meta[:group] if available'
154
+ )
155
+ assert_equal(
156
+ ['carl', 'don'],
157
+ Runo::Set::Static::Folder.root.item('foo', 'bar', 'main')[:group],
158
+ 'Field#[:group] should return @meta[:group] of the nearest folder'
159
+ )
160
+ end
161
+
162
+ def test_roles_of_nobody
163
+ Runo.client = nil
164
+ assert_equal(
165
+ 0b00001,
166
+ Runo::Set::Static::Folder.root[:roles],
167
+ 'Field#[:roles] should return the roles of the client on the field'
168
+ )
169
+ assert_equal(
170
+ 0b00001,
171
+ Runo::Set::Static::Folder.root.item('foo')[:roles],
172
+ 'Field#[:roles] should return the roles of the client on the field'
173
+ )
174
+ assert_equal(
175
+ 0b00001,
176
+ Runo::Set::Static::Folder.root.item('foo', 'main')[:roles],
177
+ 'Field#[:roles] should return the roles of the client on the field'
178
+ )
179
+ assert_equal(
180
+ 0b00001,
181
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:roles],
182
+ 'Field#[:roles] should return the roles of the client on the field'
183
+ )
184
+ assert_equal(
185
+ 0b00001,
186
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:roles],
187
+ 'Field#[:roles] should return the roles of the client on the field'
188
+ )
189
+ end
190
+
191
+ def test_roles_of_frank
192
+ Runo.client = 'frank'
193
+ assert_equal(
194
+ 0b00010,
195
+ Runo::Set::Static::Folder.root[:roles],
196
+ 'Field#[:roles] should return the roles of the client on the field'
197
+ )
198
+ assert_equal(
199
+ 0b10010,
200
+ Runo::Set::Static::Folder.root.item('foo')[:roles],
201
+ 'Field#[:roles] should return the roles of the client on the field'
202
+ )
203
+ assert_equal(
204
+ 0b10010,
205
+ Runo::Set::Static::Folder.root.item('foo', 'main')[:roles],
206
+ 'Field#[:roles] should return the roles of the client on the field'
207
+ )
208
+ assert_equal(
209
+ 0b10110,
210
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:roles],
211
+ 'Field#[:roles] should return the roles of the client on the field'
212
+ )
213
+ assert_equal(
214
+ 0b10010,
215
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:roles],
216
+ 'Field#[:roles] should return the roles of the client on the field'
217
+ )
218
+ end
219
+
220
+ def test_roles_of_roy
221
+ Runo.client = 'roy'
222
+ assert_equal(
223
+ 0b00010,
224
+ Runo::Set::Static::Folder.root[:roles],
225
+ 'Field#[:roles] should return the roles of the client on the field'
226
+ )
227
+ assert_equal(
228
+ 0b01010,
229
+ Runo::Set::Static::Folder.root.item('foo')[:roles],
230
+ 'Field#[:roles] should return the roles of the client on the field'
231
+ )
232
+ assert_equal(
233
+ 0b01010,
234
+ Runo::Set::Static::Folder.root.item('foo', 'main')[:roles],
235
+ 'Field#[:roles] should return the roles of the client on the field'
236
+ )
237
+ assert_equal(
238
+ 0b01010,
239
+ Runo::Set::Static::Folder.root.item('foo', 'main', '20091120_0001')[:roles],
240
+ 'Field#[:roles] should return the roles of the client on the field'
241
+ )
242
+ assert_equal(
243
+ 0b00010,
244
+ Runo::Set::Static::Folder.root.item('foo', 'bar')[:roles],
245
+ 'Field#[:roles] should return the roles of the client on the field'
246
+ )
247
+ end
248
+
249
+ end