forme 1.12.0 → 2.0.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 +34 -0
- data/README.rdoc +226 -204
- data/lib/forme/bs3.rb +18 -4
- data/lib/forme/erb.rb +18 -16
- data/lib/forme/form.rb +150 -117
- data/lib/forme/input.rb +1 -1
- data/lib/forme/rails.rb +41 -72
- data/lib/forme/raw.rb +2 -2
- data/lib/forme/sinatra.rb +6 -2
- data/lib/forme/tag.rb +3 -12
- data/lib/forme/template.rb +118 -0
- 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 +62 -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 +37 -51
- data/lib/sequel/plugins/forme_i18n.rb +3 -1
- data/spec/all.rb +1 -1
- data/spec/bs3_reference_spec.rb +18 -18
- data/spec/bs3_sequel_plugin_spec.rb +7 -7
- data/spec/bs3_spec.rb +23 -11
- data/spec/erb_helper.rb +73 -58
- data/spec/erubi_capture_helper.rb +202 -0
- data/spec/forme_spec.rb +30 -15
- data/spec/rails_integration_spec.rb +17 -11
- data/spec/roda_integration_spec.rb +123 -68
- data/spec/sequel_helper.rb +0 -1
- data/spec/sequel_i18n_helper.rb +1 -1
- data/spec/sequel_i18n_plugin_spec.rb +2 -2
- data/spec/sequel_plugin_spec.rb +11 -2
- data/spec/sequel_set_plugin_spec.rb +3 -3
- data/spec/shared_erb_specs.rb +75 -0
- data/spec/sinatra_integration_spec.rb +5 -6
- data/spec/spec_helper.rb +21 -3
- metadata +8 -5
- data/lib/forme/erb_form.rb +0 -74
data/spec/bs3_reference_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require_relative 'sequel_helper'
|
3
|
+
require_relative '../lib/forme/bs3'
|
4
4
|
|
5
5
|
describe "Forme Bootstrap3 (BS3) forms" do
|
6
6
|
def sel(opts, s)
|
@@ -33,7 +33,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should create an input[:text] tag with a label when ':id => bar' with an error" do
|
36
|
-
@f.input(:text, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-text-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input class="form-control foo" id="bar" type="text"/><span class="help-block with-errors">input-text-error</span></div>'
|
36
|
+
@f.input(:text, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-text-error').to_s.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">input-text-error</span></div>'
|
37
37
|
end
|
38
38
|
|
39
39
|
describe 'from a Sequel model' do
|
@@ -43,7 +43,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
43
43
|
|
44
44
|
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
45
45
|
@ac.errors.add(:name, 'name not valid')
|
46
|
-
@c.input(:name).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="c"/><span class="help-block with-errors">name not valid</span></div>'
|
46
|
+
@c.input(:name).to_s.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">name not valid</span></div>'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -66,7 +66,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should create an input[:password] tag with a label when ':id => bar' with an error" do
|
69
|
-
@f.input(:password, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-password-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input class="form-control foo" id="bar" type="password"/><span class="help-block with-errors">input-password-error</span></div>'
|
69
|
+
@f.input(:password, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-password-error').to_s.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">input-password-error</span></div>'
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -88,7 +88,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should create an input[:email] tag with a label when ':id => bar' with an error" do
|
91
|
-
@f.input(:email, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-email-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input class="form-control foo" id="bar" type="email"/><span class="help-block with-errors">input-email-error</span></div>'
|
91
|
+
@f.input(:email, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-email-error').to_s.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">input-email-error</span></div>'
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -110,7 +110,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should create an input[:file] tag with a label when ':id => bar' with an error" do
|
113
|
-
@f.input(:file, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-file-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input class="foo" id="bar" type="file"/><span class="help-block with-errors">input-file-error</span></div>'
|
113
|
+
@f.input(:file, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-file-error').to_s.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">input-file-error</span></div>'
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -132,7 +132,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should create an input[:submit] tag without error message " do
|
135
|
-
@f.input(:submit, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
135
|
+
@f.input(:submit, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input aria-describedby="foo_error_message" aria-invalid="true" class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -154,7 +154,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should create an input[:reset] tag without error message " do
|
157
|
-
@f.input(:reset, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
157
|
+
@f.input(:reset, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input aria-describedby="foo_error_message" aria-invalid="true" class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -180,7 +180,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should create a textarea tag with .has-error and error message when ':error => is-a-string'" do
|
183
|
-
@f.input(:textarea, :error=>'input-textarea-error').to_s.must_equal '<div class="form-group has-error"><textarea class="form-control"></textarea><span class="help-block with-errors">input-textarea-error</span></div>'
|
183
|
+
@f.input(:textarea, :error=>'input-textarea-error').to_s.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>'
|
184
184
|
end
|
185
185
|
|
186
186
|
describe 'from a Sequel model' do
|
@@ -190,7 +190,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
190
190
|
|
191
191
|
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
192
192
|
@ac.errors.add(:name, 'name not valid')
|
193
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea><span class="help-block with-errors">name not valid</span></div>'
|
193
|
+
@c.input(:name, :as=>:textarea).to_s.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">name not valid</span></div>'
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
@@ -225,7 +225,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should create a select tag with .has-error and error message when ':error => is-a-string'" do
|
228
|
-
@f.input(:select, :error=>'input-select-error').to_s.must_equal '<div class="form-group has-error"><select class="form-control"></select><span class="help-block with-errors">input-select-error</span></div>'
|
228
|
+
@f.input(:select, :error=>'input-select-error').to_s.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>'
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should correctly handle a Sequel model output :as => :select" do
|
@@ -234,7 +234,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
234
234
|
|
235
235
|
it "should correctly handle a Sequel model output :as => :select with error" do
|
236
236
|
@ac.errors.add(:artist, 'error message')
|
237
|
-
@c.input(:artist, :as=>:select).to_s.must_equal '<div class="form-group has-error 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 value="1">a</option><option selected="selected" value="2">d</option></select><span class="help-block with-errors">error message</span></div>'
|
237
|
+
@c.input(:artist, :as=>:select).to_s.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">error message</span></div>'
|
238
238
|
end
|
239
239
|
|
240
240
|
describe 'from a Sequel model' do
|
@@ -244,7 +244,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
244
244
|
|
245
245
|
it "should correctly handle a boolean attribute from a Sequel model with an error" do
|
246
246
|
@ac.errors.add(:gold, 'error message')
|
247
|
-
@c.input(:gold).to_s.must_equal '<div class="boolean form-group has-error"><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><span class="help-block with-errors">error message</span></div>'
|
247
|
+
@c.input(:gold).to_s.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">error message</span></div>'
|
248
248
|
end
|
249
249
|
end
|
250
250
|
end
|
@@ -267,7 +267,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
267
267
|
end
|
268
268
|
|
269
269
|
it "should create an input[:checkbox] tag with a label when ':id => bar' with an error" do
|
270
|
-
@f.input(:checkbox, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-checkbox-error').to_s.must_equal '<div class="has-error"><div class="checkbox"><label for="bar"><input class="foo" id="bar" type="checkbox"/> Gold</label></div><span class="help-block with-errors">input-checkbox-error</span></div>'
|
270
|
+
@f.input(:checkbox, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-checkbox-error').to_s.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">input-checkbox-error</span></div>'
|
271
271
|
end
|
272
272
|
|
273
273
|
describe 'from a Sequel model' do
|
@@ -277,7 +277,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
277
277
|
|
278
278
|
it "should correctly handle a boolean attribute ':as=>:checkbox' with an error" do
|
279
279
|
@ac.errors.add(:gold, 'error message')
|
280
|
-
@c.input(:gold, :as=>:checkbox).to_s.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 checked="checked" id="album_gold" name="album[gold]" type="checkbox" value="t"/> Gold</label></div><span class="help-block with-errors">error message</span></div>'
|
280
|
+
@c.input(:gold, :as=>:checkbox).to_s.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">error message</span></div>'
|
281
281
|
end
|
282
282
|
end
|
283
283
|
end
|
@@ -301,7 +301,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
301
301
|
end
|
302
302
|
|
303
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 class="foo" id="bar" type="radio"/> Gold</label></div><span class="help-block with-errors">input-radio-error</span></div>'
|
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
305
|
end
|
306
306
|
|
307
307
|
describe 'from a Sequel model' do
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require_relative 'sequel_helper'
|
3
|
+
require_relative '../lib/forme/bs3'
|
4
4
|
|
5
5
|
describe "Forme Sequel::Model BS3 forms" do
|
6
6
|
before do
|
@@ -263,7 +263,7 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
263
263
|
|
264
264
|
it "should handle an error message on the underlying column for pg_array_to_many associations" do
|
265
265
|
@ab.errors.add(:atag_ids, 'tis not valid')
|
266
|
-
@b.input(:atags).to_s.must_equal '<div class="form-group has-error pg_array_to_many"><label for="album_atag_ids">Atags</label> <select class="form-control" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select><span class="help-block with-errors">tis not valid</span></div>'
|
266
|
+
@b.input(:atags).to_s.must_equal '<div class="form-group has-error pg_array_to_many"><label for="album_atag_ids">Atags</label> <select aria-describedby="album_atag_ids_error_message" aria-invalid="true" class="form-control" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select><span class="help-block with-errors">tis not valid</span></div>'
|
267
267
|
@b.input(:atags, :as=>:checkbox).to_s.must_equal '<div class="pg_array_to_many checkboxset has-error"><label>Atags</label><div class="checkbox"><label class="option" for="album_atag_ids_1"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_atag_ids_2"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_atag_ids_3"><input id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label></div><span class="help-block with-errors">tis not valid</span></div>'
|
268
268
|
@b.input(:atags, :as=>:checkbox,:wrapper=>:li).to_s.must_equal '<li class="pg_array_to_many checkboxset has-error"><label>Atags</label><div class="checkbox"><label class="option" for="album_atag_ids_1"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_atag_ids_2"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_atag_ids_3"><input id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label></div><span class="help-block with-errors">tis not valid</span></li>'
|
269
269
|
end
|
@@ -308,7 +308,7 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
308
308
|
|
309
309
|
it "should handle errors on methods not backed by columns" do
|
310
310
|
@ab.errors.add(:artist_name, 'foo')
|
311
|
-
@b.input(:artist_name).to_s.must_equal '<div class="form-group has-error"><label for="album_artist_name">Artist name</label> <input class="form-control" id="album_artist_name" name="album[artist_name]" type="text" value="a"/><span class="help-block with-errors">foo</span></div>'
|
311
|
+
@b.input(:artist_name).to_s.must_equal '<div class="form-group has-error"><label for="album_artist_name">Artist name</label> <input aria-describedby="album_artist_name_error_message" aria-invalid="true" class="form-control" id="album_artist_name" name="album[artist_name]" type="text" value="a"/><span class="help-block with-errors">foo</span></div>'
|
312
312
|
end
|
313
313
|
|
314
314
|
it "should respect a :type option with a schema type as the input type for methods not backed by columns" do
|
@@ -323,12 +323,12 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
323
323
|
|
324
324
|
it "should correctly show an error message if there is one" do
|
325
325
|
@ab.errors.add(:name, 'tis not valid')
|
326
|
-
@b.input(:name).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/><span class="help-block with-errors">tis not valid</span></div>'
|
326
|
+
@b.input(:name).to_s.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="b"/><span class="help-block with-errors">tis not valid</span></div>'
|
327
327
|
end
|
328
328
|
|
329
329
|
it "should correctly show an error message for many_to_one associations if there is one" do
|
330
330
|
@ab.errors.add(:artist_id, 'tis not valid')
|
331
|
-
@b.input(:artist).to_s.must_equal '<div class="form-group has-error 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><span class="help-block with-errors">tis not valid</span></div>'
|
331
|
+
@b.input(:artist).to_s.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 selected="selected" value="1">a</option><option value="2">d</option></select><span class="help-block with-errors">tis not valid</span></div>'
|
332
332
|
end
|
333
333
|
|
334
334
|
it "should raise an error for unhandled associations" do
|
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)
|
@@ -99,6 +99,18 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
it "should consider form's :errors hash based on the :key option" do
|
103
|
+
@f.opts[:errors] = { 'foo' => 'must be present' }
|
104
|
+
@f.input(:text, :key=>"foo").to_s.must_equal "<div class=\"form-group has-error\"><input aria-describedby=\"foo_error_message\" aria-invalid=\"true\" class=\"form-control\" id=\"foo\" name=\"foo\" type=\"text\"/><span class=\"help-block with-errors\">must be present</span></div>"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should consider form's :errors hash based on the :key option when using namespaces" do
|
108
|
+
@f.opts[:errors] = { 'bar' => { 'foo' => 'must be present' } }
|
109
|
+
@f.with_opts(:namespace=>['bar']) do
|
110
|
+
@f.input(:text, :key=>"foo").to_s.must_equal "<div class=\"form-group has-error\"><input aria-describedby=\"bar_foo_error_message\" aria-invalid=\"true\" class=\"form-control\" id=\"bar_foo\" name=\"bar[foo]\" type=\"text\"/><span class=\"help-block with-errors\">must be present</span></div>"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
102
114
|
it "should support a with_obj method that changes the object and namespace for the given block" do
|
103
115
|
@f.with_obj([:a, :c], 'bar') do
|
104
116
|
@f.input(:first).to_s.must_equal '<div class="form-group"><input class="form-control" id="bar_first" name="bar[first]" type="text" value="a"/></div>'
|
@@ -481,19 +493,19 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
481
493
|
end
|
482
494
|
|
483
495
|
it "should automatically note the input has errors if :error option is used" do
|
484
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
496
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
485
497
|
end
|
486
498
|
|
487
499
|
it "should add an error message after the label" do
|
488
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<div class="form-group has-error"><label>Foo</label> <input class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
500
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<div class="form-group has-error"><label>Foo</label> <input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
489
501
|
end
|
490
502
|
|
491
503
|
it "should add to existing :class option if :error option is used" do
|
492
|
-
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input class="form-control bar" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
504
|
+
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control bar" type="text" value="foo"/><span class="help-block with-errors">Bad Stuff!</span></div>'
|
493
505
|
end
|
494
506
|
|
495
507
|
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'}).to_s.must_equal '<div class="form-group has-error"><input class="form-control" type="text" value="foo"/><span class="foo help-block with-errors">Bad Stuff!</span></div>'
|
508
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<div class="form-group has-error"><input aria-invalid="true" class="form-control" type="text" value="foo"/><span class="foo help-block with-errors">Bad Stuff!</span></div>'
|
497
509
|
end
|
498
510
|
|
499
511
|
it "#open should return an opening tag" do
|
@@ -527,12 +539,12 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
527
539
|
end
|
528
540
|
|
529
541
|
it "#tag should accept children as procs" do
|
530
|
-
@f.tag(:div, {:class=>"foo"}, lambda{|t| t.
|
542
|
+
@f.tag(:div, {:class=>"foo"}, lambda{|t| t.tag(:input, :class=>t.attr[:class])}).to_s.must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
|
531
543
|
end
|
532
544
|
|
533
545
|
it "#tag should accept children as methods" do
|
534
546
|
o = Object.new
|
535
|
-
def o.foo(t) t.
|
547
|
+
def o.foo(t) t.tag(:input, :class=>t.attr[:class]) end
|
536
548
|
@f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.must_equal '<div class="foo"><input class="form-control foo" type="text"/></div>'
|
537
549
|
end
|
538
550
|
|
@@ -624,7 +636,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
624
636
|
end
|
625
637
|
|
626
638
|
it "inputs should have helper displayed inside wrapper, after error" do
|
627
|
-
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li class="has-error"><input class="form-control" type="text"/><span class="help-block with-errors">bad</span><span class="helper">List type of foo</span></li>'
|
639
|
+
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li class="has-error"><input aria-invalid="true" class="form-control" type="text"/><span class="help-block with-errors">bad</span><span class="helper">List type of foo</span></li>'
|
628
640
|
end
|
629
641
|
|
630
642
|
it "inputs should accept a :formatter option to use a custom formatter" do
|
@@ -661,7 +673,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
661
673
|
end
|
662
674
|
|
663
675
|
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).to_s.must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea>!!! bar</div>'
|
676
|
+
@f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><textarea aria-describedby="foo_error_message" aria-invalid="true" class="form-control" id="foo"></textarea>!!! bar</div>'
|
665
677
|
end
|
666
678
|
|
667
679
|
it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
|
@@ -679,7 +691,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
679
691
|
end
|
680
692
|
|
681
693
|
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).to_s.must_equal '<div class="form-group"><textarea class="form-control" id="foo"></textarea></div>'
|
694
|
+
@f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<div class="form-group"><textarea aria-invalid="true" class="form-control" id="foo"></textarea></div>'
|
683
695
|
end
|
684
696
|
|
685
697
|
it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
|
data/spec/erb_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'shared_erb_specs'
|
2
|
+
|
1
3
|
ERB_BLOCK = lambda do |r|
|
2
4
|
r.get '' do
|
3
5
|
erb <<END
|
@@ -65,6 +67,29 @@ END
|
|
65
67
|
END
|
66
68
|
end
|
67
69
|
|
70
|
+
r.get 'nest_seq_simple' do
|
71
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
72
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
73
|
+
@nest = <<END
|
74
|
+
n1
|
75
|
+
<% f.subform(:artist) do %>
|
76
|
+
n2
|
77
|
+
<%= f.input(:name2) %>
|
78
|
+
n3
|
79
|
+
<% end %>
|
80
|
+
n4
|
81
|
+
END
|
82
|
+
erb <<END
|
83
|
+
0
|
84
|
+
<% form(@album, :action=>'/baz') do |f| %>
|
85
|
+
1
|
86
|
+
<%= erb(@nest, :locals=>{:f=>f}) %>
|
87
|
+
3
|
88
|
+
<% end %>
|
89
|
+
4
|
90
|
+
END
|
91
|
+
end
|
92
|
+
|
68
93
|
r.get 'nest_seq' do
|
69
94
|
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
70
95
|
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
@@ -92,6 +117,50 @@ END
|
|
92
117
|
END
|
93
118
|
end
|
94
119
|
|
120
|
+
r.get 'grid-block' do
|
121
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
122
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
123
|
+
erb <<END
|
124
|
+
0
|
125
|
+
<% form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
126
|
+
1
|
127
|
+
<% f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') do %>
|
128
|
+
2
|
129
|
+
<% end %>
|
130
|
+
3
|
131
|
+
<% end %>
|
132
|
+
4
|
133
|
+
END
|
134
|
+
end
|
135
|
+
|
136
|
+
r.get 'grid-noblock' do
|
137
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
138
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
139
|
+
erb <<END
|
140
|
+
0
|
141
|
+
<% form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
142
|
+
1
|
143
|
+
<%= f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') %>
|
144
|
+
2
|
145
|
+
<% end %>
|
146
|
+
3
|
147
|
+
END
|
148
|
+
end
|
149
|
+
|
150
|
+
r.get 'grid-noblock-multiple' do
|
151
|
+
@artist = Artist.load(:name=>'A', :id=>2)
|
152
|
+
@artist.associations[:albums] = [Album.load(:name=>'N', :copies_sold=>2, :id=>1)]
|
153
|
+
erb <<END
|
154
|
+
0
|
155
|
+
<% form(@artist, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
156
|
+
1
|
157
|
+
<%= f.subform(:albums, :inputs=>[:name, :copies_sold], :legend=>'Foo', :grid=>true, :labels=>%w'Name Copies') %>
|
158
|
+
2
|
159
|
+
<% end %>
|
160
|
+
3
|
161
|
+
END
|
162
|
+
end
|
163
|
+
|
95
164
|
r.get 'hash' do
|
96
165
|
erb "<% form({:action=>'/baz'}, :obj=>[:foo]) do |f| %> <%= f.input(:first) %> <% end %>"
|
97
166
|
end
|
@@ -115,6 +184,10 @@ END
|
|
115
184
|
END
|
116
185
|
end
|
117
186
|
|
187
|
+
r.get 'hidden_tags' do
|
188
|
+
erb "<%= form([:foo, :bar], {:action=>'/baz'}, :hidden_tags=>[{'a'=>'b'}]) %>"
|
189
|
+
end
|
190
|
+
|
118
191
|
r.get 'noblock' do
|
119
192
|
erb "<%= form([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') %>"
|
120
193
|
end
|
@@ -127,61 +200,3 @@ END
|
|
127
200
|
erb "<%= form(:action=>'/baz') %>"
|
128
201
|
end
|
129
202
|
end
|
130
|
-
|
131
|
-
module FormeErbSpecs
|
132
|
-
extend Minitest::Spec::DSL
|
133
|
-
|
134
|
-
before do
|
135
|
-
o = Object.new
|
136
|
-
def o.puts(*) end
|
137
|
-
@rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o, 'SCRIPT_NAME'=>''}
|
138
|
-
end
|
139
|
-
|
140
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
141
|
-
sin_get('/').must_equal '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="Save"/> </form>'
|
142
|
-
end
|
143
|
-
|
144
|
-
it "#form should have inputs work with a block" do
|
145
|
-
sin_get('/inputs_block').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
|
146
|
-
end
|
147
|
-
|
148
|
-
it "#form should have inputs with fieldset_ol wrapper work with block" do
|
149
|
-
sin_get('/inputs_block_wrapper').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
|
150
|
-
end
|
151
|
-
|
152
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
153
|
-
sin_get('/nest').must_equal '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
|
154
|
-
end
|
155
|
-
|
156
|
-
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
157
|
-
sin_get('/nest_sep').must_equal '0 <form action="/baz"> 1 <p>FBB</p> 2 n1 <div> n2 <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> n3 </div> n4 <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> n5 3 </form>4'
|
158
|
-
end
|
159
|
-
|
160
|
-
it "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
|
161
|
-
sin_get('/nest_seq').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Foo</legend><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></label></fieldset> 2 n1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Artist</legend> n2 <label>Name2: <input id="album_artist_attributes_name2" name="album[artist_attributes][name2]" type="text" value="A2"/></label> n3 </fieldset> n4 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Bar</legend><label>Name3: <input id="album_artist_attributes_name3" name="album[artist_attributes][name3]" type="text" value="A3"/></label></fieldset> n5 3 </form>4'
|
162
|
-
end
|
163
|
-
|
164
|
-
it "#form should accept two hashes instead of requiring obj as first argument" do
|
165
|
-
sin_get('/hash').must_equal '<form action="/baz"> <input id="first" name="first" type="text" value="foo"/> </form>'
|
166
|
-
end
|
167
|
-
|
168
|
-
it "#form should deal with emitted code" do
|
169
|
-
sin_get('/legend').must_equal '<form action="/baz"> <p>FBB</p> <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> <p>FBB2</p> </form>'
|
170
|
-
end
|
171
|
-
|
172
|
-
it "#form should work with :inputs, :button, and :legend options" do
|
173
|
-
sin_get('/combined').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
|
174
|
-
end
|
175
|
-
|
176
|
-
it "#form should work without a block" do
|
177
|
-
sin_get('/noblock').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
|
178
|
-
end
|
179
|
-
|
180
|
-
it "#form should work without a block and still have hidden tags emitted" do
|
181
|
-
sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
|
182
|
-
end
|
183
|
-
|
184
|
-
it "#form with an empty form should work" do
|
185
|
-
sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
|
186
|
-
end
|
187
|
-
end
|