forme 2.1.0 → 2.2.0

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