ramaze 2010.06.18 → 2011.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +1 -0
  2. data/MANIFEST +9 -16
  3. data/README.md +37 -30
  4. data/Rakefile +5 -1
  5. data/TODO.md +19 -0
  6. data/doc/AUTHORS +5 -1
  7. data/doc/CHANGELOG +3553 -3272
  8. data/doc/tutorial/todolist.html +1512 -1512
  9. data/examples/app/blog/app.rb +2 -0
  10. data/examples/app/todolist/controller/init.rb +1 -2
  11. data/examples/app/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -1
  12. data/examples/app/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +1 -1
  13. data/examples/app/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +1 -1
  14. data/examples/app/wiktacular/mkd/main/current.mkd +1 -1
  15. data/examples/app/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +1 -1
  16. data/examples/app/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +2 -2
  17. data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +16 -16
  18. data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +16 -16
  19. data/examples/app/wiktacular/mkd/testing/current.mkd +16 -16
  20. data/lib/proto/model/init.rb +1 -1
  21. data/lib/proto/public/js/jquery.js +2034 -1095
  22. data/lib/proto/start.rb +2 -0
  23. data/lib/proto/view/index.xhtml +3 -3
  24. data/lib/ramaze.rb +1 -2
  25. data/lib/ramaze/cache.rb +1 -0
  26. data/lib/ramaze/cache/sequel.rb +131 -37
  27. data/lib/ramaze/controller.rb +1 -0
  28. data/lib/ramaze/gestalt.rb +75 -46
  29. data/lib/ramaze/helper.rb +1 -0
  30. data/lib/ramaze/helper/auth.rb +38 -4
  31. data/lib/ramaze/helper/blue_form.rb +498 -78
  32. data/lib/ramaze/helper/cache.rb +2 -2
  33. data/lib/ramaze/helper/csrf.rb +225 -0
  34. data/lib/ramaze/helper/erector.rb +67 -9
  35. data/lib/ramaze/helper/flash.rb +4 -2
  36. data/lib/ramaze/helper/gestalt.rb +2 -0
  37. data/lib/ramaze/helper/gravatar.rb +1 -1
  38. data/lib/ramaze/helper/localize.rb +4 -0
  39. data/lib/ramaze/helper/send_file.rb +30 -0
  40. data/lib/ramaze/helper/thread.rb +5 -0
  41. data/lib/ramaze/helper/user.rb +4 -3
  42. data/lib/ramaze/helper/xhtml.rb +87 -8
  43. data/lib/ramaze/log.rb +13 -0
  44. data/lib/ramaze/log/analogger.rb +15 -5
  45. data/lib/ramaze/log/growl.rb +28 -13
  46. data/lib/ramaze/log/hub.rb +12 -4
  47. data/lib/ramaze/log/informer.rb +28 -11
  48. data/lib/ramaze/log/knotify.rb +7 -2
  49. data/lib/ramaze/log/logger.rb +12 -4
  50. data/lib/ramaze/log/logging.rb +40 -14
  51. data/lib/ramaze/log/rotatinginformer.rb +47 -23
  52. data/lib/ramaze/log/syslog.rb +37 -31
  53. data/lib/ramaze/log/xosd.rb +7 -4
  54. data/lib/ramaze/middleware_compiler.rb +2 -2
  55. data/lib/ramaze/snippets/fiber.rb +63 -63
  56. data/lib/ramaze/snippets/ramaze/lru_hash.rb +1 -1
  57. data/lib/ramaze/tool/bin.rb +1 -1
  58. data/lib/ramaze/version.rb +1 -1
  59. data/lib/ramaze/view.rb +4 -4
  60. data/lib/ramaze/view/erector.rb +88 -13
  61. data/ramaze.gemspec +65 -65
  62. data/spec/ramaze/bin/ramaze.rb +1 -1
  63. data/spec/ramaze/cache/localmemcache.rb +20 -12
  64. data/spec/ramaze/cache/sequel.rb +19 -19
  65. data/spec/ramaze/helper/blue_form.rb +549 -257
  66. data/spec/ramaze/helper/csrf.rb +109 -0
  67. data/spec/ramaze/helper/httpdigest.rb +31 -29
  68. data/spec/ramaze/helper/user.rb +1 -1
  69. data/spec/ramaze/helper/xhtml.rb +17 -0
  70. data/spec/ramaze/log/growl.rb +34 -0
  71. data/spec/ramaze/log/informer.rb +1 -0
  72. data/spec/ramaze/view/erector.rb +49 -71
  73. data/spec/ramaze/view/erector/external_view.erector +5 -0
  74. data/spec/ramaze/view/erector/index.erector +5 -0
  75. data/spec/ramaze/view/erector/layout.erector +13 -3
  76. data/spec/ramaze/view/erector/tables.erector +23 -0
  77. data/spec/ramaze/view/erector/view.erector +6 -0
  78. data/tasks/git.rake +2 -2
  79. metadata +133 -176
  80. data/examples/helpers/form_with_sequel.rb +0 -24
  81. data/examples/helpers/nitro_form.rb +0 -23
  82. data/lib/ramaze/helper/form.rb +0 -133
  83. data/lib/ramaze/helper/nitroform.rb +0 -14
  84. data/lib/ramaze/helper/pager.rb +0 -367
  85. data/lib/ramaze/helper/partial.rb +0 -100
  86. data/lib/ramaze/helper/sequel.rb +0 -55
  87. data/lib/ramaze/helper/sequel_form.rb +0 -284
  88. data/lib/vendor/etag.rb +0 -22
  89. data/spec/ramaze/helper/form.rb +0 -360
  90. data/spec/ramaze/helper/pager.rb +0 -96
  91. data/spec/ramaze/helper/sequel_form.rb +0 -94
  92. data/spec/ramaze/view/erector/external.erector +0 -1
  93. data/spec/ramaze/view/erector/invoke_helper_method.erector +0 -1
  94. data/spec/ramaze/view/erector/strict_xhtml.erector +0 -3
  95. data/spec/ramaze/view/erector/sum.erector +0 -1
