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/bs3_spec.rb CHANGED
@@ -11,119 +11,123 @@ describe "Forme Bootstrap3 (BS3) forms" do
11
11
  end
12
12
 
13
13
  it "should create a simple input tags" do
14
- @f.input(:text).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
15
- @f.input(:radio).to_s.must_equal '<div class="radio"><input type="radio"/></div>'
16
- @f.input(:password).to_s.must_equal '<div class="form-group"><input class="form-control" type="password"/></div>'
17
- @f.input(:checkbox).to_s.must_equal '<div class="checkbox"><input type="checkbox"/></div>'
18
- @f.input(:submit).to_s.must_equal '<input class="btn btn-default" type="submit"/>'
14
+ @f.input(:text).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
15
+ @f.input(:radio).must_equal '<div class="radio"><input type="radio"/></div>'
16
+ @f.input(:password).must_equal '<div class="form-group"><input class="form-control" type="password"/></div>'
17
+ @f.input(:checkbox).must_equal '<div class="checkbox"><input type="checkbox"/></div>'
18
+ @f.input(:submit).must_equal '<input class="btn btn-default" type="submit"/>'
19
19
  end
20
20
 
21
+ it "should remove form-control class from attributes for checkbox tag" do
22
+ @f.tag(:input, :type=>:checkbox, :class=>'form-control').must_equal '<input type="checkbox"/>'
23
+ end
24
+
21
25
  it "should use :name option as attribute" do
