forme 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/forme_spec.rb DELETED
@@ -1,1216 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe "Forme plain forms" do
4
- def sel(opts, s)
5
- opts.map{|o| "<option #{'selected="selected" ' if o == s}value=\"#{o}\">#{sprintf("%02i", o)}</option>"}.join
6
- end
7
-
8
- before do
9
- @f = Forme::Form.new
10
- end
11
-
12
- it "Forme.version should return version string" do
13
- Forme.version.must_match(/\A\d+\.\d+\.\d+\z/)
14
- end
15
-
16
- it "should create a simple input tags" do
17
- @f.input(:text).to_s.must_equal '<input type="text"/>'
18
- @f.input(:radio).to_s.must_equal '<input type="radio"/>'
19
- @f.input(:password).to_s.must_equal '<input type="password"/>'
20
- @f.input(:checkbox).to_s.must_equal '<input type="checkbox"/>'
21
- @f.input(:submit).to_s.must_equal '<input type="submit"/>'
22
- end
23
-
24
- it "should use :html option if given" do
25
- @f.input(:text, :html=>"<a>foo</a>").to_s.must_equal '<a>foo</a>'
26
- end
27
-
28
- it "should support a callable :html option" do
29
- @f.input(:text, :html=>proc{|i| "<a>#{i.type}</a>"}).to_s.must_equal '<a>text</a>'
30
- end
31
-
32
- it "should still use labeler, wrapper, error_handler, and helper if :html option is given" do
33
- @f.input(:text, :html=>"<a>foo</a>", :label=>'a', :error=>'b', :help=>'c', :wrapper=>:div).to_s.must_equal '<div><label>a: <a>foo</a></label><span class="error_message">b</span><span class="helper">c</span></div>'
34
- end
35
-
36
- it "should use :name option as attribute" do
37
- @f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" type="text"/>'
38
- end
39
-
40
- it "should use :id option as attribute" do
41
- @f.input(:text, :id=>"foo").to_s.must_equal '<input id="foo" type="text"/>'
42
- end
43
-
44
- it "should use :class option as attribute" do
45
- @f.input(:text, :class=>"foo").to_s.must_equal '<input class="foo" type="text"/>'
46
- end
47
-
48
- it "should use :value option as attribute" do
49
- @f.input(:text, :value=>"foo").to_s.must_equal '<input type="text" value="foo"/>'
50
- end
51
-
52
- it "should use :placeholder option as attribute" do
53
- @f.input(:text, :placeholder=>"foo").to_s.must_equal '<input placeholder="foo" type="text"/>'
54
- end
55
-
56
- it "should use :style option as attribute" do
57
- @f.input(:text, :style=>"foo").to_s.must_equal '<input style="foo" type="text"/>'
58
- end
59
-
60
- it "should use :key option as name and id attributes" do
61
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text"/>'
62
- end
63
-
64
- it "should use :key_id option as suffix for :key option id attributes" do
65
- @f.input(:text, :key=>"foo", :key_id=>'bar').to_s.must_equal '<input id="foo_bar" name="foo" type="text"/>'
66
- end
67
-
68
- it "should have :key option respect :multiple option" do
69
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="foo" name="foo[]" type="text"/>'
70
- end
71
-
72
- it "should use :key option respect form's current namespace" do
73
- @f.with_opts(:namespace=>['bar']) do
74
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
75
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="bar_foo" name="bar[foo][]" type="text"/>'
76
- @f.with_opts(:namespace=>['bar', 'baz']) do
77
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_baz_foo" name="bar[baz][foo]" type="text"/>'
78
- end
79
- end
80
- end
81
-
82
- it "should consider form's :values hash for default values based on the :key option if :value is not present" do
83
- @f.opts[:values] = {'foo'=>'baz'}
84
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
85
- @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="foo" name="foo" type="text" value="x"/>'
86
-
87
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
88
- @f.opts[:values] = {:foo=>'baz'}
89
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
90
- end
91
-
92
- it "should consider form's :values hash for default values based on the :key option when using namespaces" do
93
- @f.opts[:values] = {'bar'=>{'foo'=>'baz'}}
94
- @f.with_opts(:namespace=>['bar']) do
95
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
96
- @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="x"/>'
97
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
98
- end
99
-
100
- @f.with_opts(:namespace=>[:bar]) do
101
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
102
-
103
- @f.opts[:values] = {:bar=>{:foo=>'baz'}}
104
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
105
- @f.opts[:values] = {:bar=>{}}
106
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
107
- @f.opts[:values] = {}
108
- @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
109
-
110
- @f.opts[:values] = {'bar'=>{'quux'=>{'foo'=>'baz'}}}
111
- @f.with_opts(:namespace=>['bar', 'quux']) do
112
- @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/>'
113
- end
114
- end
115
- end
116
-
117
- it "should consider form's :errors hash based on the :key option" do
118
- @f.opts[:errors] = { 'foo' => 'must be present' }
119
- @f.input(:text, :key=>"foo").to_s.must_equal "<input aria-describedby=\"foo_error_message\" aria-invalid=\"true\" class=\"error\" id=\"foo\" name=\"foo\" type=\"text\"/><span class=\"error_message\" id=\"foo_error_message\">must be present</span>"
120
- end
121
-
122
- it "should consider form's :errors hash based on the :key option when using namespaces" do
123
- @f.opts[:errors] = { 'bar' => { 'foo' => 'must be present' } }
124
- @f.with_opts(:namespace=>['bar']) do
125
- @f.input(:text, :key=>"foo").to_s.must_equal "<input aria-describedby=\"bar_foo_error_message\" aria-invalid=\"true\" class=\"error\" id=\"bar_foo\" name=\"bar[foo]\" type=\"text\"/><span class=\"error_message\" id=\"bar_foo_error_message\">must be present</span>"
126
- end
127
- end
128
-
129
- it "should support a with_obj method that changes the object and namespace for the given block" do
130
- @f.with_obj([:a, :c], 'bar') do
131
- @f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="a"/>'
132
- @f.with_obj([:b], 'baz') do
133
- @f.input(:first).to_s.must_equal '<input id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/>'
134
- end
135
- @f.with_obj([:b], %w'baz quux') do
136
- @f.input(:first).to_s.must_equal '<input id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/>'
137
- end
138
- @f.with_obj([:b]) do
139
- @f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="b"/>'
140
- end
141
- @f.input(:last).to_s.must_equal '<input id="bar_last" name="bar[last]" type="text" value="c"/>'
142
- end
143
- end
144
-
145
- it "should support a each_obj method that changes the object and namespace for multiple objects for the given block" do
146
- @f.tag(:form) do
147
- @f.each_obj([[:a, :c], [:b, :d]], 'bar') do
148
- @f.input(:first)
149
- @f.input(:last)
150
- end
151
- end.to_s.must_equal '<form><input id="bar_0_first" name="bar[0][first]" type="text" value="a"/><input id="bar_0_last" name="bar[0][last]" type="text" value="c"/><input id="bar_1_first" name="bar[1][first]" type="text" value="b"/><input id="bar_1_last" name="bar[1][last]" type="text" value="d"/></form>'
152
-
153
- @f.tag(:form) do
154
- @f.each_obj([[:a, :c], [:b, :d]], %w'bar baz') do
155
- @f.input(:first)
156
- @f.input(:last)
157
- end
158
- end.to_s.must_equal '<form><input id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/><input id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/><input id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/><input id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></form>'
159
-
160
- @f.tag(:form) do
161
- @f.each_obj([[:a, :c], [:b, :d]]) do
162
- @f.input(:first)
163
- @f.input(:last)
164
- end
165
- end.to_s.must_equal '<form><input id="0_first" name="0[first]" type="text" value="a"/><input id="0_last" name="0[last]" type="text" value="c"/><input id="1_first" name="1[first]" type="text" value="b"/><input id="1_last" name="1[last]" type="text" value="d"/></form>'
166
- end
167
-
168
- it "should allow overriding form inputs on a per-block basis" do
169
- @f.input(:text).to_s.must_equal '<input type="text"/>'
170
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.must_equal '<div><input type="text"/></div>'
171
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s.must_equal '<div><input type="text"/></div>'}
172
- @f.with_opts(:wrapper=>:div) do
173
- @f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
174
- @f.with_opts(:wrapper=>:li){@f.input(:text).to_s.must_equal '<li><input type="text"/></li>'}
175
- @f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
176
- end
177
- @f.input(:text).to_s.must_equal '<input type="text"/>'
178
- end
179
-
180
- it "should handle delayed formatting when overriding form inputs on a per-block basis" do
181
- @f.form do
182
- @f.input(:text)
183
- @f.with_opts(:wrapper=>:div) do
184
- @f.input(:text)
185
- @f.with_opts(:wrapper=>:li){@f.input(:text)}
186
- @f.input(:text)
187
- end
188
- @f.input(:text)
189
- end.to_s.must_equal '<form><input type="text"/><div><input type="text"/></div><li><input type="text"/></li><div><input type="text"/></div><input type="text"/></form>'
190
- end
191
-
192
- it "should support :obj method to with_opts for changing the obj inside the block" do
193
- @f.form do
194
- @f.with_opts(:obj=>[:a, :c]) do
195
- @f.input(:first)
196
- @f.with_opts(:obj=>[:b]){@f.input(:first)}
197
- @f.input(:last)
198
- end
199
- end.to_s.must_equal '<form><input id="first" name="first" type="text" value="a"/><input id="first" name="first" type="text" value="b"/><input id="last" name="last" type="text" value="c"/></form>'
200
- end
201
-
202
- it "should allow arbitrary attributes using the :attr option" do
203
- @f.input(:text, :attr=>{:bar=>"foo"}).to_s.must_equal '<input bar="foo" type="text"/>'
204
- end
205
-
206
- it "should convert the :data option into attributes" do
207
- @f.input(:text, :data=>{:bar=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
208
- end
209
-
210
- it "should replace underscores with hyphens in symbol :data keys when :dasherize_data is set" do
211
- @f.input(:text, :data=>{:foo_bar=>"baz"}).to_s.must_equal '<input data-foo_bar="baz" type="text"/>'
212
- @f.input(:text, :data=>{"foo_bar"=>"baz"}).to_s.must_equal '<input data-foo_bar="baz" type="text"/>'
213
-
214
- @f.input(:text, :data=>{:foo_bar=>"baz"}, :dasherize_data => true).to_s.must_equal '<input data-foo-bar="baz" type="text"/>'
215
- @f.input(:text, :data=>{"foo_bar"=>"baz"}, :dasherize_data => true).to_s.must_equal '<input data-foo_bar="baz" type="text"/>'
216
- end
217
-
218
- it "should not have standard options override the :attr option" do
219
- @f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.must_equal '<input name="foo" type="text"/>'
220
- end
221
-
222
- it "should combine :class standard option with :attr option" do
223
- @f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.must_equal '<input class="foo bar" type="text"/>'
224
- end
225
-
226
- it "should not have :data options override the :attr option" do
227
- @f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
228
- end
229
-
230
- it "should use :size and :maxlength options as attributes for text inputs" do
231
- @f.input(:text, :size=>5, :maxlength=>10).to_s.must_equal '<input maxlength="10" size="5" type="text"/>'
232
- @f.input(:textarea, :size=>5, :maxlength=>10).to_s.must_equal '<textarea></textarea>'
233
- end
234
-
235
- it "should create hidden input with value 0 for each checkbox with a name" do
236
- @f.input(:checkbox, :name=>"foo").to_s.must_equal '<input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/>'
237
- end
238
-
239
- it "should not create hidden input with value 0 for readonly or disabled checkboxes" do
240
- @f.input(:checkbox, :name=>"foo", :formatter=>:disabled).to_s.must_equal '<input disabled="disabled" name="foo" type="checkbox"/>'
241
- @f.input(:checkbox, :name=>"foo", :formatter=>:readonly).to_s.must_equal '<input disabled="disabled" name="foo" type="checkbox"/>'
242
- end
243
-
244
- it "should create hidden input with value 0 for readonly or disabled checkboxes if no_hidden is explicitly given and not true" do
245
- @f.input(:checkbox, :name=>"foo", :formatter=>:disabled, :no_hidden=>false).to_s.must_equal '<input name="foo" type="hidden" value="0"/><input disabled="disabled" name="foo" type="checkbox"/>'
246
- @f.input(:checkbox, :name=>"foo", :formatter=>:readonly, :no_hidden=>false).to_s.must_equal '<input name="foo" type="hidden" value="0"/><input disabled="disabled" name="foo" type="checkbox"/>'
247
- end
248
-
249
- it "should not create hidden input with value 0 for each checkbox with a name if :no_hidden option is used" do
250
- @f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.must_equal '<input name="foo" type="checkbox"/>'
251
- end
252
-
253
- it "should create hidden input with _hidden appened to id for each checkbox with a name and id" do
254
- @f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.must_equal '<input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/>'
255
- end
256
-
257
- it "should create hidden input with value f for each checkbox with a name and value t" do
258
- @f.input(:checkbox, :name=>"foo", :value=>"t").to_s.must_equal '<input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/>'
259
- end
260
-
261
- it "should use :hidden_value option for value of hidden input for checkbox" do
262
- @f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
263
- end
264
-
265
- it "should handle :checked option" do
266
- @f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
267
- @f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
268
- end
269
-
270
- it "should create textarea tag" do
271
- @f.input(:textarea).to_s.must_equal '<textarea></textarea>'
272
- @f.input(:textarea, :value=>'a').to_s.must_equal '<textarea>a</textarea>'
273
- end
274
-
275
- it "should use :cols and :rows options as attributes for textarea inputs" do
276
- @f.input(:text, :cols=>5, :rows=>10).to_s.must_equal '<input type="text"/>'
277
- @f.input(:textarea, :cols=>5, :rows=>10).to_s.must_equal '<textarea cols="5" rows="10"></textarea>'
278
- end
279
-
280
- it "should create select tag" do
281
- @f.input(:select).to_s.must_equal '<select></select>'
282
- end
283
-
284
- it "should respect multiple and size options in select tag" do
285
- @f.input(:select, :multiple=>true, :size=>10).to_s.must_equal '<select multiple="multiple" size="10"></select>'
286
- end
287
-
288
- it "should create date tag" do
289
- @f.input(:date).to_s.must_equal '<input type="date"/>'
290
- end
291
-
292
- it "should create datetime-local tag" do
293
- @f.input(:datetime).to_s.must_equal '<input type="datetime-local"/>'
294
- end
295
-
296
- it "should not error for input type :input" do
297
- @f.input(:input).to_s.must_equal '<input type="input"/>'
298
- end
299
-
300
- it "should use multiple select boxes for dates if the :as=>:select option is given" do
301
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
302
- end
303
-
304
- it "should use labels for select boxes for dates if the :as=>:select and :select_labels options are given" do
305
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_labels=>{:year=>'Y', :month=>'M', :day=>'D'}, :labeler=>:explicit).to_s.must_equal %{<label class="label-before" for="bar">Y</label><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<label class="label-before" for="bar_month">M</label><select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<label class="label-before" for="bar_day">D</label><select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
306
- end
307
-
308
- it "should allow ordering date select boxes via :order" do
309
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
310
- end
311
-
312
- it "should allow only using specific date select boxes via :order" do
313
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
314
- end
315
-
316
- it "should support :select_options for dates when :as=>:select is given" do
317
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
318
- end
319
-
320
- it "should support :select_options with both values and text for dates when :as=>:select is given" do
321
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>[[2011, 'A'], [2012, 'B']]}).to_s.must_equal %{<select id="bar" name="foo[year]"><option selected="selected" value="2011">A</option><option value="2012">B</option></select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
322
- end
323
-
324
- it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
325
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.must_equal %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
326
- end
327
-
328
- it "should use multiple select boxes for datetimes if the :as=>:select option is given" do
329
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
330
- end
331
-
332
- it "should allow ordering select boxes for datetimes via :order" do
333
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2), :order=>[:day, '/', :month, 'T', :hour, ':', :minute]).to_s.must_equal %{<select id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>}
334
- end
335
-
336
- it "should support :select_options for datetimes when :as=>:select option is given" do
337
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 10, 3, 2), :select_options=>{:year=>1970..2020, :hour=>9..17}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
338
- end
339
-
340
- it "should create select tag with options" do
341
- @f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
342
- @f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
343
- end
344
-
345
- it "should create select tag with options and values" do
346
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<select><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
347
- end
348
-
349
- it "should have select work with false values" do
350
- @f.input(:select, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<select><option value="true">1</option><option selected="selected" value="false">2</option></select>'
351
- end
352
-
353
- it "should create select tag with option groups" do
354
- @f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup label="e"><option value="3">c</option></optgroup></select>'
355
- end
356
-
357
- it "should create select tag with option groups with attributes" do
358
- @f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup class="f" label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup class="g" label="e"><option value="3">c</option></optgroup></select>'
359
- end
360
-
361
- it "should create select tag with options and values with hashes" do
362
- @f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.must_equal '<select><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select>'
363
- end
364
-
365
- it "should create select tag with options and values using given method" do
366
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
367
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<select><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select>'
368
- end
369
-
370
- it "should use html attributes specified in options" do
371
- @f.input(:text, :value=>'foo', :name=>'bar').to_s.must_equal '<input name="bar" type="text" value="foo"/>'
372
- @f.input(:textarea, :value=>'foo', :name=>'bar').to_s.must_equal '<textarea name="bar">foo</textarea>'
373
- @f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.must_equal '<select name="bar"><option>1</option><option>2</option><option>3</option></select>'
374
- end
375
-
376
- it "should support :add_blank option for select inputs" do
377
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
378
- end
379
-
380
- it "should use Forme.default_add_blank_prompt value if :add_blank option is true" do
381
- begin
382
- Forme.default_add_blank_prompt = 'foo'
383
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
384
- ensure
385
- Forme.default_add_blank_prompt = nil
386
- end
387
- end
388
-
389
- it "should use :add_blank option value as prompt if it is a String" do
390
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<select><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
391
- end
392
-
393
- it "should support :add_blank option with :blank_position :after for select inputs" do
394
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.must_equal '<select><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select>'
395
- end
396
-
397
- it "should support :add_blank option with :blank_attr option for select inputs" do
398
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.must_equal '<select><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
399
- end
400
-
401
- it "should create set of radio buttons" do
402
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
403
- @f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
404
- end
405
-
406
- it "should have radioset work with false values" do
407
- @f.input(:radioset, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<label class="option"><input type="radio" value="true"/> 1</label><label class="option"><input checked="checked" type="radio" value="false"/> 2</label>'
408
- end
409
-
410
- it "should create set of radio buttons with options and values" do
411
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
412
- end
413
-
414
- it "should create set of radio buttons with options and values with hashes" do
415
- @f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="radio" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label><label class="option"><input id="baz" type="radio" value="c"/> c</label>'
416
- end
417
-
418
- it "should create set of radio buttons with options and values using given method" do
419
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
420
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="radio" value="a"/> 1</label><label class="option"><input checked="checked" type="radio" value="b"/> 2</label><label class="option"><input type="radio" value="c"/> 3</label>'
421
- end
422
-
423
- it "should support :add_blank option for radioset inputs" do
424
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> </label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
425
- end
426
-
427
- it "should use :add_blank option value as prompt if it is a String" do
428
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
429
- end
430
-
431
- it "should respect the :key option for radio sets" do
432
- @f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label>'
433
- end
434
-
435
- it "should create set of radio buttons with fieldsets and legends for :optgroups" do
436
- @f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="radio" value="3"/> c</label></fieldset>'
437
- end
438
-
439
- it "should create set of radio buttons with label attributes" do
440
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :label_attr=>{:foo=>:bar}).to_s.must_equal '<label class="option" foo="bar"><input type="radio" value="1"/> 1</label><label class="option" foo="bar"><input checked="checked" type="radio" value="2"/> 2</label><label class="option" foo="bar"><input type="radio" value="3"/> 3</label>'
441
- end
442
-
443
- it "should create set of radio buttons with :error and :error_attr options" do
444
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input aria-invalid="true" class="error" type="radio" value="3"/> 3</label><span bar="baz" class="error_message">foo</span>'
445
- end
446
-
447
- it "should support custom error_handler for set of radio buttons" do
448
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}, :error_handler=>lambda{|tag, input| input.tag(:div, {}, tag)}).to_s.must_equal '<div><label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label></div>'
449
- end
450
-
451
- it "should create set of checkbox buttons" do
452
- @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
453
- @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
454
- end
455
-
456
- it "should create set of checkbox buttons with options and values" do
457
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
458
- end
459
-
460
- it "should have radioset work with false values" do
461
- @f.input(:checkboxset, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<label class="option"><input type="checkbox" value="true"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="false"/> 2</label>'
462
- end
463
-
464
- it "should support :wrapper and :tag_wrapper for checkboxsets" do
465
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_wrapper=>:div, :wrapper=>:li).to_s.must_equal '<li><div><label class="option"><input type="checkbox" value="1"/> a</label></div><div><label class="option"><input type="checkbox" value="2"/> b</label></div><div><label class="option"><input type="checkbox" value="3"/> c</label></div></li>'
466
- end
467
-
468
- it "should support :label for checkboxsets" do
469
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo').to_s.must_equal '<span class="label">foo</span><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
470
- end
471
-
472
- it "should support fieldset/legend for checkboxsets" do
473
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :labeler=>:legend, :wrapper=>:fieldset).to_s.must_equal '<fieldset><legend>foo</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
474
- end
475
-
476
- it "should support legend with attributes for checkboxsets" do
477
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :label_attr=>{:class=>"baz"}, :tag_label_attr=>{:class=>"bar"}, :labeler=>:legend, :wrapper=>:fieldset).to_s.must_equal '<fieldset><legend class="baz">foo</legend><label class="bar"><input type="checkbox" value="1"/> a</label><label class="bar"><input type="checkbox" value="2"/> b</label><label class="bar"><input type="checkbox" value="3"/> c</label></fieldset>'
478
- end
479
-
480
- it "should support legend with attributes for checkboxsets, handling errors with :error_handler=>:after_legend" do
481
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :id=>:quux, :label=>'foo', :label_attr=>{:class=>"baz"}, :tag_label_attr=>{:class=>"bar"}, :labeler=>:legend, :wrapper=>:fieldset, :error=>'bar2', :error_handler=>:after_legend).to_s.must_equal '<fieldset><legend class="baz">foo</legend><span class="error_message" id="quux_1_error_message">bar2</span><label class="bar"><input aria-describedby="quux_1_error_message" aria-invalid="true" class="error" id="quux_1" type="checkbox" value="1"/> a</label><label class="bar"><input id="quux_2" type="checkbox" value="2"/> b</label><label class="bar"><input id="quux_3" type="checkbox" value="3"/> c</label></fieldset>'
482
- end
483
-
484
- it "should support :tag_labeler for checkboxsets" do
485
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_labeler=>:explicit).to_s.must_equal '<input type="checkbox" value="1"/><label class="option label-after">a</label><input type="checkbox" value="2"/><label class="option label-after">b</label><input type="checkbox" value="3"/><label class="option label-after">c</label>'
486
- end
487
-
488
- it "should support custom :labeler for checkboxsets" do
489
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :labeler=>lambda{|tag, input| input.tag(:div, {}, tag)}).to_s.must_equal '<div><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label></div>'
490
- end
491
-
492
- it "should create set of checkbox buttons with options and values with hashes" do
493
- @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
494
- end
495
-
496
- it "should create set of checkbox buttons with options and values using given method" do
497
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
498
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="checkbox" value="a"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label><label class="option"><input type="checkbox" value="c"/> 3</label>'
499
- end
500
-
501
- it "should support :add_blank option for checkboxset inputs" do
502
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> </label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
503
- end
504
-
505
- it "should use :add_blank option value as prompt if it is a String" do
506
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
507
- end
508
-
509
- it "should respect the :key option for checkbox sets" do
510
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label>'
511
- end
512
-
513
- it "should prefer the :name option to :key option for checkbox sets" do
514
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
515
- end
516
-
517
- it "should prefer the :name and :id option to :key option for checkbox sets" do
518
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.must_equal '<label class="option"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
519
- end
520
-
521
- it "should respect the :error option for checkbox sets" do
522
- @f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input aria-invalid="true" class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
523
- end
524
-
525
- it "should create set of checkbox buttons with fieldsets and legends for optgroups" do
526
- @f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
527
- end
528
-
529
- it "should create set of checkbox buttons with label attributes" do
530
- @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2, :label_attr=>{:foo=>:bar}).to_s.must_equal '<label class="option" foo="bar"><input type="checkbox" value="1"/> 1</label><label class="option" foo="bar"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option" foo="bar"><input type="checkbox" value="3"/> 3</label>'
531
- end
532
-
533
- it "should raise an Error for empty checkbox sets" do
534
- @f.input(:checkboxset, :options=>[], :error=>'foo', :value=>2).to_s.must_equal '<span class="error_message">foo</span>'
535
- end
536
-
537
- it "radio and checkbox inputs should handle :checked option" do
538
- @f.input(:radio, :checked=>true).to_s.must_equal '<input checked="checked" type="radio"/>'
539
- @f.input(:radio, :checked=>false).to_s.must_equal '<input type="radio"/>'
540
- @f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
541
- @f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
542
- end
543
-
544
- it "inputs should handle :autofocus option" do
545
- @f.input(:text, :autofocus=>true).to_s.must_equal '<input autofocus="autofocus" type="text"/>'
546
- @f.input(:text, :autofocus=>false).to_s.must_equal '<input type="text"/>'
547
- end
548
-
549
- it "inputs should handle :required option" do
550
- @f.input(:text, :required=>true).to_s.must_equal '<input required="required" type="text"/>'
551
- @f.input(:text, :required=>false).to_s.must_equal '<input type="text"/>'
552
- end
553
-
554
- it "inputs should handle :disabled option" do
555
- @f.input(:text, :disabled=>true).to_s.must_equal '<input disabled="disabled" type="text"/>'
556
- @f.input(:text, :disabled=>false).to_s.must_equal '<input type="text"/>'
557
- end
558
-
559
- it "inputs should not include options with nil values" do
560
- @f.input(:text, :name=>nil).to_s.must_equal '<input type="text"/>'
561
- @f.input(:textarea, :name=>nil).to_s.must_equal '<textarea></textarea>'
562
- end
563
-
564
- it "inputs should include options with false values" do
565
- @f.input(:text, :name=>false).to_s.must_equal '<input name="false" type="text"/>'
566
- end
567
-
568
- it "should automatically create a label if a :label option is used" do
569
- @f.input(:text, :label=>'Foo', :value=>'foo').to_s.must_equal '<label>Foo: <input type="text" value="foo"/></label>'
570
- end
571
-
572
- it "should set label attributes with :label_attr option" do
573
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.must_equal '<label class="bar">Foo: <input type="text" value="foo"/></label>'
574
- end
575
-
576
- it "should handle implicit labels with checkboxes" do
577
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.must_equal '<input name="a" type="hidden" value="0"/><label><input name="a" type="checkbox" value="foo"/> Foo</label>'
578
- end
579
-
580
- it "should handle implicit labels with :label_position=>:after" do
581
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.must_equal '<label><input type="text" value="foo"/> Foo</label>'
582
- end
583
-
584
- it "should handle implicit labels with checkboxes with :label_position=>:before" do
585
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.must_equal '<input name="a" type="hidden" value="0"/><label>Foo <input name="a" type="checkbox" value="foo"/></label>'
586
- end
587
-
588
- it "should automatically note the input has errors if :error option is used" do
589
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<input aria-invalid="true" class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
590
- end
591
-
592
- it "should add an error message after the label" do
593
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<label>Foo: <input aria-invalid="true" class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
594
- end
595
-
596
- it "should add to existing :class option if :error option is used" do
597
- @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<input aria-invalid="true" class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
598
- end
599
-
600
- it "should respect :error_attr option for setting the attributes for the error message span" do
601
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input aria-invalid="true" class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
602
- end
603
-
604
- it "should use aria-describedby and aria-invalid tags for errors with where the id attribute can be determined" do
605
- @f.input(:text, :error=>'Bad Stuff!', :id=>:bar, :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input aria-describedby="bar_error_message" aria-invalid="true" class="error" id="bar" type="text" value="foo"/><span class="foo error_message" id="bar_error_message">Bad Stuff!</span>'
606
- end
607
-
608
- it "#open should return an opening tag" do
609
- @f.open(:action=>'foo', :method=>'post').to_s.must_equal '<form action="foo" method="post">'
610
- end
611
-
612
- it "#close should return a closing tag" do
613
- @f.close.to_s.must_equal '</form>'
614
- end
615
-
616
- it "#button should return a submit tag" do
617
- @f.button.to_s.must_equal '<input type="submit"/>'
618
- end
619
-
620
- it "#button should accept an options hash" do
621
- @f.button(:name=>'foo', :value=>'bar').to_s.must_equal '<input name="foo" type="submit" value="bar"/>'
622
- end
623
-
624
- it "#button should accept a string to use as a value" do
625
- @f.button('foo').to_s.must_equal '<input type="submit" value="foo"/>'
626
- end
627
-
628
- it "#tag should return a serialized_tag" do
629
- @f.tag(:textarea).to_s.must_equal '<textarea></textarea>'
630
- @f.tag(:textarea, :name=>:foo).to_s.must_equal '<textarea name="foo"></textarea>'
631
- @f.tag(:textarea, {:name=>:foo}, :bar).to_s.must_equal '<textarea name="foo">bar</textarea>'
632
- end
633
-
634
- it "#tag should accept a block" do
635
- @f.tag(:div){@f.tag(:textarea)}.to_s.must_equal '<div><textarea></textarea></div>'
636
- @f.tag(:div, :name=>'a'){@f.tag(:textarea)}.to_s.must_equal '<div name="a"><textarea></textarea></div>'
637
- @f.tag(:div, {:name=>'a'}, ["text"]){@f.tag(:textarea)}.to_s.must_equal '<div name="a">text<textarea></textarea></div>'
638
- end
639
-
640
- it "#tag should accept children as procs" do
641
- @f.tag(:div, {:class=>"foo"}, lambda{|t| t.tag(:input, :class=>t.attr[:class])}).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
642
- end
643
-
644
- it "#tag should accept children as methods" do
645
- o = Object.new
646
- def o.foo(t) t.tag(:input, :class=>t.attr[:class]) end
647
- @f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
648
- end
649
-
650
- it "should have an #inputs method for multiple inputs wrapped in a fieldset" do
651
- @f.inputs([:textarea, :text]).to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
652
- end
653
-
654
- it "should have an #inputs method for multiple inputs wrapped in a fieldset when using an empty block" do
655
- @f.inputs([:textarea, :text]){}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
656
- end
657
-
658
- it "should have default #inputs method accept an :attr option" do
659
- @f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.must_equal '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
660
- end
661
-
662
- it "should have default #inputs method accept a :legend option" do
663
- @f.inputs([:textarea, :text], :legend=>'Inputs').to_s.must_equal '<fieldset class="inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
664
- end
665
-
666
- it "should have default #inputs method accept a :legend_attr option" do
667
- @f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<fieldset class="inputs"><legend class="foo">Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
668
- end
669
-
670
- it "should have an #inputs method take a block and yield to it" do
671
- @f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
672
- end
673
-
674
- it "should have an #inputs method work with both args and block" do
675
- @f.inputs([:textarea]){@f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
676
- end
677
-
678
- it "should have an #inputs method support array arguments and creating inputs with the array as argument list" do
679
- @f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.must_equal '<fieldset class="inputs"><textarea name="foo"></textarea><input id="bar" type="text"/></fieldset>'
680
- end
681
-
682
- it "should have #inputs accept transformer options to modify the options inside the inputs" do
683
- @f.inputs([:textarea, :text], :wrapper=>:div).to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea></div><div><input type="text"/></div></fieldset>'
684
- end
685
-
686
- it "should have #inputs accept :nested_inputs_wrapper options to modify the :input_wrapper option inside the inputs" do
687
- @f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea><input type="text"/></div></fieldset>'
688
- end
689
-
690
- it "should escape tag content" do
691
- @f.tag(:div, {}, ['<p></p>']).to_s.must_equal '<div>&lt;p&gt;&lt;/p&gt;</div>'
692
- end
693
-
694
- it "should not escape raw tag content using Forme::Raw" do
695
- @f.tag(:div, {}, ['<p></p>'.dup.extend(Forme::Raw)]).to_s.must_equal '<div><p></p></div>'
696
- end
697
-
698
- it "should not escape raw tag content using Forme.raw" do
699
- @f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
700
- end
701
-
702
- it "should not escape raw tag content using Form#raw" do
703
- @f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
704
- end
705
-
706
- it "should escape tag content in attribute values" do
707
- @f.tag(:div, :foo=>'<p></p>').to_s.must_equal '<div foo="&lt;p&gt;&lt;/p&gt;"></div>'
708
- end
709
-
710
- it "should not escape raw tag content in attribute values" do
711
- @f.tag(:div, :foo=>Forme.raw('<p></p>')).to_s.must_equal '<div foo="<p></p>"></div>'
712
- end
713
-
714
- it "should format dates, times, and datetimes in ISO format" do
715
- @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
716
- @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
717
- @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
718
- end
719
-
720
- it "should format bigdecimals in standard notation" do
721
- @f.tag(:div, :foo=>BigDecimal('10000.010')).to_s.must_equal '<div foo="10000.01"></div>'
722
- end
723
-
724
- it "inputs should accept a :wrapper option to use a custom wrapper" do
725
- @f.input(:text, :wrapper=>:li).to_s.must_equal '<li><input type="text"/></li>'
726
- end
727
-
728
- it "inputs should accept a :wrapper_attr option to use custom wrapper attributes" do
729
- @f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.must_equal '<li class="foo"><input type="text"/></li>'
730
- end
731
-
732
- it "inputs should accept a :help option to use custom helper text" do
733
- @f.input(:text, :help=>"List type of foo").to_s.must_equal '<input type="text"/><span class="helper">List type of foo</span>'
734
- end
735
-
736
- it "inputs should accept a :helper_attr option for custom helper attributes" do
737
- @f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.must_equal '<input type="text"/><span class="foo helper">List type of foo</span>'
738
- end
739
-
740
- it "inputs should have helper displayed inside wrapper, after error" do
741
- @f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li><input aria-invalid="true" class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
742
- end
743
-
744
- it "inputs should accept a :formatter option to use a custom formatter" do
745
- @f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span class="readonly-text">1</span></label>'
746
- @f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <input type="text" value="1"/></label>'
747
- end
748
-
749
- it "inputs should accept a :labeler option to use a custom labeler" do
750
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
751
- end
752
-
753
- it "inputs handle explicit labels with :label_position=>:after" do
754
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.must_equal '<textarea id="foo"></textarea><label class="label-after" for="foo">bar</label>'
755
- end
756
-
757
- it "inputs handle explicit labels with :key_id" do
758
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :key=>:bar, :key_id=>:foo).to_s.must_equal '<label class="label-before" for="bar_foo">bar</label><textarea id="bar_foo" name="bar"></textarea>'
759
- end
760
-
761
- it "should handle explicit labels with checkboxes" do
762
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.must_equal '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label class="label-after" for="bar">Foo</label>'
763
- end
764
-
765
- it "should handle explicit labels with checkboxes with :label_position=>:before" do
766
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.must_equal '<label class="label-before" for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
767
- end
768
-
769
- it "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
770
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.must_equal '<label>Foo <input id="bar" name="a" type="checkbox" value="foo"/></label>'
771
- end
772
-
773
- it "inputs should accept a :error_handler option to use a custom error_handler" do
774
- @f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo"></textarea>!!! bar'
775
- end
776
-
777
- it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
778
- @f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.must_equal '<ol><textarea></textarea></ol>'
779
- end
780
-
781
- it "inputs should accept a :wrapper=>nil option to not use a wrapper" do
782
- Forme::Form.new(:wrapper=>:li).input(:text, :wrapper=>nil).to_s.must_equal '<input type="text"/>'
783
- end
784
-
785
- it "inputs should accept a :labeler=>nil option to not use a labeler" do
786
- @f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.must_equal '<textarea id="foo"></textarea>'
787
- end
788
-
789
- it "inputs should accept a :error_handler=>nil option to not use an error_handler" do
790
- @f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea aria-invalid="true" class="error" id="foo"></textarea>'
791
- end
792
-
793
- it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
794
- @f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.must_equal '<form><textarea></textarea></form>'
795
- end
796
-
797
- it "#inputs should treat a single hash argument as an options hash with no default inputs" do
798
- @f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.must_equal '<ol><textarea></textarea></ol>'
799
- end
800
-
801
- it "should support setting defaults for inputs at the form level" do
802
- f = Forme::Form.new(:input_defaults=>{'text'=>{:size=>20}, 'textarea'=>{:cols=>80, :rows=>6}})
803
- f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
804
- f.input(:textarea, :name=>"foo").to_s.must_equal '<textarea cols="80" name="foo" rows="6"></textarea>'
805
- end
806
-
807
- it "should work with input_defaults with symbol keys using using inputs with symbol keys" do
808
- f = Forme::Form.new(:input_defaults=>{:text=>{:size=>20}, 'text'=>{:size=>30}})
809
- f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
810
- f.input('text', :name=>"foo").to_s.must_equal '<input name="foo" size="30" type="text"/>'
811
- end
812
-
813
- it "invalid custom transformers should raise an Error" do
814
- proc{Forme::Form.new(:wrapper=>Object.new).input(:text).to_s}.must_raise(Forme::Error)
815
- proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.must_raise(Forme::Error)
816
- proc{@f.input(:textarea, :formatter=>nil).to_s}.must_raise(Forme::Error)
817
- end
818
-
819
- it "should handle :before and :after hook options" do
820
- Forme.form({}, :before=>lambda{|f| f.tag(:input, :type=>:hidden, :name=>:a, :value=>'b')}, :after=>lambda{|f| f.tag(:input, :type=>:hidden, :name=>:c, :value=>'d')}){|f| f.tag(:input)}.to_s.must_equal '<form><input name="a" type="hidden" value="b"/><input/><input name="c" type="hidden" value="d"/></form>'
821
- end
822
- end
823
-
824
- describe "Forme custom" do
825
- it "formatters can be specified as a proc" do
826
- Forme::Form.new(:formatter=>proc{|i| i.tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.must_equal '<textarea foo="name"></textarea>'
827
- end
828
-
829
- it "serializers can be specified as a proc" do
830
- Forme::Form.new(:serializer=>proc{|t| "#{t.type} = #{t.opts[:name]}"}).input(:textarea, :name=>'foo').to_s.must_equal 'textarea = foo'
831
- end
832
-
833
- it "labelers can be specified as a proc" do
834
- Forme::Form.new(:labeler=>proc{|t, i| ["#{i.opts[:label]}: ", t]}).input(:textarea, :name=>'foo', :label=>'bar').to_s.must_equal 'bar: <textarea name="foo"></textarea>'
835
- end
836
-
837
- it "error_handlers can be specified as a proc" do
838
- Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.must_equal '<textarea aria-invalid="true" class="error" name="foo"></textarea>!!! bar'
839
- end
840
-
841
- it "wrappers can be specified as a proc" do
842
- Forme::Form.new(:wrapper=>proc{|t, i| t.tag(:div, {:bar=>i.opts[:name]}, t)}).input(:textarea, :name=>'foo').to_s.must_equal '<div bar="foo"><textarea name="foo"></textarea></div>'
843
- end
844
-
845
- it "inputs_wrappers can be specified as a proc" do
846
- Forme::Form.new(:inputs_wrapper=>proc{|f, opts, &block| f.tag(:div, &block)}).inputs([:textarea]).to_s.must_equal '<div><textarea></textarea></div>'
847
- end
848
-
849
- it "can use nil as value to disable default transformer" do
850
- Forme::Form.new(:labeler=>nil).input(:textarea, :label=>'foo').to_s.must_equal '<textarea></textarea>'
851
- end
852
- end
853
-
854
- describe "Forme built-in custom" do
855
- it "transformers should raise if the there is no matching transformer" do
856
- proc{Forme::Form.new(:formatter=>:foo).input(:text).to_s}.must_raise(Forme::Error)
857
- end
858
-
859
- it "formatter: disabled disables all inputs unless :disabled=>false option" do
860
- Forme::Form.new(:formatter=>:disabled).input(:textarea).to_s.must_equal '<textarea disabled="disabled"></textarea>'
861
- Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.must_equal '<textarea></textarea>'
862
- end
863
-
864
- it "formatter: readonly uses spans for text input fields and disables radio/checkbox fields" do
865
- Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span class=\"readonly-text\">Bar</span></label>"
866
- Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
867
- Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
868
- Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
869
- Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
870
- Forme::Form.new(:formatter=>:readonly).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "<label>Foo: <span>2</span></label>"
871
- end
872
-
873
- it "formatter: readonly removes hidden inputs" do
874
- Forme::Form.new(:formatter=>:readonly).input(:hidden, :value=>"Bar").to_s.must_equal ""
875
- end
876
-
877
- it "formatter: readonly formats text into paragraphs for textarea inputs" do
878
- Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>"\n Bar\nBaz\n\nQuuz\n\n1\n2 \n").to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\"><p> Bar<br />Baz</p><p>Quuz</p><p>1<br />2 </p></div></label>"
879
- end
880
-
881
- it "formatter: readonly does not format nil, raw string, or non-string inputs" do
882
- Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo").to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\"></div></label>"
883
- Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>Forme.raw("Bar\n\nBaz")).to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\">Bar\n\nBaz</div></label>"
884
- Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>1).to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\">1</div></label>"
885
- end
886
-
887
- it "formatter: readonly should ignore submit buttons" do
888
- Forme.form({}, :formatter=>:readonly, :button=>'a').to_s.must_equal '<form></form>'
889
- end
890
-
891
- it "labeler: explicit uses an explicit label with for attribute" do
892
- Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
893
- end
894
-
895
- it "labeler: explicit handles the key option correctly" do
896
- Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
897
- end
898
-
899
- it "labeler: explicit should handle tags with errors" do
900
- Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><input aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo" type="text" value="f"/><span class="error_message" id="foo_error_message">Bad Stuff!</span>'
901
- end
902
-
903
- it "wrapper: li wraps tag in an li" do
904
- Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo').to_s.must_equal '<li><textarea id="foo"></textarea></li>'
905
- Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<li id="bar"><textarea id="foo"></textarea></li>'
906
- end
907
-
908
- it "wrapper: p wraps tag in an p" do
909
- Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo').to_s.must_equal '<p><textarea id="foo"></textarea></p>'
910
- Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<p id="bar"><textarea id="foo"></textarea></p>'
911
- end
912
-
913
- it "wrapper: div wraps tag in an div" do
914
- Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo').to_s.must_equal '<div><textarea id="foo"></textarea></div>'
915
- Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<div id="bar"><textarea id="foo"></textarea></div>'
916
- end
917
-
918
- it "wrapper: span wraps tag in an span" do
919
- Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo').to_s.must_equal '<span><textarea id="foo"></textarea></span>'
920
- Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<span id="bar"><textarea id="foo"></textarea></span>'
921
- end
922
-
923
- it "wrapper: td wraps tag in an td" do
924
- Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo').to_s.must_equal '<td><textarea id="foo"></textarea></td>'
925
- Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<td id="bar"><textarea id="foo"></textarea></td>'
926
- end
927
-
928
- it "wrapper: trtd wraps tag in an tr/td" do
929
- Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo').to_s.must_equal '<tr><td><textarea id="foo"></textarea></td><td></td></tr>'
930
- Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<tr id="bar"><td><textarea id="foo"></textarea></td><td></td></tr>'
931
- end
932
-
933
- it "wrapper: trtd supports multiple tags in separate tds" do
934
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
935
- end
936
-
937
- it "wrapper: trtd should use at most 2 td tags" do
938
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo"></textarea><span class="error_message" id="foo_error_message">Bar</span></td></tr>'
939
- end
940
-
941
- it "wrapper: trtd should handle inputs with label after" do
942
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-after" for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
943
- end
944
-
945
- it "wrapper: tr should use a td wrapper and tr inputs_wrapper" do
946
- Forme::Form.new(:wrapper=>:tr).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
947
- f = Forme::Form.new
948
- f.with_opts(:wrapper=>:tr){f.inputs([:textarea])}.to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
949
- end
950
-
951
- it "wrapper: table should use a trtd wrapper and table inputs_wrapper" do
952
- Forme::Form.new(:wrapper=>:table).inputs([:textarea]).to_s.must_equal '<table><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
953
- f = Forme::Form.new
954
- f.with_opts(:wrapper=>:table){f.inputs([:textarea])}.to_s.must_equal '<table><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
955
- end
956
-
957
- it "wrapper: ol should use an li wrapper and ol inputs_wrapper" do
958
- Forme::Form.new(:wrapper=>:ol).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
959
- f = Forme::Form.new
960
- f.with_opts(:wrapper=>:ol){f.inputs([:textarea])}.to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
961
- end
962
-
963
- it "wrapper: fieldset_ol should use an li wrapper and fieldset_ol inputs_wrapper" do
964
- Forme::Form.new(:wrapper=>:fieldset_ol).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
965
- f = Forme::Form.new
966
- f.with_opts(:wrapper=>:fieldset_ol){f.inputs([:textarea])}.to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
967
- end
968
-
969
- it "wrapper should not override inputs_wrapper if both given" do
970
- Forme::Form.new(:wrapper=>:tr, :inputs_wrapper=>:div).inputs([:textarea]).to_s.must_equal '<div><td><textarea></textarea></td></div>'
971
- f = Forme::Form.new
972
- f.with_opts(:wrapper=>:tr, :inputs_wrapper=>:div){f.inputs([:textarea])}.to_s.must_equal '<div><td><textarea></textarea></td></div>'
973
- end
974
-
975
- it "inputs_wrapper: ol wraps tags in an ol" do
976
- Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
977
- Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<ol foo="1"><li><textarea></textarea></li></ol>'
978
- end
979
-
980
- it "inputs_wrapper: fieldset_ol wraps tags in a fieldset and an ol" do
981
- Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
982
- Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<fieldset class="inputs" foo="1"><ol><li><textarea></textarea></li></ol></fieldset>'
983
- end
984
-
985
- it "inputs_wrapper: fieldset_ol supports a :legend option" do
986
- Forme.form({}, :inputs_wrapper=>:fieldset_ol, :wrapper=>:li, :legend=>'Foo', :inputs=>[:textarea]).to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><ol><li><textarea></textarea></li></ol></fieldset></form>'
987
- end
988
-
989
- it "inputs_wrapper: div wraps tags in a div" do
990
- Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea]).to_s.must_equal '<div><span><textarea></textarea></span></div>'
991
- Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<div foo="1"><span><textarea></textarea></span></div>'
992
- end
993
-
994
- it "inputs_wrapper: tr wraps tags in an tr" do
995
- Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
996
- Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<tr foo="1"><td><textarea></textarea></td></tr>'
997
- end
998
-
999
- it "inputs_wrapper: table wraps tags in an table" do
1000
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea]).to_s.must_equal '<table><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
1001
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<table foo="1"><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
1002
- end
1003
-
1004
- it "inputs_wrapper: table accepts a :legend option" do
1005
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs').to_s.must_equal '<table><caption>Inputs</caption><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
1006
- end
1007
-
1008
- it "inputs_wrapper: table accepts a :legend_attr option" do
1009
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<table><caption class="foo">Inputs</caption><tbody><tr><td><textarea></textarea></td><td></td></tr></tbody></table>'
1010
- end
1011
-
1012
- it "inputs_wrapper: table accepts a :labels option" do
1013
- Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.must_equal '<table><thead><tr><th>A</th><th>B</th><th>C</th></tr></thead><tbody></tbody></table>'
1014
- end
1015
-
1016
- it "inputs_wrapper: table doesn't add empty header row for :labels=>[]" do
1017
- Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>[]).to_s.must_equal '<table><tbody></tbody></table>'
1018
- end
1019
-
1020
- it "serializer: html_usa formats dates and datetimes in American format without timezones" do
1021
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="06/05/2011"></div>'
1022
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02PM"></div>'
1023
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02AM"></div>'
1024
- end
1025
-
1026
- it "serializer: html_usa should convert date and datetime inputs into text inputs" do
1027
- Forme::Form.new(:serializer=>:html_usa).input(:date, :value=>Date.new(2011, 6, 5)).to_s.must_equal '<input type="text" value="06/05/2011"/>'
1028
- Forme::Form.new(:serializer=>:html_usa).input(:datetime, :value=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<input type="text" value="06/05/2011 04:03:02PM"/>'
1029
- end
1030
-
1031
- it "serializer: text uses plain text output instead of html" do
1032
- Forme::Form.new(:serializer=>:text).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
1033
- Forme::Form.new(:serializer=>:text).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
1034
- Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
1035
- Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
1036
- Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
1037
- Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
1038
- Forme::Form.new(:serializer=>:text).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "Foo: \n___ 1\n_X_ 2\n___ 3\n\n"
1039
- Forme::Form.new(:serializer=>:text).input(:password, :label=>"Pass").to_s.must_equal "Pass: ********\n\n"
1040
- Forme::Form.new(:serializer=>:text).button().to_s.must_equal ""
1041
- Forme::Form.new(:serializer=>:text).inputs([[:textarea, {:label=>"Foo", :value=>"Bar"}]], :legend=>'Baz').to_s.must_equal "Baz\n---\nFoo: Bar\n\n"
1042
- Forme::Form.new(:serializer=>:text).tag(:p){|f| f.input(:textarea, :label=>"Foo", :value=>"Bar")}.to_s.must_equal "Foo: Bar\n\n"
1043
- Forme::Form.new(:serializer=>:text).tag(:p, {}, ['a']).to_s.must_equal "a"
1044
- end
1045
- end
1046
-
1047
- describe "Forme registering custom transformers" do
1048
- it "should have #register_transformer register a transformer object for later use" do
1049
- Forme.register_transformer(:wrapper, :div2, proc{|t, i| i.tag(:div2, {}, [t])})
1050
- Forme::Form.new(:wrapper=>:div2).input(:textarea).to_s.must_equal '<div2><textarea></textarea></div2>'
1051
- end
1052
-
1053
- it "should have #register_transformer register a transformer block for later use" do
1054
- Forme.register_transformer(:wrapper, :div1){|t, i| i.tag(:div1, {}, [t])}
1055
- Forme::Form.new(:wrapper=>:div1).input(:textarea).to_s.must_equal '<div1><textarea></textarea></div1>'
1056
- end
1057
-
1058
- it "should have #register_transformer raise an error if given a block and an object" do
1059
- proc do
1060
- Forme.register_transformer(:wrapper, :div1, proc{|t, i| t}){|t, i| i.tag(:div1, {}, [t])}
1061
- end.must_raise(Forme::Error)
1062
- end
1063
- end
1064
-
1065
- describe "Forme configurations" do
1066
- after do
1067
- Forme.default_config = :default
1068
- end
1069
-
1070
- it "config: :formastic uses fieldset_ol inputs_wrapper and li wrapper, and explicit labeler" do
1071
- Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
1072
- end
1073
-
1074
- it "should be able to set a default configuration with Forme.default_config=" do
1075
- Forme.default_config = :formtastic
1076
- Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
1077
- end
1078
-
1079
- it "should have #register_config register a configuration for later use" do
1080
- Forme.register_config(:foo, :wrapper=>:li, :labeler=>:explicit)
1081
- Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.must_equal '<li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li>'
1082
- end
1083
-
1084
- it "should have #register_config support a :base option to base it on an existing config" do
1085
- Forme.register_config(:foo2, :labeler=>:default, :base=>:formtastic)
1086
- Forme::Form.new(:config=>:foo2).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label>Foo: <textarea id="foo"></textarea></label></li></ol></fieldset>'
1087
- end
1088
-
1089
- end
1090
-
1091
- describe "Forme object forms" do
1092
- it "should handle a simple case" do
1093
- obj = Class.new{def forme_input(form, field, opts) form._input(:text, :name=>"obj[#{field}]", :id=>"obj_#{field}", :value=>"#{field}_foo") end}.new
1094
- Forme::Form.new(obj).input(:field).to_s.must_equal '<input id="obj_field" name="obj[field]" type="text" value="field_foo"/>'
1095
- end
1096
-
1097
- it "should handle more complex case with multiple different types and opts" do
1098
- obj = Class.new do
1099
- def self.name() "Foo" end
1100
-
1101
- attr_reader :x, :y
1102
-
1103
- def initialize(x, y)
1104
- @x, @y = x, y
1105
- end
1106
- def forme_input(form, field, opts={})
1107
- t = opts[:type]
1108
- t ||= (field == :x ? :textarea : :text)
1109
- s = field.to_s
1110
- form._input(t, {:label=>s.upcase, :name=>"foo[#{s}]", :id=>"foo_#{s}", :value=>send(field)}.merge!(opts))
1111
- end
1112
- end.new('&foo', 3)
1113
- f = Forme::Form.new(obj)
1114
- f.input(:x).to_s.must_equal '<label>X: <textarea id="foo_x" name="foo[x]">&amp;foo</textarea></label>'
1115
- f.input(:y, :attr=>{:brain=>'no'}).to_s.must_equal '<label>Y: <input brain="no" id="foo_y" name="foo[y]" type="text" value="3"/></label>'
1116
- end
1117
-
1118
- it "should handle case where obj doesn't respond to forme_input" do
1119
- Forme::Form.new([:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
1120
- obj = Class.new{attr_accessor :foo}.new
1121
- obj.foo = 'bar'
1122
- Forme::Form.new(obj).input(:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="bar"/>'
1123
- end
1124
-
1125
- it "should respect opts hash when obj doesn't respond to forme_input" do
1126
- Forme::Form.new([:foo]).input(:first, :name=>'bar').to_s.must_equal '<input id="first" name="bar" type="text" value="foo"/>'
1127
- Forme::Form.new([:foo]).input(:first, :id=>'bar').to_s.must_equal '<input id="bar" name="first" type="text" value="foo"/>'
1128
- Forme::Form.new([:foo]).input(:first, :value=>'bar').to_s.must_equal '<input id="first" name="first" type="text" value="bar"/>'
1129
- Forme::Form.new([:foo]).input(:first, :attr=>{:x=>'bar'}).to_s.must_equal '<input id="first" name="first" type="text" value="foo" x="bar"/>'
1130
- end
1131
-
1132
- it "should respect current namespace" do
1133
- Forme::Form.new([:foo], :namespace=>'a').input(:first).to_s.must_equal '<input id="a_first" name="a[first]" type="text" value="foo"/>'
1134
- end
1135
-
1136
- it "should get values for hashes using #[]" do
1137
- Forme::Form.new(:obj=>{:bar=>:foo}, :namespace=>'a').input(:bar).to_s.must_equal '<input id="a_bar" name="a[bar]" type="text" value="foo"/>'
1138
- end
1139
-
1140
- it "should handle obj passed in via :obj hash key" do
1141
- Forme::Form.new(:obj=>[:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
1142
- end
1143
-
1144
- it "should be able to turn off obj handling per input using :obj=>nil option" do
1145
- Forme::Form.new([:foo]).input(:checkbox, :name=>"foo", :hidden_value=>"no", :obj=>nil).to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
1146
- end
1147
-
1148
- it "should be able to change input type" do
1149
- Forme::Form.new([:foo]).input(:first, :type=>:email).to_s.must_equal '<input id="first" name="first" type="email" value="foo"/>'
1150
- end
1151
-
1152
- it "should not have default value for file input" do
1153
- Forme::Form.new([:foo]).input(:first, :type=>:file).to_s.must_equal '<input id="first" name="first" type="file"/>'
1154
- end
1155
-
1156
- it "should be able to set value for file input" do
1157
- Forme::Form.new([:foo]).input(:first, :type=>:file, :value=>"foo").to_s.must_equal '<input id="first" name="first" type="file" value="foo"/>'
1158
- end
1159
- end
1160
-
1161
- describe "Forme.form DSL" do
1162
- it "should return a form tag" do
1163
- Forme.form.to_s.must_equal '<form></form>'
1164
- end
1165
-
1166
- it "should yield a Form object to the block" do
1167
- Forme.form{|f| f.must_be_kind_of(Forme::Form)}
1168
- end
1169
-
1170
- it "should respect an array of classes" do
1171
- Forme.form(:class=>[:foo, :bar]).to_s.must_equal '<form class="foo bar"></form>'
1172
- Forme.form(:class=>[:foo, [:bar, :baz]]).to_s.must_equal '<form class="foo bar baz"></form>'
1173
- end
1174
-
1175
- it "should have inputs called instead the block be added to the existing form" do
1176
- Forme.form{|f| f.input(:text)}.to_s.must_equal '<form><input type="text"/></form>'
1177
- end
1178
-
1179
- it "should be able to nest inputs inside tags" do
1180
- Forme.form{|f| f.tag(:div){f.input(:text)}}.to_s.must_equal '<form><div><input type="text"/></div></form>'
1181
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text)}}}.to_s.must_equal '<form><div><fieldset><input type="text"/></fieldset></div></form>'
1182
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.tag(:span){f.input(:text)}}}}.to_s.must_equal '<form><div><fieldset><span><input type="text"/></span></fieldset></div></form>'
1183
- Forme.form{|f| f.tag(:div){f.input(:text)}; f.input(:radio)}.to_s.must_equal '<form><div><input type="text"/></div><input type="radio"/></form>'
1184
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text); f.input(:radio)}; f.input(:checkbox)}}.to_s.must_equal '<form><div><fieldset><input type="text"/><input type="radio"/></fieldset><input type="checkbox"/></div></form>'
1185
- end
1186
-
1187
- it "should handle an :inputs option to automatically create inputs" do
1188
- Forme.form({}, :inputs=>[:text, :textarea]).to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset></form>'
1189
- end
1190
-
1191
- it "should handle a :legend option if inputs is used" do
1192
- Forme.form({}, :inputs=>[:text, :textarea], :legend=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><input type="text"/><textarea></textarea></fieldset></form>'
1193
- end
1194
-
1195
- it "should still work with a block if :inputs is used" do
1196
- Forme.form({}, :inputs=>[:text]){|f| f.input(:textarea)}.to_s.must_equal '<form><fieldset class="inputs"><input type="text"/></fieldset><textarea></textarea></form>'
1197
- end
1198
-
1199
- it "should handle an :button option to automatically create a button" do
1200
- Forme.form({}, :button=>'Foo').to_s.must_equal '<form><input type="submit" value="Foo"/></form>'
1201
- end
1202
-
1203
- it "should allow :button option value to be a hash" do
1204
- Forme.form({}, :button=>{:value=>'Foo', :name=>'bar'}).to_s.must_equal '<form><input name="bar" type="submit" value="Foo"/></form>'
1205
- end
1206
-
1207
- it "should handle an :button option work with a block" do
1208
- Forme.form({}, :button=>'Foo'){|f| f.input(:textarea)}.to_s.must_equal '<form><textarea></textarea><input type="submit" value="Foo"/></form>'
1209
- end
1210
-
1211
- it "should have an :button and :inputs option work together" do
1212
- Forme.form({}, :inputs=>[:text, :textarea], :button=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset><input type="submit" value="Foo"/></form>'
1213
- end
1214
-
1215
- end
1216
-