@@ -5,69 +5,81 @@ Bacon.summary_at_exit
5
5
 
6
6
  describe BF = Ramaze::Helper::BlueForm do
7
7
  extend BF
8
-
9
- def tidy(html)
10
- require 'open3'
11
- Open3.popen3('tidy -i'){|sin, sout, serr|
12
- sin.print(html)
13
- sin.close
14
- sout.read[/<body>(.+)<\/body>/m, 1]
15
- }
16
- end
8
+
9
+ # Generate some dummy data
10
+ @data = Class.new do
11
+ attr_reader :username
12
+ attr_reader :password
13
+ attr_reader :assigned
14
+ attr_reader :assigned_hash
15
+ attr_reader :message
16
+ attr_reader :servers_hash
17
+ attr_reader :servers_array
18
+ attr_accessor :errors
19
+
20
+ def initialize
21
+ @username = 'mrfoo'
22
+ @password = 'super-secret-password'
23
+ @assigned = ['bacon', 'steak']
24
+ @assigned_hash= {'Bacon' => 'bacon', 'Steak' => 'steak'}
25
+ @message = 'Hello, textarea!'
26
+ @servers_hash = {
27
+ :webrick => 'WEBrick',
28
+ :mongrel => 'Mongrel',
29
+ :thin => 'Thin',
30
+ }
31
+ @servers_array = ['WEBrick', 'Mongrel', 'Thin']
32
+ end
33
+ end.new
17
34
 
18
35
  # very strange comparision, sort all characters and compare, so we don't have
19
36
  # order issues.
20
37
  def assert(expected, output)
21
- left = expected.to_s.gsub(/\s+/, ' ').gsub(/>\s+</, '><').strip
38
+ left = expected.to_s.gsub(/\s+/, ' ').gsub(/>\s+</, '><').strip
22
39
  right = output.to_s.gsub(/\s+/, ' ').gsub(/>\s+</, '><').strip
23
40
  left.scan(/./).sort.should == right.scan(/./).sort
24
- #
25
- # unless left == right
26
- # puts "", "Expected:"
27
- # puts left
28
- # puts tidy(left)
29
- # puts "", "Got:"
30
- # puts right
31
- # puts tidy(right)
32
- # puts
33
- # end
34
- # left.should == right
35
- end
36
-
37
- it 'makes form with method' do
38
- out = form(:method => :post)
41
+ end
42
+
43
+ # ------------------------------------------------
44
+ # Basic forms
45
+
46
+ it 'Make a basic form' do
47
+ out = form_for(@data, :method => :post)
39
48
  assert(<<-FORM, out)
40
49
  <form method="post"></form>
41
50
  FORM
42
51
  end
43
52
 
44
- it 'makes form with method and action' do
45
- out = form(:method => :post, :action => '/')
53
+ it 'Make a form with the method and action attributes specified' do
54
+ out = form_for(@data, :method => :post, :action => '/')
46
55
  assert(<<-FORM, out)
47
56
  <form method="post" action="/"></form>
48
57
  FORM
49
58
  end
50
59
 
51
- it 'makes form with method, action, and name' do
52
- out = form(:method => :post, :action => '/', :name => :spec)
60
+ it 'Make a form with a method, action and a name attribute' do
61
+ out = form_for(@data, :method => :post, :action => '/', :name => :spec)
53
62
  assert(<<-FORM, out)
54
63
  <form method="post" action="/" name="spec">
55
64
  </form>
56
65
  FORM
57
66
  end
58
67
 
59
- it 'makes form with class and id' do
60
- out = form(:class => :foo, :id => :bar)
68
+ it 'Make a form with a class and an ID' do
69
+ out = form_for(@data, :class => :foo, :id => :bar)
61
70
  assert(<<-FORM, out)
62
71
  <form class="foo" id="bar">
63
72
  </form>
64
73
  FORM
65
74
  end
66
75
 
67
- it 'makes form with legend' do
68
- out = form(:method => :get){|f|
69
- f.legend('The Form')
70
- }
76
+ it 'Make a form with a fieldset and a legend' do
77
+ out = form_for(@data, :method => :get) do |f|
78
+ f.g.fieldset do
79
+ f.legend('The Form')
80
+ end
81
+ end
82
+
71
83
  assert(<<-FORM, out)
72
84
  <form method="get">
73
85
  <fieldset>
@@ -76,358 +88,638 @@ describe BF = Ramaze::Helper::BlueForm do
76
88
  </form>
77
89
  FORM
78
90
  end
91
+
92
+ # ------------------------------------------------
93
+ # Text fields
79
94
 