22
- @f.input(:text, :name=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" name="foo" type="text"/></div>'
26
+ @f.input(:text, :name=>"foo").must_equal '<div class="form-group"><input class="form-control" name="foo" type="text"/></div>'
23
27
  end
24
28
 
25
29
  it "should use :id option as attribute" do
26
- @f.input(:text, :id=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" type="text"/></div>'
30
+ @f.input(:text, :id=>"foo").must_equal '<div class="form-group"><input class="form-control" id="foo" type="text"/></div>'
27
31
  end
28
32
 
29
33
  it "should use :class option as attribute" do
30
- @f.input(:text, :class=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control foo" type="text"/></div>'
34
+ @f.input(:text, :class=>"foo").must_equal '<div class="form-group"><input class="form-control foo" type="text"/></div>'
31
35
  end
32
36
 
33
37
  it "should use :value option as attribute" do
34
- @f.input(:text, :value=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" type="text" value="foo"/></div>'
38
+ @f.input(:text, :value=>"foo").must_equal '<div class="form-group"><input class="form-control" type="text" value="foo"/></div>'
35
39
  end
36
40
 
37
41
  it "should use :placeholder option as attribute" do
38
- @f.input(:text, :placeholder=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" placeholder="foo" type="text"/></div>'
42
+ @f.input(:text, :placeholder=>"foo").must_equal '<div class="form-group"><input class="form-control" placeholder="foo" type="text"/></div>'
39
43
  end
40
44
 
41
45
  it "should use :style option as attribute" do
42
- @f.input(:text, :style=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" style="foo" type="text"/></div>'
46
+ @f.input(:text, :style=>"foo").must_equal '<div class="form-group"><input class="form-control" style="foo" type="text"/></div>'
43
47
  end
44
48
 
45
49
  it "should use :key option as name and id attributes" do
46
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text"/></div>'
50
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text"/></div>'
47
51
  end
48
52
 
49
53
  it "should use :key_id option as suffix for :key option id attributes" do
50
- @f.input(:text, :key=>"foo", :key_id=>'bar').to_s.must_equal '<div class="form-group"><input class="form-control" id="foo_bar" name="foo" type="text"/></div>'
54
+ @f.input(:text, :key=>"foo", :key_id=>'bar').must_equal '<div class="form-group"><input class="form-control" id="foo_bar" name="foo" type="text"/></div>'
51
55
  end
52
56
 
53
57
  it "should have :key option respect :multiple option" do
54
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo[]" type="text"/></div>'
58
+ @f.input(:text, :key=>"foo", :multiple=>true).must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo[]" type="text"/></div>'
55
59
  end
56
60
 
57
61
  it "should use :key option respect form's current namespace" do
58
62
  @f.with_opts(:namespace=>['bar']) do
59
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
60
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo][]" type="text"/></div>'
63
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
64
+ @f.input(:text, :key=>"foo", :multiple=>true).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo][]" type="text"/></div>'
61
65
  @f.with_opts(:namespace=>['bar', 'baz']) do
62
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_baz_foo" name="bar[baz][foo]" type="text"/></div>'
66
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="bar_baz_foo" name="bar[baz][foo]" type="text"/></div>'
63
67
  end
64
68
  end
65
69
  end
66
70
 
67
71
  it "should consider form's :values hash for default values based on the :key option if :value is not present" do
68
72
  @f.opts[:values] = {'foo'=>'baz'}
69
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
70
- @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="x"/></div>'
73
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
74
+ @f.input(:text, :key=>"foo", :value=>'x').must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="x"/></div>'
71
75
 
72
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
76
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
73
77
  @f.opts[:values] = {:foo=>'baz'}
74
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
78
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="foo" name="foo" type="text" value="baz"/></div>'
75
79
  end
76
80
 
77
81
  it "should consider form's :values hash for default values based on the :key option when using namespaces" do
78
82
  @f.opts[:values] = {'bar'=>{'foo'=>'baz'}}
79
83
  @f.with_opts(:namespace=>['bar']) do
80
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
81
- @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="x"/></div>'
82
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
84
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
85
+ @f.input(:text, :key=>"foo", :value=>'x').must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="x"/></div>'
86
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
83
87
  end
84
88
 
85
89
  @f.with_opts(:namespace=>[:bar]) do
86
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
90
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
87
91
 
88
92
  @f.opts[:values] = {:bar=>{:foo=>'baz'}}
89
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
93
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text" value="baz"/></div>'
90
94
  @f.opts[:values] = {:bar=>{}}
91
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
95
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
92
96
  @f.opts[:values] = {}
93
- @f.input(:text, :key=>:foo).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
97
+ @f.input(:text, :key=>:foo).must_equal '<div class="form-group"><input class="form-control" id="bar_foo" name="bar[foo]" type="text"/></div>'
94
98
 
95
99
  @f.opts[:values] = {'bar'=>{'quux'=>{'foo'=>'baz'}}}
96
100
  @f.with_opts(:namespace=>['bar', 'quux']) do
97
- @f.input(:text, :key=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/></div>'
101
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group"><input class="form-control" id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/></div>'
98
102
  end
99
103
  end
100
104
  end
101
105
 
102
106
  it "should consider form's :errors hash based on the :key option" do
103
107
  @f.opts[:errors] = { 'foo' => 'must be present' }
104
- @f.input(:text, :key=>"foo").to_s.must_equal "<div class=\"form-group has-error\"><input aria-describedby=\"foo_error_message\" aria-invalid=\"true\" class=\"form-control\" id=\"foo\" name=\"foo\" type=\"text\"/><span class=\"help-block with-errors\">must be present</span></div>"
108
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group has-error"><input aria-describedby="foo_error_message" aria-invalid="true" class="form-control" id="foo" name="foo" type="text"/><span class="help-block with-errors" id="foo_error_message">must be present</span></div>'
105
109
  end
106
110
 
107
111
  it "should consider form's :errors hash based on the :key option when using namespaces" do
108
112
  @f.opts[:errors] = { 'bar' => { 'foo' => 'must be present' } }
109
113
  @f.with_opts(:namespace=>['bar']) do
110
- @f.input(:text, :key=>"foo").to_s.must_equal "<div class=\"form-group has-error\"><input aria-describedby=\"bar_foo_error_message\" aria-invalid=\"true\" class=\"form-control\" id=\"bar_foo\" name=\"bar[foo]\" type=\"text\"/><span class=\"help-block with-errors\">must be present</span></div>"
114
+ @f.input(:text, :key=>"foo").must_equal '<div class="form-group has-error"><input aria-describedby="bar_foo_error_message" aria-invalid="true" class="form-control" id="bar_foo" name="bar[foo]" type="text"/><span class="help-block with-errors" id="bar_foo_error_message">must be present</span></div>'
111
115
  end
112
116
  end
113
117
 
114
118
  it "should support a with_obj method that changes the object and namespace for the given block" do
115
119
  @f.with_obj([:a, :c], 'bar') do
116
- @f.input(:first).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_first" name="bar[first]" type="text" value="a"/></div>'
120
+ @f.input(:first).must_equal '<div class="form-group"><input class="form-control" id="bar_first" name="bar[first]" type="text" value="a"/></div>'
117
121
  @f.with_obj([:b], 'baz') do
118
- @f.input(:first).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/></div>'
122
+ @f.input(:first).must_equal '<div class="form-group"><input class="form-control" id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/></div>'
119
123
  end
120
124
  @f.with_obj([:b], %w'baz quux') do
121
- @f.input(:first).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/></div>'
125
+ @f.input(:first).must_equal '<div class="form-group"><input class="form-control" id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/></div>'
122
126
  end
123
127
  @f.with_obj([:b]) do
124
- @f.input(:first).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_first" name="bar[first]" type="text" value="b"/></div>'
128
+ @f.input(:first).must_equal '<div class="form-group"><input class="form-control" id="bar_first" name="bar[first]" type="text" value="b"/></div>'
125
129
  end
126
- @f.input(:last).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_last" name="bar[last]" type="text" value="c"/></div>'
130
+ @f.input(:last).must_equal '<div class="form-group"><input class="form-control" id="bar_last" name="bar[last]" type="text" value="c"/></div>'
127
131
  end
128
132
  end
129
133
 
@@ -133,33 +137,33 @@ describe "Forme Bootstrap3 (BS3) forms" do
133
137
  @f.input(:first)
134
138
  @f.input(:last)
135
139
  end
136
- end.to_s.must_equal '<form><div class="form-group"><input class="form-control" id="bar_0_first" name="bar[0][first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="bar_0_last" name="bar[0][last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="bar_1_first" name="bar[1][first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="bar_1_last" name="bar[1][last]" type="text" value="d"/></div></form>'
140
+ end.must_equal '<form><div class="form-group"><input class="form-control" id="bar_0_first" name="bar[0][first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="bar_0_last" name="bar[0][last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="bar_1_first" name="bar[1][first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="bar_1_last" name="bar[1][last]" type="text" value="d"/></div></form>'
137
141
 
138
142
  @f.tag(:form) do
139
143
  @f.each_obj([[:a, :c], [:b, :d]], %w'bar baz') do
140
144
  @f.input(:first)
141
145
  @f.input(:last)
142
146
  end
143
- end.to_s.must_equal '<form><div class="form-group"><input class="form-control" id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></div></form>'
147
+ end.must_equal '<form><div class="form-group"><input class="form-control" id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></div></form>'
144
148
 
145
149
  @f.tag(:form) do
146
150
  @f.each_obj([[:a, :c], [:b, :d]]) do
147
151
  @f.input(:first)
148
152
  @f.input(:last)
149
153
  end
150
- end.to_s.must_equal '<form><div class="form-group"><input class="form-control" id="0_first" name="0[first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="0_last" name="0[last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="1_first" name="1[first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="1_last" name="1[last]" type="text" value="d"/></div></form>'
154
+ end.must_equal '<form><div class="form-group"><input class="form-control" id="0_first" name="0[first]" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="0_last" name="0[last]" type="text" value="c"/></div><div class="form-group"><input class="form-control" id="1_first" name="1[first]" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="1_last" name="1[last]" type="text" value="d"/></div></form>'
151
155
  end
152
156
 
153
157
  it "should allow overriding form inputs on a per-block basis" do
154
- @f.input(:text).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
155
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.must_equal '<div><input class="form-control" type="text"/></div>'
156
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s.must_equal '<div><input class="form-control" type="text"/></div>'}
158
+ @f.input(:text).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
159
+ @f.with_opts(:wrapper=>:div){@f.input(:text)}.must_equal '<div><input class="form-control" type="text"/></div>'
160
+ @f.with_opts(:wrapper=>:div){@f.input(:text).must_equal '<div><input class="form-control" type="text"/></div>'}
157
161
  @f.with_opts(:wrapper=>:div) do
158
- @f.input(:text).to_s.must_equal '<div><input class="form-control" type="text"/></div>'
159
- @f.with_opts(:wrapper=>:li){@f.input(:text).to_s.must_equal '<li><input class="form-control" type="text"/></li>'}
160
- @f.input(:text).to_s.must_equal '<div><input class="form-control" type="text"/></div>'
162
+ @f.input(:text).must_equal '<div><input class="form-control" type="text"/></div>'
163
+ @f.with_opts(:wrapper=>:li){@f.input(:text).must_equal '<li><input class="form-control" type="text"/></li>'}
164
+ @f.input(:text).must_equal '<div><input class="form-control" type="text"/></div>'
161
165
  end
162
- @f.input(:text).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
166
+ @f.input(:text).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
163
167
  end
164
168
 
165
169
  it "should handle delayed formatting when overriding form inputs on a per-block basis" do
@@ -171,7 +175,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
171
175
  @f.input(:text)
172
176
  end
173
177
  @f.input(:text)
174
- end.to_s.must_equal '<form><div class="form-group"><input class="form-control" type="text"/></div><div><input class="form-control" type="text"/></div><li><input class="form-control" type="text"/></li><div><input class="form-control" type="text"/></div><div class="form-group"><input class="form-control" type="text"/></div></form>'
178
+ end.must_equal '<form><div class="form-group"><input class="form-control" type="text"/></div><div><input class="form-control" type="text"/></div><li><input class="form-control" type="text"/></li><div><input class="form-control" type="text"/></div><div class="form-group"><input class="form-control" type="text"/></div></form>'
175
179
  end
176
180
 
177
181
  it "should support :obj method to with_opts for changing the obj inside the block" do
@@ -181,542 +185,567 @@ describe "Forme Bootstrap3 (BS3) forms" do
181
185
  @f.with_opts(:obj=>[:b]){@f.input(:first)}
182
186
  @f.input(:last)
183
187
  end
184
- end.to_s.must_equal '<form><div class="form-group"><input class="form-control" id="first" name="first" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="first" name="first" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="last" name="last" type="text" value="c"/></div></form>'
188
+ end.must_equal '<form><div class="form-group"><input class="form-control" id="first" name="first" type="text" value="a"/></div><div class="form-group"><input class="form-control" id="first" name="first" type="text" value="b"/></div><div class="form-group"><input class="form-control" id="last" name="last" type="text" value="c"/></div></form>'
185
189
  end
186
190
 
187
191
  it "should allow arbitrary attributes using the :attr option" do
188
- @f.input(:text, :attr=>{:bar=>"foo"}).to_s.must_equal '<div class="form-group"><input bar="foo" class="form-control" type="text"/></div>'
192
+ @f.input(:text, :attr=>{:bar=>"foo"}).must_equal '<div class="form-group"><input bar="foo" class="form-control" type="text"/></div>'
189
193
  end
190
194
 
191
195
  it "should convert the :data option into attributes" do
192
- @f.input(:text, :data=>{:bar=>"foo"}).to_s.must_equal '<div class="form-group"><input class="form-control" data-bar="foo" type="text"/></div>'
196
+ @f.input(:text, :data=>{:bar=>"foo"}).must_equal '<div class="form-group"><input class="form-control" data-bar="foo" type="text"/></div>'
197
+ end
198
+
199
+ it "should support the :dasherize_data option when using the :data option" do
200
+ @f.input(:text, :data=>{:bar_baz=>"foo"}, :dasherize_data=>true).must_equal '<div class="form-group"><input class="form-control" data-bar-baz="foo" type="text"/></div>'
193
201
  end
194
202
 
195
203
  it "should not have standard options override the :attr option" do
196
- @f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.must_equal '<div class="form-group"><input class="form-control" name="foo" type="text"/></div>'
204
+ @f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).must_equal '<div class="form-group"><input class="form-control" name="foo" type="text"/></div>'
197
205
  end
198
206
 
199
207
  it "should combine :class standard option with :attr option" do
200
- @f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.must_equal '<div class="form-group"><input class="form-control foo bar" type="text"/></div>'
208
+ @f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).must_equal '<div class="form-group"><input class="form-control foo bar" type="text"/></div>'
201
209
  end
202
210
 
203
211
  it "should not have :data options override the :attr option" do
204
- @f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.must_equal '<div class="form-group"><input class="form-control" data-bar="foo" type="text"/></div>'
212
+ @f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).must_equal '<div class="form-group"><input class="form-control" data-bar="foo" type="text"/></div>'
205
213
  end
206
214
 
207
215
  it "should use :size and :maxlength options as attributes for text inputs" do
208
- @f.input(:text, :size=>5, :maxlength=>10).to_s.must_equal '<div class="form-group"><input class="form-control" maxlength="10" size="5" type="text"/></div>'
209
- @f.input(:textarea, :size=>5, :maxlength=>10).to_s.must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
216
+ @f.input(:text, :size=>5, :maxlength=>10).must_equal '<div class="form-group"><input class="form-control" maxlength="10" size="5" type="text"/></div>'
217
+ @f.input(:textarea, :size=>5, :maxlength=>10).must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
210
218
  end
211
219
 
212
220
  it "should create hidden input with value 0 for each checkbox with a name" do
213
- @f.input(:checkbox, :name=>"foo").to_s.must_equal '<div class="checkbox"><input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/></div>'
221
+ @f.input(:checkbox, :name=>"foo").must_equal '<div class="checkbox"><input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/></div>'
214
222
  end
215
223
 
216
224
  it "should not create hidden input with value 0 for each checkbox with a name if :no_hidden option is used" do
217
- @f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.must_equal '<div class="checkbox"><input name="foo" type="checkbox"/></div>'
225
+ @f.input(:checkbox, :name=>"foo", :no_hidden=>true).must_equal '<div class="checkbox"><input name="foo" type="checkbox"/></div>'
218
226
  end
219
227
 
220
228
  it "should create hidden input with _hidden appended to id for each checkbox with a name and id" do
221
- @f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.must_equal '<div class="checkbox"><input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/></div>'
229
+ @f.input(:checkbox, :name=>"foo", :id=>"bar").must_equal '<div class="checkbox"><input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/></div>'
222
230
  end
223
231
 
224
232
  it "should create hidden input with value f for each checkbox with a name and value t" do
225
- @f.input(:checkbox, :name=>"foo", :value=>"t").to_s.must_equal '<div class="checkbox"><input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/></div>'
233
+ @f.input(:checkbox, :name=>"foo", :value=>"t").must_equal '<div class="checkbox"><input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/></div>'
226
234
  end
227
235
 
228
236
  it "should use :hidden_value option for value of hidden input for checkbox" do
229
- @f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.must_equal '<div class="checkbox"><input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/></div>'
237
+ @f.input(:checkbox, :name=>"foo", :hidden_value=>"no").must_equal '<div class="checkbox"><input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/></div>'
230
238
  end
231
239
 
232
240
  it "should create hidden input" do
233
- @f.input(:hidden).to_s.must_equal '<input type="hidden"/>'
241
+ @f.input(:hidden).must_equal '<input type="hidden"/>'
234
242
  end
235
243
 
236
244
  it "should handle :checked option" do
237
- @f.input(:checkbox, :checked=>true).to_s.must_equal '<div class="checkbox"><input checked="checked" type="checkbox"/></div>'
238
- @f.input(:checkbox, :checked=>false).to_s.must_equal '<div class="checkbox"><input type="checkbox"/></div>'
245
+ @f.input(:checkbox, :checked=>true).must_equal '<div class="checkbox"><input checked="checked" type="checkbox"/></div>'
246
+ @f.input(:checkbox, :checked=>false).must_equal '<div class="checkbox"><input type="checkbox"/></div>'
239
247
  end
240
248
 
241
249
  it "should create textarea tag" do
242
- @f.input(:textarea).to_s.must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
243
- @f.input(:textarea, :value=>'a').to_s.must_equal '<div class="form-group"><textarea class="form-control">a</textarea></div>'
250
+ @f.input(:textarea).must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
251
+ @f.input(:textarea, :value=>'a').must_equal '<div class="form-group"><textarea class="form-control">a</textarea></div>'
244
252
  end
245
253
 
246
254
  it "should use :cols and :rows options as attributes for textarea inputs" do
247
- @f.input(:text, :cols=>5, :rows=>10).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
248
- @f.input(:textarea, :cols=>5, :rows=>10).to_s.must_equal '<div class="form-group"><textarea class="form-control" cols="5" rows="10"></textarea></div>'
255
+ @f.input(:text, :cols=>5, :rows=>10).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
256
+ @f.input(:textarea, :cols=>5, :rows=>10).must_equal '<div class="form-group"><textarea class="form-control" cols="5" rows="10"></textarea></div>'
249
257
  end
250
258
 
251
259
  it "should create select tag" do
252
- @f.input(:select).to_s.must_equal '<div class="form-group"><select class="form-control"></select></div>'
260
+ @f.input(:select).must_equal '<div class="form-group"><select class="form-control"></select></div>'
253
261
  end
254
262
 
255
263
  it "should respect multiple and size options in select tag" do
256
- @f.input(:select, :multiple=>true, :size=>10).to_s.must_equal '<div class="form-group"><select class="form-control" multiple="multiple" size="10"></select></div>'
264
+ @f.input(:select, :multiple=>true, :size=>10).must_equal '<div class="form-group"><select class="form-control" multiple="multiple" size="10"></select></div>'
257
265
  end
258
266
 
259
267
  it "should create date tag" do
260
- @f.input(:date).to_s.must_equal '<div class="form-group"><input class="form-control" type="date"/></div>'
268
+ @f.input(:date).must_equal '<div class="form-group"><input class="form-control" type="date"/></div>'
261
269
  end
262
270
 
263
271
  it "should create datetime-local tag" do
264
- @f.input(:datetime).to_s.must_equal '<div class="form-group"><input class="form-control" type="datetime-local"/></div>'
272
+ @f.input(:datetime).must_equal '<div class="form-group"><input class="form-control" type="datetime-local"/></div>'
265
273
  end
266
274
 
267
275
  it "should not error for input type :input" do
268
- @f.input(:input).to_s.must_equal '<div class="form-group"><input class="form-control" type="input"/></div>'
276
+ @f.input(:input).must_equal '<div class="form-group"><input class="form-control" type="input"/></div>'
269
277
  end
270
278
 
271
279
  it "should use multiple select boxes for dates if the :as=>:select option is given" do
272
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></div>}
280
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></div>}
273
281
  end
