forme 2.1.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 +10 -0
- data/README.rdoc +3 -3
- data/lib/forme/bs3.rb +7 -7
- data/lib/forme/form.rb +2 -0
- data/lib/forme/transformers/error_handler.rb +10 -10
- data/lib/forme/transformers/formatter.rb +32 -34
- data/lib/forme/version.rb +1 -1
- data/lib/sequel/plugins/forme.rb +8 -6
- data/lib/sequel/plugins/forme_set.rb +2 -4
- data/spec/bs3_reference_spec.rb +288 -311
- data/spec/bs3_sequel_plugin_spec.rb +152 -152
- data/spec/bs3_spec.rb +234 -205
- data/spec/forme_coverage.rb +1 -0
- data/spec/forme_spec.rb +429 -353
- data/spec/rails_integration_spec.rb +13 -1
- data/spec/roda_integration_spec.rb +20 -2
- data/spec/sequel_helper.rb +3 -1
- data/spec/sequel_i18n_plugin_spec.rb +4 -4
- data/spec/sequel_plugin_spec.rb +252 -149
- data/spec/sequel_set_plugin_spec.rb +6 -0
- data/spec/shared_erb_specs.rb +1 -1
- data/spec/sinatra_integration_spec.rb +26 -0
- metadata +2 -2
data/spec/bs3_reference_spec.rb
CHANGED
@@ -15,344 +15,321 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
15
15
|
@c = Forme::Form.new(@ac, :config=>:bs3)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
it "should create an input[:radio] tag with a label when ':class => bar'" do
|
296
|
-
@f.input(:radio, :label=>"Gold", :class=>'bar').to_s.must_equal '<div class="radio"><label><input class="bar" type="radio"/> Gold</label></div>'
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should create an input[:radio] tag with a label when ':id => bar'" do
|
300
|
-
@f.input(:radio, :label=>"Gold", :id=>'bar').to_s.must_equal '<div class="radio"><label for="bar"><input id="bar" type="radio"/> Gold</label></div>'
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should create an input[:radio] tag with a label when ':id => bar' with an error" do
|
304
|
-
@f.input(:radio, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-radio-error').to_s.must_equal '<div class="has-error"><div class="radio"><label for="bar"><input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="radio"/> Gold</label></div><span class="help-block with-errors">input-radio-error</span></div>'
|
305
|
-
end
|
306
|
-
|
307
|
-
describe 'from a Sequel model' do
|
308
|
-
it "should correctly handle a boolean attribute ':as=>:radio'" do
|
309
|
-
@c.input(:gold, :as=>:radio).to_s.must_equal '<div class="boolean radioset"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div></div>'
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should correctly handle a boolean attribute ':as=>:radio' with an error" do
|
313
|
-
@ac.errors.add(:gold, 'error message')
|
314
|
-
@c.input(:gold, :as=>:radio).to_s.must_equal '<div class="boolean radioset has-error"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">error message</span></div>'
|
315
|
-
end
|
316
|
-
end
|
18
|
+
it "should create a simple input[:text] tag" do
|
19
|
+
@f.input(:text).must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create an input[:text] tag with a label when ':label => Name'" do
|
23
|
+
@f.input(:text, :label=>"Name").must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="text"/></div>'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create an input[:text] tag with a label when ':class => bar'" do
|
27
|
+
@f.input(:text, :label=>"Name", :class=>'bar').must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="text"/></div>'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create an input[:text] tag with a label when ':id => bar'" do
|
31
|
+
@f.input(:text, :label=>"Name", :id=>'bar').must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="text"/></div>'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create an input[:text] tag with a label when ':id => bar' with an error" do
|
35
|
+
@f.input(:text, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-text-error').must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="text"/><span class="help-block with-errors" id="bar_error_message">input-text-error</span></div>'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create a correct input[:text] tag from Sequel model" do
|
39
|
+
@c.input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="c"/></div>'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
43
|
+
@ac.errors.add(:name, 'name not valid')
|
44
|
+
@c.input(:name).must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input aria-describedby="album_name_error_message" aria-invalid="true" class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="c"/><span class="help-block with-errors" id="album_name_error_message">name not valid</span></div>'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should create a simple input[:password] tag" do
|
48
|
+
@f.input(:password).must_equal '<div class="form-group"><input class="form-control" type="password"/></div>'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create an input[:password] tag with a label when ':label => Name'" do
|
52
|
+
@f.input(:password, :label=>"Name").must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="password"/></div>'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create an input[:password] tag with a label when ':class => bar'" do
|
56
|
+
@f.input(:password, :label=>"Name", :class=>'bar').must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="password"/></div>'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should create an input[:password] tag with a label when ':id => bar'" do
|
60
|
+
@f.input(:password, :label=>"Name", :id=>'bar').must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="password"/></div>'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should create an input[:password] tag with a label when ':id => bar' with an error" do
|
64
|
+
@f.input(:password, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-password-error').must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="password"/><span class="help-block with-errors" id="bar_error_message">input-password-error</span></div>'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should create a simple input[:email] tag" do
|
68
|
+
@f.input(:email).must_equal '<div class="form-group"><input class="form-control" type="email"/></div>'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should create an input[:email] tag with a label when ':label => Name'" do
|
72
|
+
@f.input(:email, :label=>"Name").must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="email"/></div>'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should create an input[:email] tag with a label when ':class => bar'" do
|
76
|
+
@f.input(:email, :label=>"Name", :class=>'bar').must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="email"/></div>'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should create an input[:email] tag with a label when ':id => bar'" do
|
80
|
+
@f.input(:email, :label=>"Name", :id=>'bar').must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="email"/></div>'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should create an input[:email] tag with a label when ':id => bar' with an error" do
|
84
|
+
@f.input(:email, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-email-error').must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="email"/><span class="help-block with-errors" id="bar_error_message">input-email-error</span></div>'
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create a simple input[:file] tag" do
|
88
|
+
@f.input(:file).must_equal '<div class="form-group"><input type="file"/></div>'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should create an input[:file] tag with a label when ':label => Name'" do
|
92
|
+
@f.input(:file, :label=>"Name").must_equal '<div class="form-group"><label>Name</label> <input type="file"/></div>'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should create an input[:file] tag with a label when ':class => bar'" do
|
96
|
+
@f.input(:file, :label=>"Name", :class=>'bar').must_equal '<div class="form-group"><label>Name</label> <input class="bar" type="file"/></div>'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should create an input[:file] tag with a label when ':id => bar'" do
|
100
|
+
@f.input(:file, :label=>"Name", :id=>'bar').must_equal '<div class="form-group"><label for="bar">Name</label> <input id="bar" type="file"/></div>'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should create an input[:file] tag with a label when ':id => bar' with an error" do
|
104
|
+
@f.input(:file, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-file-error').must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="file"/><span class="help-block with-errors" id="bar_error_message">input-file-error</span></div>'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should create a simple input[:submit] tag" do
|
108
|
+
@f.input(:submit).must_equal '<input class="btn btn-default" type="submit"/>'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should create a input[:submit] tag with attributes" do
|
112
|
+
@f.input(:submit, :attr=>{:class=>'bar'}).must_equal '<input class="btn btn-default bar" type="submit"/>'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should create an input[:submit] tag with the correct value" do
|
116
|
+
@f.input(:submit, :value=>'Save').must_equal '<input class="btn btn-default" type="submit" value="Save"/>'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should create an input[:submit] tag with the correct class" do
|
120
|
+
@f.input(:submit, :value=>'Save', :class=>'btn-primary').must_equal '<input class="btn btn-primary" type="submit" value="Save"/>'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should create an input[:submit] tag with the correct id" do
|
124
|
+
@f.input(:submit, :value=>'Save', :id=>'foo').must_equal '<input class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should create an input[:submit] tag without error message " do
|
128
|
+
@f.input(:submit, :value=>'Save', :id=>'foo', :error=>'error-message').must_equal '<input class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should create a simple input[:reset] tag" do
|
132
|
+
@f.input(:reset).must_equal '<input class="btn btn-default" type="reset"/>'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should create an input[:reset] tag with the correct value" do
|
136
|
+
@f.input(:reset, :value=>'Save').must_equal '<input class="btn btn-default" type="reset" value="Save"/>'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should create an input[:reset] tag with the correct class" do
|
140
|
+
@f.input(:reset, :value=>'Save', :class=>'btn-primary').must_equal '<input class="btn btn-primary" type="reset" value="Save"/>'
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should create an input[:reset] tag with the correct id" do
|
144
|
+
@f.input(:reset, :value=>'Save', :id=>'foo').must_equal '<input class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should create an input[:reset] tag without error message " do
|
148
|
+
@f.input(:reset, :value=>'Save', :id=>'foo', :error=>'error-message').must_equal '<input class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should create a simple :textarea tag" do
|
152
|
+
@f.input(:textarea).must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should create an :textarea tag with the correct value" do
|
156
|
+
@f.input(:textarea, :value=>'Bio').must_equal '<div class="form-group"><textarea class="form-control">Bio</textarea></div>'
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should create an :textarea tag with the correct class" do
|
160
|
+
@f.input(:textarea, :class=>'foo').must_equal '<div class="form-group"><textarea class="form-control foo"></textarea></div>'
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should create an :textarea tag with the correct id" do
|
164
|
+
@f.input(:textarea, :id=>'bar').must_equal '<div class="form-group"><textarea class="form-control" id="bar"></textarea></div>'
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should create a textarea tag without a .has-error and error message span when ':skip_error => true'" do
|
168
|
+
@f.input(:textarea, :skip_error=>true).must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should create a textarea tag with .has-error and error message when ':error => is-a-string'" do
|
172
|
+
@f.input(:textarea, :error=>'input-textarea-error').must_equal '<div class="form-group has-error"><textarea aria-invalid="true" class="form-control"></textarea><span class="help-block with-errors">input-textarea-error</span></div>'
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should create a correct input[:text] tag from Sequel model" do
|
176
|
+
@c.input(:name, :as=>:textarea).must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea></div>'
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
180
|
+
@ac.errors.add(:name, 'name not valid')
|
181
|
+
@c.input(:name, :as=>:textarea).must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <textarea aria-describedby="album_name_error_message" aria-invalid="true" class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea><span class="help-block with-errors" id="album_name_error_message">name not valid</span></div>'
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should create a simple :select tag" do
|
185
|
+
@f.input(:select).must_equal '<div class="form-group"><select class="form-control"></select></div>'
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should create a simple :select tag with options" do
|
189
|
+
@f.input(:select, :options=>[[:a, 1], [:b,2]]).must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option value="2">b</option></select></div>'
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should create a simple :select tag with options and the correct value" do
|
193
|
+
@f.input(:select, :options=>[[:a, 1], [:b,2]], :value=>2).must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option selected="selected" value="2">b</option></select></div>'
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should support :add_blank option for select inputs" do
|
197
|
+
@f.input(:select, :options=>[[:a, 1], [:b, 2]], :add_blank=>true, :value=>1).must_equal '<div class="form-group"><select class="form-control"><option value=""></option><option selected="selected" value="1">a</option><option value="2">b</option></select></div>'
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should create an :select tag with the correct class" do
|
201
|
+
@f.input(:select, :class=>'foo').must_equal '<div class="form-group"><select class="form-control foo"></select></div>'
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should create an :select tag with the correct id" do
|
205
|
+
@f.input(:select, :id=>'bar').must_equal '<div class="form-group"><select class="form-control" id="bar"></select></div>'
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should create a select tag without .has-error and error message span when ':skip_error => true'" do
|
209
|
+
@f.input(:select, :skip_error=>true).must_equal '<div class="form-group"><select class="form-control"></select></div>'
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should create a select tag with .has-error and error message when ':error => is-a-string'" do
|
213
|
+
@f.input(:select, :error=>'input-select-error').must_equal '<div class="form-group has-error"><select aria-invalid="true" class="form-control"></select><span class="help-block with-errors">input-select-error</span></div>'
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should correctly handle a Sequel model output :as => :select" do
|
217
|
+
@b.input(:artist, :as=>:select).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></div>'
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should correctly handle a Sequel model output :as => :select with error" do
|
221
|
+
@ac.errors.add(:artist, 'error message')
|
222
|
+
@c.input(:artist, :as=>:select).must_equal '<div class="form-group has-error many_to_one"><label for="album_artist_id">Artist</label> <select aria-describedby="album_artist_id_error_message" aria-invalid="true" class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a</option><option selected="selected" value="2">d</option></select><span class="help-block with-errors" id="album_artist_id_error_message">error message</span></div>'
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should correctly handle a boolean attribute from a Sequel model" do
|
226
|
+
@c.input(:gold).must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option selected="selected" value="t">True</option><option value="f">False</option></select></div>'
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should correctly handle a boolean attribute from a Sequel model with an error" do
|
230
|
+
@ac.errors.add(:gold, 'error message')
|
231
|
+
@c.input(:gold).must_equal '<div class="boolean form-group has-error"><label for="album_gold">Gold</label> <select aria-describedby="album_gold_error_message" aria-invalid="true" class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option selected="selected" value="t">True</option><option value="f">False</option></select><span class="help-block with-errors" id="album_gold_error_message">error message</span></div>'
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should create a simple input[:checkbox] tag" do
|
235
|
+
@f.input(:checkbox).must_equal '<div class="checkbox"><input type="checkbox"/></div>'
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should remove form-control class from attributes for input[:checkbox] tag" do
|
239
|
+
@f.input(:checkbox, :class=>'form-control').must_equal '<div class="checkbox"><input type="checkbox"/></div>'
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should create an input[:checkbox] tag with a label when ':label => Gold'" do
|
243
|
+
@f.input(:checkbox, :label=>"Gold").must_equal '<div class="checkbox"><label><input type="checkbox"/> Gold</label></div>'
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should create an input[:checkbox] tag with a label when ':class => bar'" do
|
247
|
+
@f.input(:checkbox, :label=>"Gold", :class=>'bar').must_equal '<div class="checkbox"><label><input class="bar" type="checkbox"/> Gold</label></div>'
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should create an input[:checkbox] tag with a label when ':id => bar'" do
|
251
|
+
@f.input(:checkbox, :label=>"Gold", :id=>'bar').must_equal '<div class="checkbox"><label for="bar"><input id="bar" type="checkbox"/> Gold</label></div>'
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should create an input[:checkbox] tag with a label when ':id => bar' with an error" do
|
255
|
+
@f.input(:checkbox, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-checkbox-error').must_equal '<div class="has-error"><div class="checkbox"><label for="bar"><input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="checkbox"/> Gold</label></div><span class="help-block with-errors" id="bar_error_message">input-checkbox-error</span></div>'
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should correctly handle a boolean attribute ':as=>:checkbox'" do
|
259
|
+
@c.input(:gold, :as=>:checkbox).must_equal '<div class="boolean checkbox"><label for="album_gold"><input id="album_gold_hidden" name="album[gold]" type="hidden" value="f"/><input checked="checked" id="album_gold" name="album[gold]" type="checkbox" value="t"/> Gold</label></div>'
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should correctly handle a boolean attribute ':as=>:checkbox' with an error" do
|
263
|
+
@ac.errors.add(:gold, 'error message')
|
264
|
+
@c.input(:gold, :as=>:checkbox).must_equal '<div class="boolean has-error"><div class="checkbox"><label for="album_gold"><input id="album_gold_hidden" name="album[gold]" type="hidden" value="f"/><input aria-describedby="album_gold_error_message" aria-invalid="true" checked="checked" id="album_gold" name="album[gold]" type="checkbox" value="t"/> Gold</label></div><span class="help-block with-errors" id="album_gold_error_message">error message</span></div>'
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should create a simple input[:radio] tag" do
|
268
|
+
@f.input(:radio).must_equal '<div class="radio"><input type="radio"/></div>'
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should create an input[:radio] tag with a label when ':label => Gold'" do
|
272
|
+
@f.input(:radio, :label=>"Gold").must_equal '<div class="radio"><label><input type="radio"/> Gold</label></div>'
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should create an input[:radio] tag with a label when ':class => bar'" do
|
276
|
+
@f.input(:radio, :label=>"Gold", :class=>'bar').must_equal '<div class="radio"><label><input class="bar" type="radio"/> Gold</label></div>'
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should create an input[:radio] tag with a label when ':id => bar'" do
|
280
|
+
@f.input(:radio, :label=>"Gold", :id=>'bar').must_equal '<div class="radio"><label for="bar"><input id="bar" type="radio"/> Gold</label></div>'
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should create an input[:radio] tag with a label when ':id => bar' with an error" do
|
284
|
+
@f.input(:radio, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-radio-error').must_equal '<div class="has-error"><div class="radio"><label for="bar"><input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="radio"/> Gold</label></div><span class="help-block with-errors" id="bar_error_message">input-radio-error</span></div>'
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should correctly handle a boolean attribute ':as=>:radio'" do
|
288
|
+
@c.input(:gold, :as=>:radio).must_equal '<div class="boolean radioset"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div></div>'
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should correctly handle a boolean attribute ':as=>:radio' with an error" do
|
292
|
+
@ac.errors.add(:gold, 'error message')
|
293
|
+
@c.input(:gold, :as=>:radio).must_equal '<div class="boolean radioset has-error"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">error message</span></div>'
|
317
294
|
end
|
318
295
|
|
319
296
|
|
320
297
|
it "should correctly handle a :checkboxset tag" do
|
321
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]]).
|
298
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b,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 type="checkbox" value="2"/> b</label></div></div>'
|
322
299
|
end
|
323
300
|
|
324
301
|
it "should correctly handle a :checkboxset tag without options" do
|
325
|
-
@f.input(:checkboxset, :options=>[]).
|
302
|
+
@f.input(:checkboxset, :options=>[]).must_equal '<div class="checkboxset"></div>'
|
326
303
|
end
|
327
304
|
|
328
305
|
it "should correctly handle a :checkboxset tag with an error - Alternative A: (see BS3 HTML reference)" do
|
329
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message').
|
306
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message').must_equal '<div class="checkboxset has-error"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
330
307
|
end
|
331
308
|
|
332
309
|
it "should correctly handle a :checkboxset tag with an error and label - Alternative A: (see BS3 HTML reference)" do
|
333
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'CheckboxSet').
|
310
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'CheckboxSet').must_equal '<div class="checkboxset has-error"><label>CheckboxSet</label><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
334
311
|
end
|
335
312
|
|
336
313
|
it "should correctly handle a :radioset tag" do
|
337
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]]).
|
314
|
+
@f.input(:radioset, :options=>[[:a, 1], [:b,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 type="radio" value="2"/> b</label></div></div>'
|
338
315
|
end
|
339
316
|
|
340
317
|
it "should correctly handle a :radioset tag without options" do
|
341
|
-
@f.input(:radioset, :options=>[]).
|
318
|
+
@f.input(:radioset, :options=>[]).must_equal '<div class="radioset"></div>'
|
342
319
|
end
|
343
320
|
|
344
321
|
it "should correctly handle a :radioset tag with an error - Alternative A: (see BS3 HTML reference)" do
|
345
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message').
|
322
|
+
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message').must_equal '<div class="radioset has-error"><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input type="radio" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
346
323
|
end
|
347
324
|
|
348
325
|
it "should correctly handle a :radioset tag with an error and label - Alternative A: (see BS3 HTML reference)" do
|
349
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'RadioSet').
|
326
|
+
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'RadioSet').must_equal '<div class="radioset has-error"><label>RadioSet</label><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input type="radio" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
350
327
|
end
|
351
328
|
|
352
329
|
it "should use a set of radio buttons for many_to_one associations with :as=>:radio option" do
|
353
|
-
@b.input(:artist, :as=>:radio).
|
354
|
-
@b.input(:artist, :as=>:radio, :wrapper=>nil).
|
355
|
-
@c.input(:artist, :as=>:radio).
|
356
|
-
@c.input(:artist, :as=>:radio, :wrapper=>:div).
|
330
|
+
@b.input(:artist, :as=>:radio).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
331
|
+
@b.input(:artist, :as=>:radio, :wrapper=>nil).must_equal '<label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div>'
|
332
|
+
@c.input(:artist, :as=>:radio).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input checked="checked" id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
333
|
+
@c.input(:artist, :as=>:radio, :wrapper=>:div).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input checked="checked" id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
357
334
|
end
|
358
335
|
end
|