80
- it 'makes form with input_text(label, name, value)' do
81
- out = form(:method => :get){|f|
82
- f.input_text 'Username', :username, 'mrfoo'
83
- }
95
+ it 'Make a form with input_text(label, value)' do
96
+ out = form_for(@data, :method => :get) do |f|
97
+ f.input_text 'Username', :username
98
+ end
99
+
84
100
  assert(<<-FORM, out)
85
101
  <form method="get">
86
- <fieldset>
87
- <p>
88
- <label for="form-username">Username</label>
89
- <input type="text" name="username" class="text" id="form-username" value="mrfoo" />
90
- </p>
91
- </fieldset>
102
+ <p>
103
+ <label for="form_username">Username</label>
104
+ <input type="text" name="username" id="form_username" value="mrfoo" />
105
+ </p>
92
106
  </form>
93
107
  FORM
94
108
  end
95
-
96
- it 'makes form with input_text(label, name)' do
97
- out = form(:method => :get){|f|
98
- f.input_text 'Username', :username
99
- }
109
+
110
+ it 'Make a form with input_text(username, label, value)' do
111
+ out = form_for(@data, :method => :get) do |f|
112
+ f.input_text 'Username', :username, :value => 'mrboo'
113
+ end
114
+
100
115
  assert(<<-FORM, out)
101
116
  <form method="get">
102
- <fieldset>
103
- <p>
104
- <label for="form-username">Username</label>
105
- <input type="text" name="username" class="text" id="form-username" />
106
- </p>
107
- </fieldset>
117
+ <p>
118
+ <label for="form_username">Username</label>
119
+ <input type="text" name="username" id="form_username" value="mrboo" />
120
+ </p>
108
121
  </form>
109
122
  FORM
110
123
  end
111
-
112
- it 'makes form with input_text(label, name, value, hash)' do
113
- out = form(:method => :get){|f|
114
- f.input_text 'Username', :username, nil, :size => 10
115
- }
124
+
125
+ it 'Make a form with input_text(label, name, size, id)' do
126
+ out = form_for(@data, :method => :get) do |f|
127
+ f.input_text 'Username', :username, :size => 10, :id => 'my_id'
128
+ end
129
+
116
130
  assert(<<-FORM, out)
117
131
  <form method="get">
118
- <fieldset>
119
- <p>
120
- <label for="form-username">Username</label>
121
- <input size="10" type="text" name="username" class="text" id="form-username" />
122
- </p>
123
- </fieldset>
132
+ <p>
133
+ <label for="my_id">Username</label>
134
+ <input size="10" type="text" name="username" id="my_id" value="mrfoo" />
135
+ </p>
124
136
  </form>
125
137
  FORM
126
138
  end
127
-
128
- it 'makes form with input_password(label, name)' do
129
- out = form(:method => :get){|f|
139
+
140
+ # ------------------------------------------------
141
+ # Password fields
142
+
143
+ it 'Make a form with input_password(label, name)' do
144
+ out = form_for(nil , :method => :get) do |f|
130
145
  f.input_password 'Password', :password
131
- }
146
+ end
147
+
132
148
  assert(<<-FORM, out)
133
149
  <form method="get">
134
- <fieldset>
135
- <p>
136
- <label for="form-password">Password</label>
137
- <input type="password" name="password" class="text" id="form-password" />
138
- </p>
139
- </fieldset>
150
+ <p>
151
+ <label for="form_password">Password</label>
152
+ <input type="password" name="password" id="form_password" />
153
+ </p>
140
154
  </form>
141
155
  FORM
142
156
  end
157
+
158
+ it 'Make a form with input_password(label, name, value, class)' do
159
+ out = form_for(@data, :method => :get) do |f|
160
+ f.input_password 'Password', :password, :value => 'super-secret-password', :class => 'password_class'
161
+ end
143
162
 
144
- it 'makes form with input_submit()' do
145
- out = form(:method => :get){|f|
163
+ assert(<<-FORM, out)
164
+ <form method="get">
165
+ <p>
166
+ <label for="form_password">Password</label>
167
+ <input class="password_class" type="password" name="password" id="form_password" value="super-secret-password" />
168
+ </p>
169
+ </form>
170
+ FORM
171
+ end
172
+
173
+ # ------------------------------------------------
174
+ # Submit buttons
175
+
176
+ it 'Make a form with input_submit()' do
177
+ out = form_for(@data, :method => :get) do |f|
146
178
  f.input_submit
147
- }
179
+ end
180
+
148
181
  assert(<<-FORM, out)
149
182
  <form method="get">
150
- <fieldset>
151
183
  <p>
152
- <input type="submit" class="button submit" />
184
+ <input type="submit" />
153
185
  </p>
154
- </fieldset>
155
186
  </form>
156
187
  FORM
157
188
  end
158
189
 
159
- it 'makes form with input_submit(value)' do
160
- out = form(:method => :get){|f|
190
+ it 'Make a form with input_submit(value)' do
191
+ out = form_for(@data, :method => :get) do |f|
161
192
  f.input_submit 'Send'
162
- }
193
+ end
194
+
163
195
  assert(<<-FORM, out)
164
196
  <form method="get">
165
- <fieldset>
166
- <p>
167
- <input type="submit" class="button submit" value="Send" />
168
- </p>
169
- </fieldset>
197
+ <p>
198
+ <input type="submit" value="Send" />
199
+ </p>
170
200
  </form>
171
201
  FORM
172
202
  end