274
282
 
275
283
  it "should allow ordering date select boxes via :order" do
276
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select class="form-control" id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select></div>}
284
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select class="form-control" id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select></div>}
277
285
  end
278
286
 
279
287
  it "should allow only using specific date select boxes via :order" do
280
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select class="form-control" id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select></div>}
288
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).must_equal %{<div class="form-group"><select class="form-control" id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select class="form-control" id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select></div>}
281
289
  end
282
290
 
283
291
  it "should support :select_options for dates when :as=>:select is given" do
284
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></div>}
292
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).must_equal %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></div>}
285
293
  end
286
294
 
287
295
  it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
288
- @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 class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
296
+ @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 class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
289
297
  end
290
298
 
291
299
  it "should use multiple select boxes for datetimes if the :as=>:select option is given" do
292
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select class="form-control" id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select class="form-control" id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select></div>}
300
+ @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).must_equal %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select class="form-control" id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select class="form-control" id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select></div>}
293
301
  end
294
302
 
295
303
  it "should allow ordering select boxes for datetimes via :order" do
296
- @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 %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select class="form-control" id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select></div>}
304
+ @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 %{<div class=\"form-group\"><select class="form-control" id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select class="form-control" id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select></div>}
297
305
  end
298
306
 
299
307
  it "should support :select_options for datetimes when :as=>:select option is given" do
300
- @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 %{<div class="form-group"><select class="form-control" id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select class="form-control" id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select class="form-control" id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select></div>}
308
+ @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 %{<div class="form-group"><select class="form-control" id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select class="form-control" id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select class="form-control" id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select class="form-control" id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select class="form-control" id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select class="form-control" id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select></div>}
301
309
  end
302
310
 
303
311
  it "should create select tag with options" do
304
- @f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
305
- @f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
312
+ @f.input(:select, :options=>[1, 2, 3], :selected=>2).must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
313
+ @f.input(:select, :options=>[1, 2, 3], :value=>2).must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
306
314
  end
307
315
 
308
316
  it "should create select tag with options and values" do
309
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
317
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
310
318
  end
311
319
 
312
320
  it "should create select tag with option groups" do
313
- @f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><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></div>'
321
+ @f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).must_equal '<div class="form-group"><select class="form-control"><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></div>'
314
322
  end
