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