173
-
174
- it 'makes form with input_checkbox(label, name)' do
175
- out = form(:method => :get){|f|
203
+
204
+ # ------------------------------------------------
205
+ # Checkboxes
206
+
207
+ it 'Make a form with input_checkbox(label, name)' do
208
+ out = form_for(@data, :method => :get) do |f|
176
209
  f.input_checkbox 'Assigned', :assigned
177
- }
210
+ end
211
+
178
212
  assert(<<-FORM, out)
179
213
  <form method="get">
180
- <fieldset>
181
- <p>
182
- <label for="form-assigned">Assigned</label>
183
- <input type="checkbox" name="assigned" class="checkbox" id="form-assigned" />
184
- </p>
185
- </fieldset>
214
+ <p>
215
+ <label for="form_assigned_0">Assigned</label>
216
+ <input type="hidden" name="assigned" value="0" />
217
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned[]" id="form_assigned_0" value="bacon" /> bacon</span>
218
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned[]" id="form_assigned_1" value="steak" /> steak</span>
219
+ </p>
186
220
  </form>
187
221
  FORM
188
222
  end
189
223
 
190
- it 'makes form with input_checkbox(label, name, checked = false)' do
191
- out = form(:method => :get){|f|
192
- f.input_checkbox 'Assigned', :assigned, false
193
- }
224
+ it 'Make a form with input_checkbox(label, name, checked)' do
225
+ out = form_for(@data, :method => :get) do |f|
226
+ f.input_checkbox 'Assigned', :assigned, 'bacon'
227
+ end
228
+
194
229
  assert(<<-FORM, out)
195
230
  <form method="get">
196
- <fieldset>
197
- <p>
198
- <label for="form-assigned">Assigned</label>
199
- <input type="checkbox" name="assigned" class="checkbox" id="form-assigned" />
200
- </p>
201
- </fieldset>
231
+ <p>
232
+ <label for="form_assigned_0">Assigned</label>
233
+ <input type="hidden" name="assigned" value="0" />
234
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned[]" id="form_assigned_0" checked="checked" value="bacon" /> bacon</span>
235
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned[]" id="form_assigned_1" value="steak" /> steak</span>
236
+ </p>
202
237
  </form>
203
238
  FORM
204
239
  end
205
240
 
206
- it 'makes form with input_checkbox(label, name, checked = true)' do
207
- out = form(:method => :get){|f|
208
- f.input_checkbox 'Assigned', :assigned, true
209
- }
241
+ it 'Make a form with input_checkbox(label, name, checked, values, default)' do
242
+ out = form_for(@data, :method => :get) do |f|
243
+ f.input_checkbox 'Assigned', :assigned, 'boo', :values => ['boo'], :default => 'ramaze'
244
+ end
245
+
210
246
  assert(<<-FORM, out)
211
247
  <form method="get">
212
- <fieldset>
213
- <p>
214
- <label for="form-assigned">Assigned</label>
215
- <input type="checkbox" name="assigned" class="checkbox" id="form-assigned" checked="checked" />
216
- </p>
217
- </fieldset>
248
+ <p>
249
+ <label for="form_assigned_0">Assigned</label>
250
+ <input type="hidden" name="assigned" value="ramaze" />
251
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned[]" id="form_assigned_0" checked="checked" value="boo" /> boo</span>
252
+ </p>
218
253
  </form>
219
254
  FORM
220
255
  end
256
+
257
+ # ------------------------------------------------
258
+ # Checkboxes using a hash
259
+
260
+ it 'Make a form with input_checkbox(label, name) using a hash' do
261
+ out = form_for(@data, :method => :get) do |f|
262
+ f.input_checkbox 'Assigned', :assigned_hash
263
+ end
221
264
 
222
- it 'makes form with input_checkbox(label, name, checked = nil)' do
223
- out = form(:method => :get){|f|
224
- f.input_checkbox 'Assigned', :assigned, nil
225
- }
226
265
  assert(<<-FORM, out)
227
266
  <form method="get">
228
- <fieldset>
229
- <p>
230
- <label for="form-assigned">Assigned</label>
231
- <input type="checkbox" name="assigned" class="checkbox" id="form-assigned" />
232
- </p>
233
- </fieldset>
267
+ <p>
268
+ <label for="form_assigned_hash_0">Assigned</label>
269
+ <input type="hidden" name="assigned_hash" value="0" />
270
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned_hash[]" id="form_assigned_hash_0" value="bacon" /> Bacon</span>
271
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned_hash[]" id="form_assigned_hash_1" value="steak" /> Steak</span>
272
+ </p>
234
273
  </form>
235
274
  FORM
236
275
  end
237
276
 
238
- it 'makes form with textarea(label, name)' do
239
- out = form(:method => :get){|f|
240
- f.textarea 'Message', :message
241
- }
277
+ it 'Make a form with input_checkbox(label, name, checked) using a hash' do
278
+ out = form_for(@data, :method => :get) do |f|
279
+ f.input_checkbox 'Assigned', :assigned_hash, 'bacon'
280
+ end
281
+
242
282
  assert(<<-FORM, out)
243
283
  <form method="get">
244
- <fieldset>
245
- <p>
246
- <label for="form-message">Message</label>
247
- <textarea name="message" id="form-message"></textarea>
248
- </p>
249
- </fieldset>
284
+ <p>
285
+ <label for="form_assigned_hash_0">Assigned</label>
286
+ <input type="hidden" name="assigned_hash" value="0" />
287
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned_hash[]" id="form_assigned_hash_0" checked="checked" value="bacon" /> Bacon</span>
288
+ <span class="checkbox_wrap"><input type="checkbox" name="assigned_hash[]" id="form_assigned_hash_1" value="steak" /> Steak</span>
289
+ </p>
250
290
  </form>