315
323
 
316
324
  it "should create select tag with option groups with attributes" do
317
- @f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><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></div>'
325
+ @f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).must_equal '<div class="form-group"><select class="form-control"><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></div>'
318
326
  end
319
327
 
320
328
  it "should create select tag with options and values with hashes" do
321
- @f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select></div>'
329
+ @f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).must_equal '<div class="form-group"><select class="form-control"><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select></div>'
322
330
  end
323
331
 
324
332
  it "should create select tag with options and values using given method" do
325
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
326
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select></div>'
333
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).must_equal '<div class="form-group"><select class="form-control"><option>1</option><option selected="selected">2</option><option>3</option></select></div>'
334
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).must_equal '<div class="form-group"><select class="form-control"><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select></div>'
327
335
  end
328
336
 
329
337
  it "should use html attributes specified in options" do
330
- @f.input(:text, :value=>'foo', :name=>'bar').to_s.must_equal '<div class="form-group"><input class="form-control" name="bar" type="text" value="foo"/></div>'
331
- @f.input(:textarea, :value=>'foo', :name=>'bar').to_s.must_equal '<div class="form-group"><textarea class="form-control" name="bar">foo</textarea></div>'
332
- @f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.must_equal '<div class="form-group"><select class="form-control" name="bar"><option>1</option><option>2</option><option>3</option></select></div>'
338
+ @f.input(:text, :value=>'foo', :name=>'bar').must_equal '<div class="form-group"><input class="form-control" name="bar" type="text" value="foo"/></div>'
339
+ @f.input(:textarea, :value=>'foo', :name=>'bar').must_equal '<div class="form-group"><textarea class="form-control" name="bar">foo</textarea></div>'
340
+ @f.input(:select, :name=>'bar', :options=>[1, 2, 3]).must_equal '<div class="form-group"><select class="form-control" name="bar"><option>1</option><option>2</option><option>3</option></select></div>'
333
341
  end
334
342
 
335
343
  it "should support :add_blank option for select inputs" do
336
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
344
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).must_equal '<div class="form-group"><select class="form-control"><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
337
345
  end
338
346
 
339
347
  it "should use Forme.default_add_blank_prompt value if :add_blank option is true" do
340
348
  begin
341
349
  Forme.default_add_blank_prompt = 'foo'
342
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
350
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).must_equal '<div class="form-group"><select class="form-control"><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
343
351
  ensure
344
352
  Forme.default_add_blank_prompt = nil
345
353
  end
346
354
  end
347
355
 
348
356
  it "should use :add_blank option value as prompt if it is a String" do
349
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
357
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).must_equal '<div class="form-group"><select class="form-control"><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
350
358
  end
351
359
 
352
360
  it "should support :add_blank option with :blank_position :after for select inputs" do
353
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select></div>'
361
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).must_equal '<div class="form-group"><select class="form-control"><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select></div>'
354
362
  end
355
363
 
356
364
  it "should support :add_blank option with :blank_attr option for select inputs" do
357
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
365
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).must_equal '<div class="form-group"><select class="form-control"><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select></div>'
358
366
  end
359
367
 
360
368
  it "should create set of radio buttons" do
361
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
362
- @f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
369
+ @f.input(:radioset, :options=>[1, 2, 3], :selected=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
370
+ @f.input(:radioset, :options=>[1, 2, 3], :value=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
371
+ end
372
+
373
+ it "should create set of radio buttons" do
374
+ proc{@f.input(:radioset)}.must_raise Forme::Error
375
+ end
376
+
377
+ it "should support radio buttons with nil values" do
378
+ @f.input(:radioset, :options=>[1, 2, nil], :selected=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><input type="radio"/></div></div>'
363
379
  end
364
380
 
365
381
  it "should create set of radio buttons with options and values" do
366
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
382
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
367
383
  end
368
384
 
369
385
  it "should create set of radio buttons with options and values with hashes" do
370
- @f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input foo="1" type="radio" value="a"/> a</label></div><div class="radio"><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label></div><div class="radio"><label class="option" for="baz"><input id="baz" type="radio" value="c"/> c</label></div></div>'
386
+ @f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input foo="1" type="radio" value="a"/> a</label></div><div class="radio"><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label></div><div class="radio"><label class="option" for="baz"><input id="baz" type="radio" value="c"/> c</label></div></div>'
371
387
  end
372
388
 
373
389
  it "should create set of radio buttons with options and values using given method" do
374
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
375
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="a"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="b"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="c"/> 3</label></div></div>'
390
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
391
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="a"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="b"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="c"/> 3</label></div></div>'
376
392
  end
377
393
 
378
394
  it "should support :add_blank option for radioset inputs" do
379
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value=""/> </label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
395
+ @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value=""/> </label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
380
396
  end
381
397
 
382
398
  it "should use :add_blank option value as prompt if it is a String" do
383
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value=""/> Prompt Here</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
399
+ @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value=""/> Prompt Here</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></div>'
384
400
  end
385
401
 
386
402
  it "should respect the :key option for radio sets" do
387
- @f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option" for="foo_1"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label></div><div class="radio"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option" for="foo_3"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label></div></div>'
403
+ @f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).must_equal '<div class="radioset"><div class="radio"><label class="option" for="foo_1"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label></div><div class="radio"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option" for="foo_3"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label></div></div>'
388
404
  end
389
405
 
390
406
  it "should create set of radio buttons with fieldsets and legends for :optgroups" do
391
- @f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<div class="radioset"><fieldset><legend>d</legend><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div></fieldset><fieldset><legend>e</legend><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></fieldset></div>'
407
+ @f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).must_equal '<div class="radioset"><fieldset><legend>d</legend><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> b</label></div></fieldset><fieldset><legend>e</legend><div class="radio"><label class="option"><input type="radio" value="3"/> c</label></div></fieldset></div>'
392
408
  end
393
409
 
394
410
  it "should create set of radio buttons with set label" do
395
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :label=>'foo').to_s.must_equal '<div class="radioset"><label>foo</label><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
411
+ @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :label=>'foo').must_equal '<div class="radioset"><label>foo</label><div class="radio"><label class="option"><input type="radio" value="1"/> 1</label></div><div class="radio"><label class="option"><input checked="checked" type="radio" value="2"/> 2</label></div><div class="radio"><label class="option"><input type="radio" value="3"/> 3</label></div></div>'
396
412
  end