251
291
  FORM
252
292
  end
253
293
 
254
- it 'makes form with textarea(label, name, value)' do
255
- out = form(:method => :get){|f|
256
- f.textarea 'Message', :message, 'stuff'
257
- }
294
+ # ------------------------------------------------
295
+ # Radio buttons
296
+
297
+ it 'Make a form with input_radio(label, name)' do
298
+ out = form_for(@data, :method => :get) do |f|
299
+ f.input_radio 'Assigned', :assigned
300
+ end
301
+
258
302
  assert(<<-FORM, out)
259
303
  <form method="get">
260
- <fieldset>
261
- <p>
262
- <label for="form-message">Message</label>
263
- <textarea name="message" id="form-message">stuff</textarea>
264
- </p>
265
- </fieldset>
304
+ <p>
305
+ <label for="form_assigned_0">Assigned</label>
306
+ <input type="hidden" name="assigned" value="0" />
307
+ <span class="radio_wrap"><input type="radio" name="assigned" id="form_assigned_0" value="bacon" /> bacon</span>
308
+ <span class="radio_wrap"><input type="radio" name="assigned" id="form_assigned_1" value="steak" /> steak</span>
309
+ </p>
266
310
  </form>
267
311
  FORM
268
312
  end
269
313
 
270
- it 'makes form with input_file(label, name)' do
271
- out = form(:method => :get){|f|
272
- f.input_file 'Avatar', :avatar
273
- }
314
+ it 'Make a form with input_radio(label, name, checked)' do
315
+ out = form_for(@data, :method => :get) do |f|
316
+ f.input_radio 'Assigned', :assigned, 'bacon'
317
+ end
318
+
274
319
  assert(<<-FORM, out)
275
320
  <form method="get">
276
- <fieldset>
277
- <p>
278
- <label for="form-avatar">Avatar</label>
279
- <input type="file" name="avatar" class="file" id="form-avatar" />
280
- </p>
281
- </fieldset>
321
+ <p>
322
+ <label for="form_assigned_0">Assigned</label>
323
+ <input type="hidden" name="assigned" value="0" />
324
+ <span class="radio_wrap"><input type="radio" name="assigned" id="form_assigned_0" checked="checked" value="bacon" /> bacon</span>
325
+ <span class="radio_wrap"><input type="radio" name="assigned" id="form_assigned_1" value="steak" /> steak</span>
326
+ </p>
282
327
  </form>
283
328
  FORM
284
329
  end
330
+
331
+ it 'Make a form with input_radio(label, name, checked, values, default)' do
332
+ out = form_for(@data, :method => :get) do |f|
333
+ f.input_radio 'Assigned', :assigned, 'boo', :values => ['boo'], :default => 'ramaze'
334
+ end
285
335
 
286
- it 'makes form with input_hidden(name)' do
287
- out = form(:method => :get){|f|
288
- f.input_hidden :post_id
289
- }
290
336
  assert(<<-FORM, out)
291
337
  <form method="get">
292
- <fieldset>
293
- <input type="hidden" name="post_id" />
294
- </fieldset>
338
+ <p>
339
+ <label for="form_assigned_0">Assigned</label>
340
+ <input type="hidden" name="assigned" value="ramaze" />
341
+ <span class="radio_wrap"><input type="radio" name="assigned" id="form_assigned_0" checked="checked" value="boo" /> boo</span>
342
+ </p>
295
343
  </form>
296
344
  FORM
297
345
  end
346
+
347
+ # ------------------------------------------------
348
+ # Radio buttons using a hash
349
+
350
+ it 'Make a form with input_radio(label, name) using a hash' do
351
+ out = form_for(@data, :method => :get) do |f|
352
+ f.input_radio 'Assigned', :assigned_hash
353
+ end
298
354
 
299
- it 'makes form with input_hidden(name, value)' do
300
- out = form(:method => :get){|f|
301
- f.input_hidden :post_id, 15
302
- }
303
355
  assert(<<-FORM, out)
304
356
  <form method="get">
305
- <fieldset>
306
- <input type="hidden" name="post_id" value="15" />
307
- </fieldset>
357
+ <p>
358
+ <label for="form_assigned_hash_0">Assigned</label>
359
+ <input type="hidden" name="assigned_hash" value="0" />
360
+ <span class="radio_wrap"><input type="radio" name="assigned_hash" id="form_assigned_hash_0" value="bacon" /> Bacon</span>
361
+ <span class="radio_wrap"><input type="radio" name="assigned_hash" id="form_assigned_hash_1" value="steak" /> Steak</span>
362
+ </p>
308
363
  </form>
309
364
  FORM
310
365
  end
311
366
 
312
- servers_hash = {
313
- :webrick => 'WEBrick',
314
- :mongrel => 'Mongrel',
315
- :thin => 'Thin',
316
- }
367
+ it 'Make a form with input_radio(label, name, checked) using a hash' do
368
+ out = form_for(@data, :method => :get) do |f|
369
+ f.input_radio 'Assigned', :assigned_hash, 'bacon'
370
+ end
317
371
 
318
- it 'makes form with select(label, name, values) from hash' do
319
- out = form(:method => :get){|f|
320
- f.select 'Server', :server, servers_hash
321
- }
322
372
  assert(<<-FORM, out)
323
373
  <form method="get">
324
- <fieldset>
325
- <p>
326
- <label for="form-server">Server</label>
327
- <select id="form-server" size="1" name="server">
328
- <option value="webrick">WEBrick</option>
329
- <option value="mongrel">Mongrel</option>
330
- <option value="thin">Thin</option>
331
- </select>
332
- </p>
333
- </fieldset>
374
+ <p>
375
+ <label for="form_assigned_hash_0">Assigned</label>
376
+ <input type="hidden" name="assigned_hash" value="0" />
377
+ <span class="radio_wrap"><input type="radio" name="assigned_hash" id="form_assigned_hash_0" checked="checked" value="bacon" /> Bacon</span>
378
+ <span class="radio_wrap"><input type="radio" name="assigned_hash" id="form_assigned_hash_1" value="steak" /> Steak</span>
379
+ </p>
334
380
  </form>
335
381
  FORM
336
382
  end
337
383
 
338
- it 'makes form with select(label, name, values) with selection from hash' do
339
- out = form(:method => :get){|f|
340
- f.select 'Server', :server, servers_hash, :selected => :mongrel
341
- }
384
+ # ------------------------------------------------
385
+ # File uploading
386
+
387
+ it 'Make a form with input_file(label, name)' do
388
+ out = form_for(@data, :method => :get) do |f|
389
+ f.input_file 'File', :file
390
+ end
391
+
342
392
  assert(<<-FORM, out)
343
393
  <form method="get">
344
- <fieldset>
345
- <p>
346
- <label for="form-server">Server</label>
347
- <select id="form-server" size="1" name="server">
348
- <option value="webrick">WEBrick</option>
349
- <option value="mongrel" selected="selected">Mongrel</option>
350
- <option value="thin">Thin</option>
351
- </select>
352
- </p>
353
- </fieldset>
394
+ <p>
395
+ <label for="form_file">File</label>
396
+ <input type="file" name="file" id="form_file" />
397
+ </p>
354
398
  </form>
355
399
  FORM
356
400
  end
357
401
 
358
- servers_array = %w[ WEBrick Mongrel Thin]
402
+ it 'Make a form with input_file(label, name)' do
403
+ out = form_for(@data, :method => :get) do |f|
404
+ f.input_file 'File', :file, :id => 'awesome_file'
405
+ end
406
+
407
+ assert(<<-FORM, out)
408
+ <form method="get">
409
+ <p>
410
+ <label for="awesome_file">File</label>
411
+ <input type="file" name="file" id="awesome_file" />
412
+ </p>
413
+ </form>
414
+ FORM
415
+ end
416
+
417
+ # ------------------------------------------------
418
+ # Hidden fields
419
+
420
+ it 'Make a form with input_hidden(name, value)' do
421
+ out = form_for(@data, :method => :get) do |f|
422
+ f.input_hidden :username, 'Bob Ross'
423
+ end
359
424
 
360
- it 'makes form with select(label, name, values) from array' do
361
- out = form(:method => :get){|f|
362
- f.select 'Server', :server, servers_array
363
- }
364
425
  assert(<<-FORM, out)
365
426
  <form method="get">
366
- <fieldset>
367
- <p>
368
- <label for="form-server">Server</label>
369
- <select id="form-server" size="1" name="server">
370
- <option value="WEBrick">WEBrick</option>
371
- <option value="Mongrel">Mongrel</option>
372
- <option value="Thin">Thin</option>
373
- </select>
374
- </p>
375
- </fieldset>
427
+ <input type="hidden" name="username" value="Bob Ross" />
376
428
  </form>
377
429
  FORM
378
430
  end
431
+
432
+ it 'Make a form with input_hidden(name, value, id)' do
433
+ out = form_for(@data, :method => :get) do |f|
434
+ f.input_hidden :username, 'Bob Ross', :id => 'test'
435
+ end
379
436
 
380
- it 'makes form with select(label, name, values) with selection from array' do
381
- out = form(:method => :get){|f|
382
- f.select 'Server', :server, servers_array, :selected => 'Mongrel'
383
- }
384
437
  assert(<<-FORM, out)
385
438
  <form method="get">
386
- <fieldset>
387
- <p>
388
- <label for="form-server">Server</label>
389
- <select id="form-server" size="1" name="server">
390
- <option value="WEBrick">WEBrick</option>
391
- <option value="Mongrel" selected="selected">Mongrel</option>
392
- <option value="Thin">Thin</option>
393
- </select>
394
- </p>
395
- </fieldset>
439
+ <input type="hidden" name="username" value="Bob Ross" id="test" />
396
440
  </form>
397
441
  FORM
398
442
  end
443
+
444
+ # ------------------------------------------------
445
+ # Textarea elements
446
+
447
+ it 'Make a form with textarea(label, name)' do
448
+ out = form_for(@data, :method => :get) do |f|
449
+ f.textarea 'Message', :message
450
+ end
399
451
 
400
- it 'makes form with radio(label, name, values) with selection from array' do
401
- out = form(:method => :get){|f|
402
- f.radio 'Server', :server, servers_array, :checked => 'Mongrel'
403
- }
404
452
  assert(<<-FORM, out)
405
453
  <form method="get">