397
413
 
398
414
  it "should create set of checkbox buttons" do
399
- @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
400
- @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
415
+ @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
416
+ @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
401
417
  end
402
418
 
403
419
  it "should create set of checkbox buttons with options and values" do
404
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
420
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
405
421
  end
406
422
 
407
423
  it "should create set of checkbox buttons with options and values with hashes" do
408
- @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input foo="1" type="checkbox" value="a"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option" for="baz"><input id="baz" type="checkbox" value="c"/> c</label></div></div>'
424
+ @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input foo="1" type="checkbox" value="a"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option" for="baz"><input id="baz" type="checkbox" value="c"/> c</label></div></div>'
409
425
  end
410
426
 
411
427
  it "should create set of checkbox buttons with options and values using given method" do
412
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
413
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="a"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="c"/> 3</label></div></div>'
428
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div></div>'
429
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="a"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="c"/> 3</label></div></div>'
414
430
  end
415
431
 
416
432
  it "should support :add_blank option for checkboxset inputs" do
417
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value=""/> </label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
433
+ @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value=""/> </label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
418
434
  end
419
435
 
420
436
  it "should use :add_blank option value as prompt if it is a String" do
421
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value=""/> Prompt Here</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
437
+ @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value=""/> Prompt Here</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></div>'
422
438
  end
423
439
 
424
440
  it "should respect the :key option for checkbox sets" do
425
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="foo_1"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="foo_3"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label></div></div>'
441
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="foo_1"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="foo_3"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label></div></div>'
426
442
  end
427
443
 
428
444
  it "should prefer the :name option to :key option for checkbox sets" do
429
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="foo_1"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="foo_3"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label></div></div>'
445
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="foo_1"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="foo_2"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="foo_3"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label></div></div>'
430
446
  end
431
447
 
432
448
  it "should prefer the :name and :id option to :key option for checkbox sets" do
433
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="baz_1"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="baz_2"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="baz_3"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label></div></div>'
449
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).must_equal '<div class="checkboxset"><div class="checkbox"><label class="option" for="baz_1"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option" for="baz_2"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option" for="baz_3"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label></div></div>'
434
450
  end
435
451
 
436
452
  it "should respect the :error option for checkbox sets" do
437
- @f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo-checkboxset', :value=>2).to_s.must_equal '<div class="checkboxset has-error"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div><span class="help-block with-errors">foo-checkboxset</span></div>'
453
+ @f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo-checkboxset', :value=>2).must_equal '<div class="checkboxset has-error"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> 1</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> 3</label></div><span class="help-block with-errors">foo-checkboxset</span></div>'
438
454
  end
439
455
 
440
456
  it "should create set of checkbox buttons with fieldsets and legends for optgroups" do
441
- @f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<div class="checkboxset"><fieldset><legend>d</legend><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div></fieldset><fieldset><legend>e</legend><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></fieldset></div>'
457
+ @f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).must_equal '<div class="checkboxset"><fieldset><legend>d</legend><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></div></fieldset><fieldset><legend>e</legend><div class="checkbox"><label class="option"><input type="checkbox" value="3"/> c</label></div></fieldset></div>'
442
458
  end
443
459
 
444
460
  it "radio and checkbox inputs should handle :checked option" do
445
- @f.input(:radio, :checked=>true).to_s.must_equal '<div class="radio"><input checked="checked" type="radio"/></div>'
446
- @f.input(:radio, :checked=>false).to_s.must_equal '<div class="radio"><input type="radio"/></div>'
447
- @f.input(:checkbox, :checked=>true).to_s.must_equal '<div class="checkbox"><input checked="checked" type="checkbox"/></div>'
448
- @f.input(:checkbox, :checked=>false).to_s.must_equal '<div class="checkbox"><input type="checkbox"/></div>'
461
+ @f.input(:radio, :checked=>true).must_equal '<div class="radio"><input checked="checked" type="radio"/></div>'
462
+ @f.input(:radio, :checked=>false).must_equal '<div class="radio"><input type="radio"/></div>'
463
+ @f.input(:checkbox, :checked=>true).must_equal '<div class="checkbox"><input checked="checked" type="checkbox"/></div>'
464
+ @f.input(:checkbox, :checked=>false).must_equal '<div class="checkbox"><input type="checkbox"/></div>'
449
465
  end
450
466
 
451
467
  it "inputs should handle :autofocus option" do
452
- @f.input(:text, :autofocus=>true).to_s.must_equal '<div class="form-group"><input autofocus="autofocus" class="form-control" type="text"/></div>'
453
- @f.input(:text, :autofocus=>false).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
468
+ @f.input(:text, :autofocus=>true).must_equal '<div class="form-group"><input autofocus="autofocus" class="form-control" type="text"/></div>'
469
+ @f.input(:text, :autofocus=>false).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
454
470
  end
455
471
 
456
472
  it "inputs should handle :required option" do
457
- @f.input(:text, :required=>true).to_s.must_equal '<div class="form-group"><input class="form-control" required="required" type="text"/></div>'
458
- @f.input(:text, :required=>false).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
473
+ @f.input(:text, :required=>true).must_equal '<div class="form-group"><input class="form-control" required="required" type="text"/></div>'
474
+ @f.input(:text, :required=>false).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
459
475
  end
460
476
 
461
477
  it "inputs should handle :disabled option" do
462
- @f.input(:text, :disabled=>true).to_s.must_equal '<div class="form-group"><input class="form-control" disabled="disabled" type="text"/></div>'
463
- @f.input(:text, :disabled=>false).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
478
+ @f.input(:text, :disabled=>true).must_equal '<div class="form-group"><input class="form-control" disabled="disabled" type="text"/></div>'
479
+ @f.input(:text, :disabled=>false).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
464
480
  end
465
481
 
466
482
  it "inputs should not include options with nil values" do
467
- @f.input(:text, :name=>nil).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
468
- @f.input(:textarea, :name=>nil).to_s.must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
483
+ @f.input(:text, :name=>nil).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
484
+ @f.input(:textarea, :name=>nil).must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
469
485
  end
470
486
 
471
487
  it "inputs should include options with false values" do
472
- @f.input(:text, :name=>false).to_s.must_equal '<div class="form-group"><input class="form-control" name="false" type="text"/></div>'
488
+ @f.input(:text, :name=>false).must_equal '<div class="form-group"><input class="form-control" name="false" type="text"/></div>'
473
489
  end
474
490
 
475
491
  it "should automatically create a label if a :label option is used" do
476
- @f.input(:text, :label=>'Foo', :value=>'foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" type="text" value="foo"/></div>'
492
+ @f.input(:text, :label=>'Foo', :value=>'foo').must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" type="text" value="foo"/></div>'
477
493
  end
478
494
 
479
495
  it "should set label attributes with :label_attr option" do
480
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.must_equal '<div class="form-group"><label class="bar">Foo</label> <input class="form-control" type="text" value="foo"/></div>'
496
+ @f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).must_equal '<div class="form-group"><label class="bar">Foo</label> <input class="form-control" type="text" value="foo"/></div>'
497
+ end
498
+
499
+ it "should support label not referencing input via :for=>false option" do
500
+ @f.input(:text, :id=>'x', :label=>'Foo', :value=>'foo', :label_attr=>{:for=>false}).must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" id="x" type="text" value="foo"/></div>'
481
501
  end
482
502
 
483
503
  it "should handle implicit labels with checkboxes" do
484
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.must_equal '<div class="checkbox"><label><input name="a" type="hidden" value="0"/><input name="a" type="checkbox" value="foo"/> Foo</label></div>'
504
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').must_equal '<div class="checkbox"><label><input name="a" type="hidden" value="0"/><input name="a" type="checkbox" value="foo"/> Foo</label></div>'
485
505
  end
486
506
 
487
507
  it "should handle implicit labels with :label_position=>:after" do
488
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.must_equal '<div class="form-group"><input class="form-control" type="text" value="foo"/> <label>Foo</label></div>'
508
+ @f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).must_equal '<div class="form-group"><input class="form-control" type="text" value="foo"/> <label>Foo</label></div>'
489
509
  end
490
510
 
491
511
  it "should handle implicit labels with checkboxes with :label_position=>:before" do
492
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.must_equal '<div class="checkbox"><label>Foo <input name="a" type="hidden" value="0"/><input name="a" type="checkbox" value="foo"/></label></div>'
512
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).must_equal '<div class="checkbox"><label>Foo <input name="a" type="hidden" value="0"/><input name="a" type="checkbox" value="foo"/></label></div>'
493
513
  end
494
514
 
495
515
  it "should automatically note the input has errors if :error option is used" do
496
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
516
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo').must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
497
517
  end
498
518
 
499
519
  it "should add an error message after the label" do
500
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<div class="form-group has-error"><label>Foo</label> <input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
520
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").must_equal '<div class="form-group has-error"><label>Foo</label> <input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
501
521
  end
502
522
 
503
523
  it "should add to existing :class option if :error option is used" do
504
- @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control bar" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
524
+ @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control bar" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
505
525
  end
506
526
 
507
527
  it "should respect :error_attr option for setting the attributes for the error message span" do
508
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="foo help-block with-errors">Bad Stuff!</span></div>'
528
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="foo help-block with-errors">Bad Stuff!</span></div>'
529
+ end
530
+
531
+ it "should support :skip_error_message option" do
532
+ @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo', :skip_error_message=>true).must_equal '<div class="form-group"><input aria-invalid="true" class="form-control bar" type="text" value="foo"/></div>'
509
533
  end
510
534
 
511
535
  it "#open should return an opening tag" do
512
- @f.open(:action=>'foo', :method=>'post').to_s.must_equal '<form action="foo" method="post">'
536
+ @f.open(:action=>'foo', :method=>'post').must_equal '<form action="foo" method="post">'
513
537
  end
514
538
 
515
539
  it "#close should return a closing tag" do
516
- @f.close.to_s.must_equal '</form>'
540
+ @f.close.must_equal '</form>'
517
541
  end
518
542
 
519
543
  it "#button should return a submit tag" do
520
- @f.button.to_s.must_equal '<input class="btn btn-default" type="submit"/>'
544
+ @f.button.must_equal '<input class="btn btn-default" type="submit"/>'
521
545
  end
522
546
 
523
547
  it "#button should return a submit tag without label" do
524
- @f.button(:label=>'foo').to_s.must_equal '<input class="btn btn-default" type="submit"/>'
548
+ @f.button(:label=>'foo').must_equal '<input class="btn btn-default" type="submit"/>'
525
549
  end
526
550
 
527
551
  it "#button should accept an options hash" do
528
- @f.button(:name=>'foo', :value=>'bar').to_s.must_equal '<input class="btn btn-default" name="foo" type="submit" value="bar"/>'
552
+ @f.button(:name=>'foo', :value=>'bar').must_equal '<input class="btn btn-default" name="foo" type="submit" value="bar"/>'
529
553
  end
530
554
 
531
555
  it "#button should handle added classes" do
532
- @f.button(:class=>'btn btn-primary').to_s.must_equal '<input class="btn btn-primary" type="submit"/>'
533
- @f.button(:class=>'btn-danger').to_s.must_equal '<input class="btn btn-danger" type="submit"/>'
534
- @f.button(:class=>'btn-success btn-lg').to_s.must_equal '<input class="btn btn-success btn-lg" type="submit"/>'
556
+ @f.button(:class=>'btn btn-primary').must_equal '<input class="btn btn-primary" type="submit"/>'
557
+ @f.button(:class=>'btn-danger').must_equal '<input class="btn btn-danger" type="submit"/>'
558
+ @f.button(:class=>'btn-success btn-lg').must_equal '<input class="btn btn-success btn-lg" type="submit"/>'
535
559
  end
536
560
 
537
561
  it "#button should accept a string to use as a value" do
538
- @f.button('foo').to_s.must_equal '<input class="btn btn-default" type="submit" value="foo"/>'
562
+ @f.button('foo').must_equal '<input class="btn btn-default" type="submit" value="foo"/>'
539
563
  end
540
564
 
541
565
  it "#tag should accept children as procs" do
542
- @f.tag(:div, {:class=>"foo"}, lambda{|t| t.tag(:input, :class=>t.attr[:class])}).to_s.must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
566
+ @f.tag(:div, {:class=>"foo"}, lambda{|t| t.tag(:input, :class=>t.attr[:class])}).must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
543
567
  end
544
568
 
545
569
  it "#tag should accept children as methods" do
546
570
  o = Object.new
547
571
  def o.foo(t) t.tag(:input, :class=>t.attr[:class]) end
548
- @f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
572
+ @f.tag(:div, {:class=>"foo"}, o.method(:foo)).must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
549
573
  end
550
574
 
551
575
  it "should have an #inputs method for multiple inputs wrapped in a fieldset" do
552
- @f.inputs([:textarea, :text]).to_s.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
576
+ @f.inputs([:textarea, :text]).must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
553
577
  end
554
578
 
555
579
  it "should have default #inputs method accept an :attr option" do
556
- @f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.must_equal '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
580
+ @f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).must_equal '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
557
581
  end
558
582
 
559
583
  it "should have default #inputs method accept a :legend option" do
560
- @f.inputs([:textarea, :text], :legend=>'Inputs').to_s.must_equal '<fieldset class="inputs"><legend>Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
584
+ @f.inputs([:textarea, :text], :legend=>'Inputs').must_equal '<fieldset class="inputs"><legend>Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
561
585
  end
562
586
 
563
587
  it "should have default #inputs method accept a :legend_attr option" do
564
- @f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<fieldset class="inputs"><legend class="foo">Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
588
+ @f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).must_equal '<fieldset class="inputs"><legend class="foo">Inputs</legend><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
565
589
  end
566
590
 
567
591
  it "should have an #inputs method take a block and yield to it" do
568
- @f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
592
+ @f.inputs{@f.input(:textarea); @f.input(:text)}.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
569
593
  end
570
594
 
571
595
  it "should have an #inputs method work with both args and block" do
572
- @f.inputs([:textarea]){@f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
596
+ @f.inputs([:textarea]){@f.input(:text)}.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></fieldset>'
573
597
  end
574
598
 
575
599
  it "should have an #inputs method support array arguments and creating inputs with the array as argument list" do
576
- @f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control" name="foo"></textarea></div><div class="form-group"><input class="form-control" id="bar" type="text"/></div></fieldset>'
600
+ @f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).must_equal '<fieldset class="inputs"><div class="form-group"><textarea class="form-control" name="foo"></textarea></div><div class="form-group"><input class="form-control" id="bar" type="text"/></div></fieldset>'
577
601
  end
578
602
 
579
603
  it "should have #inputs accept transformer options to modify the options inside the inputs" do