406
- <fieldset>
407
- <p>
408
- <label for="form-server-0"><input type="radio" value="WEBrick" id="form-server-0" name="server" />WEBrick</label>
409
- <label for="form-server-1"><input type="radio" value="Mongrel" id="form-server-1" name="server" checked="checked" />Mongrel</label>
410
- <label for="form-server-2"><input type="radio" value="Thin" id="form-server-2" name="server" />Thin</label>
411
- </p>
412
- </fieldset>
454
+ <p>
455
+ <label for="form_message">Message</label>
456
+ <textarea name="message" id="form_message">Hello, textarea!</textarea>
457
+ </p>
458
+ </form>
459
+ FORM
460
+ end
461
+
462
+ it 'Make a form with textarea(label, name, value)' do
463
+ out = form_for(@data, :method => :get) do |f|
464
+ f.textarea 'Message', :message, :value => 'stuff'
465
+ end
466
+
467
+ assert(<<-FORM, out)
468
+ <form method="get">
469
+ <p>
470
+ <label for="form_message">Message</label>
471
+ <textarea name="message" id="form_message">stuff</textarea>
472
+ </p>
473
+ </form>
474
+ FORM
475
+ end
476
+
477
+ # ------------------------------------------------
478
+ # Select elements
479
+
480
+ it 'Make a form with select(label, name) from a hash' do
481
+ out = form_for(@data, :method => :get) do |f|
482
+ f.select 'Server', :servers_hash
483
+ end
484
+
485
+ assert(<<-FORM, out)
486
+ <form method="get">
487
+ <p>
488
+ <label for="form_servers_hash">Server</label>
489
+ <select id="form_servers_hash" size="3" name="servers_hash">
490
+ <option value="webrick">WEBrick</option>
491
+ <option value="mongrel">Mongrel</option>
492
+ <option value="thin">Thin</option>
493
+ </select>
494
+ </p>
495
+ </form>
496
+ FORM
497
+ end
498
+
499
+ it 'Make a form with select(label, name, selected) from a hash' do
500
+ out = form_for(@data, :method => :get) do |f|
501
+ f.select 'Server', :servers_hash, :selected => :mongrel
502
+ end
503
+
504
+ assert(<<-FORM, out)
505
+ <form method="get">
506
+ <p>
507
+ <label for="form_servers_hash">Server</label>
508
+ <select id="form_servers_hash" size="3" name="servers_hash">
509
+ <option value="webrick">WEBrick</option>
510
+ <option value="mongrel" selected="selected">Mongrel</option>
511
+ <option value="thin">Thin</option>
512
+ </select>
513
+ </p>
514
+ </form>
515
+ FORM
516
+ end
517
+
518
+ it 'Make a form with select(label, name) from an array' do
519
+ out = form_for(@data, :method => :get) do |f|
520
+ f.select 'Server', :servers_array
521
+ end
522
+
523
+ assert(<<-FORM, out)
524
+ <form method="get">
525
+ <p>
526
+ <label for="form_servers_array">Server</label>
527
+ <select id="form_servers_array" size="3" name="servers_array">
528
+ <option value="WEBrick">WEBrick</option>
529
+ <option value="Mongrel">Mongrel</option>
530
+ <option value="Thin">Thin</option>
531
+ </select>
532
+ </p>
413
533
  </form>
414
534
  FORM
415
535
  end
416
536
 
417
- it 'inserts error messages' do
537
+ it 'Make a form with select(label, name, selected) from an array' do
538
+ out = form_for(@data, :method => :get) do |f|
539
+ f.select 'Server', :servers_array, :selected => 'Mongrel'
540
+ end
541
+
542
+ assert(<<-FORM, out)
543
+ <form method="get">
544
+ <p>
545
+ <label for="form_servers_array">Server</label>
546
+ <select id="form_servers_array" size="3" name="servers_array">
547
+ <option value="WEBrick">WEBrick</option>
548
+ <option value="Mongrel" selected="selected">Mongrel</option>
549
+ <option value="Thin">Thin</option>
550
+ </select>
551
+ </p>
552
+ </form>
553
+ FORM
554
+ end
555
+
556
+ # ------------------------------------------------
557
+ # Select elements with custom values
558
+
559
+ it 'Make a form with select(label, name) from a hash using custom values' do
560
+ out = form_for(@data, :method => :get) do |f|
561
+ f.select 'People', :people_hash, :values => {:chuck => 'Chuck', :bob => 'Bob'}
562
+ end
563
+
564
+ assert(<<-FORM, out)
565
+ <form method="get">
566
+ <p>
567
+ <label for="form_people_hash">People</label>
568
+ <select id="form_people_hash" size="2" name="people_hash">
569
+ <option value="chuck">Chuck</option>
570
+ <option value="bob">Bob</option>
571
+ </select>
572
+ </p>
573
+ </form>
574
+ FORM
575
+ end
576
+
577
+ it 'Make a form with select(label, name, selected) from a hash using custom values' do
578
+ out = form_for(@data, :method => :get) do |f|
579
+ f.select 'People', :people_hash, :values => {:chuck => 'Chuck', :bob => 'Bob'}, :selected => :chuck
580
+ end
581
+
582
+ assert(<<-FORM, out)
583
+ <form method="get">
584
+ <p>
585
+ <label for="form_people_hash">People</label>
586
+ <select id="form_people_hash" size="2" name="people_hash">
587
+ <option value="chuck" selected="selected">Chuck</option>
588
+ <option value="bob">Bob</option>
589
+ </select>
590
+ </p>
591
+ </form>
592
+ FORM
593
+ end
594
+
595
+ it 'Make a form with select(label, name) from an array using custom values' do
596
+ out = form_for(@data, :method => :get) do |f|
597
+ f.select 'People', :people_array, :values => ['Chuck', 'Bob']
598
+ end
599
+
600
+ assert(<<-FORM, out)
601
+ <form method="get">
602
+ <p>
603
+ <label for="form_people_array">People</label>
604
+ <select id="form_people_array" size="2" name="people_array">
605
+ <option value="Chuck">Chuck</option>
606
+ <option value="Bob">Bob</option>
607
+ </select>
608
+ </p>
609
+ </form>
610
+ FORM
611
+ end
612
+
613
+ it 'Make a form with select(label, name, selected) from an array using custom values' do
614
+ out = form_for(@data, :method => :get) do |f|
615
+ f.select 'People', :people_array, :values => ['Chuck', 'Bob'], :selected => 'Chuck'
616
+ end
617
+
618
+ assert(<<-FORM, out)
619
+ <form method="get">
620
+ <p>
621
+ <label for="form_people_array">People</label>
622
+ <select id="form_people_array" size="2" name="people_array">
623
+ <option value="Chuck" selected="selected">Chuck</option>
624
+ <option value="Bob">Bob</option>
625
+ </select>
626
+ </p>
627
+ </form>
628
+ FORM
629
+ end
630
+
631
+ it 'Make a form with multiple select(label, name) from a hash' do
632
+ out = form_for(@data, :method => :get) do |f|
633
+ f.select 'Server', :servers_hash, :multiple => :multiple
634
+ end
635
+
636
+ assert(<<-FORM, out)
637
+ <form method="get">
638
+ <p>
639
+ <label for="form_servers_hash">Server</label>
640
+ <select id="form_servers_hash" size="3" name="servers_hash[]" multiple="multiple">
641
+ <option value="webrick">WEBrick</option>
642
+ <option value="mongrel">Mongrel</option>
643
+ <option value="thin">Thin</option>
644
+ </select>
645
+ </p>
646
+ </form>
647
+ FORM
648
+ end
649
+
650
+ it 'Make a form with multiple select(label, name, selected) from a hash' do
651
+ out = form_for(@data, :method => :get) do |f|
652
+ f.select 'Server', :servers_hash, :multiple => :multiple, :selected => :webrick
653
+ end
654
+
655
+ assert(<<-FORM, out)
656
+ <form method="get">
657
+ <p>
658
+ <label for="form_servers_hash">Server</label>
659
+ <select id="form_servers_hash" size="3" name="servers_hash[]" multiple="multiple">
660
+ <option value="webrick" selected="selected">WEBrick</option>
661
+ <option value="mongrel">Mongrel</option>
662
+ <option value="thin">Thin</option>
663
+ </select>
664
+ </p>
665
+ </form>
666
+ FORM
667
+ end
668
+
669
+ it 'Make a form with multiple select(label, name, selected) from a hash' do
670
+ out = form_for(@data, :method => :get) do |f|
671
+ f.select 'Server', :servers_hash, :multiple => :multiple, :selected => [:webrick, :mongrel]
672
+ end
673
+
674
+ assert(<<-FORM, out)
675
+ <form method="get">
676
+ <p>
677
+ <label for="form_servers_hash">Server</label>
678
+ <select id="form_servers_hash" size="3" name="servers_hash[]" multiple="multiple">
679
+ <option value="webrick" selected="selected">WEBrick</option>
680
+ <option value="mongrel" selected="selected">Mongrel</option>
681
+ <option value="thin">Thin</option>
682
+ </select>
683
+ </p>
684
+ </form>
685
+ FORM
686
+ end
687
+
688
+ # ------------------------------------------------
689
+ # Error messages
690
+
691
+ it 'Insert an error message' do
418
692
  form_error :username, 'May not be empty'
419
- out = form(:method => :get){|f|
693
+ out = form_for(@data, :method => :get) do |f|
420
694
  f.input_text 'Username', :username
421
- }
695
+ end
696
+
422
697
  assert(<<-FORM, out)
423
698
  <form method="get">
424
- <fieldset>
425
- <p>
426
- <label for="form-username">Username <span class="error">May not be empty</span></label>
427
- <input type="text" name="username" class="text" id="form-username" />
428
- </p>
429
- </fieldset>
699
+ <p>
700
+ <label for="form_username">Username <span class="error">May not be empty</span></label>
701
+ <input type="text" name="username" id="form_username" value="mrfoo" />
702
+ </p>
430
703
  </form>
431
704
  FORM
432
705
  end
706
+
707
+ it 'Retrieve all errors messages from the model' do
708
+ @data.errors = {:username => "May not be empty"}
709
+ form_errors_from_model(@data)
710
+
711
+ out = form_for(@data, :method => :get) do |f|
712
+ f.input_text 'Username', :username
713
+ end
714
+
715
+ assert(<<-FORM, out)
716
+ <form method="get">
717
+ <p>
718
+ <label for="form_username">Username <span class="error">May not be empty</span></label>
719
+ <input type="text" name="username" id="form_username" value="mrfoo" />
720
+ </p>
721
+ </form>
722
+ FORM
723
+ end
724
+
433
725
  end