580
- @f.inputs([:textarea, :text], :wrapper=>:div).to_s.must_equal '<fieldset class="inputs"><div><textarea class="form-control"></textarea></div><div><input class="form-control" type="text"/></div></fieldset>'
604
+ @f.inputs([:textarea, :text], :wrapper=>:div).must_equal '<fieldset class="inputs"><div><textarea class="form-control"></textarea></div><div><input class="form-control" type="text"/></div></fieldset>'
581
605
  end
582
606
 
583
607
  it "should have #inputs accept :nested_inputs_wrapper options to modify the :input_wrapper option inside the inputs" do
584
- @f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.must_equal '<fieldset class="inputs"><div><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></div></fieldset>'
608
+ @f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.must_equal '<fieldset class="inputs"><div><div class="form-group"><textarea class="form-control"></textarea></div><div class="form-group"><input class="form-control" type="text"/></div></div></fieldset>'
585
609
  end
586
610
 
587
611
 
588
612
  it "should escape tag content" do
589
- @f.tag(:div, {}, ['<p></p>']).to_s.must_equal '<div>&lt;p&gt;&lt;/p&gt;</div>'
613
+ @f.tag(:div, {}, ['<p></p>']).must_equal '<div>&lt;p&gt;&lt;/p&gt;</div>'
590
614
  end
591
615
 
592
616
  it "should not escape raw tag content using Forme::Raw" do
593
- @f.tag(:div, {}, ['<p></p>'.dup.extend(Forme::Raw)]).to_s.must_equal '<div><p></p></div>'
617
+ @f.tag(:div, {}, ['<p></p>'.dup.extend(Forme::Raw)]).must_equal '<div><p></p></div>'
594
618
  end
595
619
 
596
620
  it "should not escape raw tag content using Forme.raw" do
597
- @f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
621
+ @f.tag(:div, {}, [Forme.raw('<p></p>')]).must_equal '<div><p></p></div>'
598
622
  end
599
623
 
600
624
  it "should not escape raw tag content using Form#raw" do
601
- @f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
625
+ @f.tag(:div, {}, [@f.raw('<p></p>')]).must_equal '<div><p></p></div>'
602
626
  end
603
627
 
604
628
  it "should escape tag content in attribute values" do
605
- @f.tag(:div, :foo=>'<p></p>').to_s.must_equal '<div foo="&lt;p&gt;&lt;/p&gt;"></div>'
629
+ @f.tag(:div, :foo=>'<p></p>').must_equal '<div foo="&lt;p&gt;&lt;/p&gt;"></div>'
606
630
  end
607
631
 
608
632
  it "should not escape raw tag content in attribute values" do
609
- @f.tag(:div, :foo=>Forme.raw('<p></p>')).to_s.must_equal '<div foo="<p></p>"></div>'
633
+ @f.tag(:div, :foo=>Forme.raw('<p></p>')).must_equal '<div foo="<p></p>"></div>'
610
634
  end
611
635
 
612
636
  it "should format dates, times, and datetimes in ISO format" do
613
- @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
614
- @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>'
615
- @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>'
637
+ @f.tag(:div, :foo=>Date.new(2011, 6, 5)).must_equal '<div foo="2011-06-05"></div>'
638
+ @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
639
+ @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
616
640
  end
617
641
 
618
642
  it "should format bigdecimals in standard notation" do
619
- @f.tag(:div, :foo=>BigDecimal('10000.010')).to_s.must_equal '<div foo="10000.01"></div>'
643
+ @f.tag(:div, :foo=>BigDecimal('10000.010')).must_equal '<div foo="10000.01"></div>'
620
644
  end
621
645
 
622
646
  it "inputs should accept a :wrapper option to use a custom wrapper" do
623
- @f.input(:text, :wrapper=>:li).to_s.must_equal '<li><input class="form-control" type="text"/></li>'
647
+ @f.input(:text, :wrapper=>:li).must_equal '<li><input class="form-control" type="text"/></li>'
624
648
  end
625
649
 
626
650
  it "inputs should accept a :wrapper_attr option to use custom wrapper attributes" do
627
- @f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.must_equal '<li class="foo"><input class="form-control" type="text"/></li>'
651
+ @f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).must_equal '<li class="foo"><input class="form-control" type="text"/></li>'
628
652
  end
629
653
 
630
654
  it "inputs should accept a :help option to use custom helper text" do
631
- @f.input(:text, :help=>"List type of foo").to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/><span class="helper">List type of foo</span></div>'
655
+ @f.input(:text, :help=>"List type of foo").must_equal '<div class="form-group"><input class="form-control" type="text"/><span class="helper">List type of foo</span></div>'
632
656
  end
633
657
 
634
658
  it "inputs should accept a :helper_attr option for custom helper attributes" do
635
- @f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/><span class="foo helper">List type of foo</span></div>'
659
+ @f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).must_equal '<div class="form-group"><input class="form-control" type="text"/><span class="foo helper">List type of foo</span></div>'
636
660
  end
637
661
 
638
662
  it "inputs should have helper displayed inside wrapper, after error" do
639
- @f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li class="has-error"><input aria-invalid="true" class="form-control" type="text"/><span class="help-block with-errors">bad</span><span class="helper">List type of foo</span></li>'
663
+ @f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).must_equal '<li class="has-error"><input aria-invalid="true" class="form-control" type="text"/><span class="help-block with-errors">bad</span><span class="helper">List type of foo</span></li>'
640
664
  end
641
665
 
642
666
  it "inputs should accept a :formatter option to use a custom formatter" do
643
- @f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <span class="readonly-text">1</span></div>'
644
- @f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" type="text" value="1"/></div>'
645
- @f.input(:text, :formatter=>:bs3_readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" readonly="readonly" type="text" value="1"/></div>'
667
+ @f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').must_equal '<div class="form-group"><label>Foo</label> <span class="readonly-text">1</span></div>'
668
+ @f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" type="text" value="1"/></div>'
669
+ @f.input(:text, :formatter=>:bs3_readonly, :value=>'1', :label=>'Foo').must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" readonly="readonly" type="text" value="1"/></div>'
646
670
  end
647
671
 
648
672
  it "bs3_readonly formatter should disable checkbox, radio, select, and textarea inputs" do
649
- @f.input(:checkbox, :formatter=>:bs3_readonly).to_s.must_equal '<div class="checkbox"><input disabled="disabled" type="checkbox"/></div>'
650
- @f.input(:radio, :formatter=>:bs3_readonly).to_s.must_equal '<div class="radio"><input disabled="disabled" type="radio"/></div>'
651
- @f.input(:select, :formatter=>:bs3_readonly).to_s.must_equal '<div class="form-group"><select class="form-control" disabled="disabled"></select></div>'
652
- @f.input(:textarea, :formatter=>:bs3_readonly).to_s.must_equal '<div class="form-group"><textarea class="form-control" readonly="readonly"></textarea></div>'
673
+ @f.input(:checkbox, :formatter=>:bs3_readonly).must_equal '<div class="checkbox"><input disabled="disabled" type="checkbox"/></div>'
674
+ @f.input(:radio, :formatter=>:bs3_readonly).must_equal '<div class="radio"><input disabled="disabled" type="radio"/></div>'
675
+ @f.input(:select, :formatter=>:bs3_readonly).must_equal '<div class="form-group"><select class="form-control" disabled="disabled"></select></div>'
676
+ @f.input(:textarea, :formatter=>:bs3_readonly).must_equal '<div class="form-group"><textarea class="form-control" readonly="readonly"></textarea></div>'
653
677
  end
654
678
 
655
679
  it "inputs should accept a :labeler option to use a custom labeler" do
656
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><label class="label-before" for="foo">bar</label><textarea class="form-control" id="foo"></textarea></div>'
680
+ @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).must_equal '<div class="form-group"><label class="label-before" for="foo">bar</label><textarea class="form-control" id="foo"></textarea></div>'
657
681
  end
658
682
 
659
683
  it "inputs handle explicit labels with :label_position=>:after" do
660
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea><label class="label-after" for="foo">bar</label></div>'
684
+ @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea><label class="label-after" for="foo">bar</label></div>'
661
685
  end
662
686
 
663
687
  it "should handle explicit labels with checkboxes" do
664
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.must_equal '<div class="checkbox"><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></div>'
688
+ @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').must_equal '<div class="checkbox"><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></div>'
665
689
  end
666
690
 
667
691
  it "should handle explicit labels with checkboxes with :label_position=>:before" do
668
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.must_equal '<div class="checkbox"><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"/></div>'
692
+ @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).must_equal '<div class="checkbox"><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"/></div>'
669
693
  end
670
694
 
671
695
  it "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
672
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.must_equal '<div class="checkbox"><label for="bar">Foo <input id="bar" name="a" type="checkbox" value="foo"/></label></div>'
696
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).must_equal '<div class="checkbox"><label for="bar">Foo <input id="bar" name="a" type="checkbox" value="foo"/></label></div>'
673
697
  end
674
698
 
675
699
  it "inputs should accept a :error_handler option to use a custom error_handler" do
676
- @f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><textarea aria-describedby="foo_error_message" aria-invalid="true" class="form-control" id="foo"></textarea>!!! bar</div>'
700
+ @f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).must_equal '<div class="form-group"><textarea aria-describedby="foo_error_message" aria-invalid="true" class="form-control" id="foo"></textarea>!!! bar</div>'
701
+ end
702
+
703
+ it "inputs should accept a :error_id option to specify id for error" do
704
+ @f.input(:textarea, :error_id=>:baz, :error=>'bar', :id=>:foo).must_equal '<div class="form-group has-error"><textarea aria-describedby="baz" aria-invalid="true" class="form-control" id="foo"></textarea><span class="help-block with-errors" id="baz">bar</span></div>'
677
705
  end
678
706
 
679
707
  it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
680
- @f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.must_equal '<ol><div class="form-group"><textarea class="form-control"></textarea></div></ol>'
681
- @f.inputs([:textarea], :inputs_wrapper=>:bs3_table, :wrapper=>:trtd).to_s.must_equal '<table class="table table-bordered"><tr><td><textarea class="form-control"></textarea></td><td></td></tr></table>'
682
- @f.inputs([:textarea], :inputs_wrapper=>:bs3_table, :wrapper=>:trtd, :legend=>'Foo', :labels=>['bar']).to_s.must_equal '<table class="table table-bordered"><caption>Foo</caption><tr><th>bar</th></tr><tr><td><textarea class="form-control"></textarea></td><td></td></tr></table>'
708
+ @f.inputs([:textarea], :inputs_wrapper=>:ol).must_equal '<ol><div class="form-group"><textarea class="form-control"></textarea></div></ol>'
709
+ @f.inputs([:textarea], :inputs_wrapper=>:bs3_table, :wrapper=>:trtd).must_equal '<table class="table table-bordered"><tr><td><textarea class="form-control"></textarea></td><td></td></tr></table>'
710
+ @f.inputs([:textarea], :inputs_wrapper=>:bs3_table, :wrapper=>:trtd, :legend=>'Foo', :labels=>['bar']).must_equal '<table class="table table-bordered"><caption>Foo</caption><tr><th>bar</th></tr><tr><td><textarea class="form-control"></textarea></td><td></td></tr></table>'
711
+ @f.inputs([:textarea], :inputs_wrapper=>:bs3_table, :wrapper=>:trtd, :attr=>{:class=>'foo'}).must_equal '<table class="foo"><tr><td><textarea class="form-control"></textarea></td><td></td></tr></table>'
683
712
  end
684
713
 
685
714
  it "inputs should accept a :wrapper=>nil option to not use a wrapper" do
686
- Forme::Form.new(:config=>:bs3,:wrapper=>:li).input(:text, :wrapper=>nil).to_s.must_equal '<input class="form-control" type="text"/>'
715
+ Forme::Form.new(:config=>:bs3,:wrapper=>:li).input(:text, :wrapper=>nil).must_equal '<input class="form-control" type="text"/>'
687
716
  end
688
717
 
689
718
  it "inputs should accept a :labeler=>nil option to not use a labeler" do
690
- @f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea></div>'
719
+ @f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea></div>'
691
720
  end
692
721
 
693
722
  it "inputs should accept a :error_handler=>nil option to not use an error_handler" do
694
- @f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><textarea aria-invalid="true" class="form-control" id="foo"></textarea></div>'
723
+ @f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).must_equal '<div class="form-group"><textarea aria-invalid="true" class="form-control" id="foo"></textarea></div>'
695
724
  end
696
725
 
697
726
  it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
698
- @f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.must_equal '<form><div class="form-group"><textarea class="form-control"></textarea></div></form>'
727
+ @f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.must_equal '<form><div class="form-group"><textarea class="form-control"></textarea></div></form>'
699
728
  end
700
729
 
701
730
  it "#inputs should treat a single hash argument as an options hash with no default inputs" do
702
- @f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.must_equal '<ol><div class="form-group"><textarea class="form-control"></textarea></div></ol>'
731
+ @f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.must_equal '<ol><div class="form-group"><textarea class="form-control"></textarea></div></ol>'
703
732
  end
704
733
 
705
734
  it "should support setting defaults for inputs at the form level" do
706
735
  f = Forme::Form.new(:config=>:bs3, :input_defaults=>{'text'=>{:size=>20}, 'textarea'=>{:cols=>80, :rows=>6}})
707
- f.input(:text, :name=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" name="foo" size="20" type="text"/></div>'
708
- f.input(:textarea, :name=>"foo").to_s.must_equal '<div class="form-group"><textarea class="form-control" cols="80" name="foo" rows="6"></textarea></div>'
736
+ f.input(:text, :name=>"foo").must_equal '<div class="form-group"><input class="form-control" name="foo" size="20" type="text"/></div>'
737
+ f.input(:textarea, :name=>"foo").must_equal '<div class="form-group"><textarea class="form-control" cols="80" name="foo" rows="6"></textarea></div>'
709
738
  end
710
739
 
711
740
  it "should work with input_defaults with symbol keys using using inputs with symbol keys" do
712
741
  f = Forme::Form.new(:config=>:bs3, :input_defaults=>{:text=>{:size=>20}, 'text'=>{:size=>30}})
713
- f.input(:text, :name=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" name="foo" size="20" type="text"/></div>'
714
- f.input('text', :name=>"foo").to_s.must_equal '<div class="form-group"><input class="form-control" name="foo" size="30" type="text"/></div>'
742
+ f.input(:text, :name=>"foo").must_equal '<div class="form-group"><input class="form-control" name="foo" size="20" type="text"/></div>'
743
+ f.input('text', :name=>"foo").must_equal '<div class="form-group"><input class="form-control" name="foo" size="30" type="text"/></div>'
715
744
  end
716
745
 
717
746
  it "invalid custom transformers should raise an Error" do
718
- proc{Forme::Form.new(:config=>:bs3, :wrapper=>Object.new).input(:text).to_s}.must_raise(Forme::Error)
719
- proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.must_raise(Forme::Error)
720
- proc{@f.input(:textarea, :formatter=>nil).to_s}.must_raise(Forme::Error)
747
+ proc{Forme::Form.new(:config=>:bs3, :wrapper=>Object.new).input(:text)}.must_raise(Forme::Error)
748
+ proc{@f.input(:textarea, :wrapper=>Object.new)}.must_raise(Forme::Error)
749
+ proc{@f.input(:textarea, :formatter=>nil)}.must_raise(Forme::Error)
721
750
  end
722
751
  end