forme 1.8.0 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +50 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +181 -9
- data/lib/forme/bs3.rb +1 -1
- data/lib/forme/form.rb +1 -1
- data/lib/forme/transformers/error_handler.rb +46 -1
- data/lib/forme/transformers/formatter.rb +57 -43
- data/lib/forme/transformers/inputs_wrapper.rb +2 -2
- data/lib/forme/transformers/labeler.rb +19 -0
- data/lib/forme/transformers/serializer.rb +1 -12
- data/lib/forme/transformers/wrapper.rb +1 -1
- data/lib/forme/version.rb +1 -1
- data/lib/forme.rb +27 -0
- data/lib/roda/plugins/forme_route_csrf.rb +15 -1
- data/lib/roda/plugins/forme_set.rb +214 -0
- data/lib/sequel/plugins/forme.rb +10 -5
- data/lib/sequel/plugins/forme_set.rb +50 -28
- data/spec/bs3_reference_spec.rb +4 -4
- data/spec/bs3_sequel_plugin_spec.rb +45 -45
- data/spec/bs3_spec.rb +1 -1
- data/spec/erb_helper.rb +2 -2
- data/spec/forme_spec.rb +75 -18
- data/spec/rails_integration_spec.rb +43 -26
- data/spec/roda_integration_spec.rb +357 -1
- data/spec/sequel_i18n_plugin_spec.rb +5 -4
- data/spec/sequel_plugin_spec.rb +61 -54
- data/spec/sequel_set_plugin_spec.rb +63 -14
- data/spec/spec_helper.rb +2 -2
- metadata +25 -6
data/spec/bs3_reference_spec.rb
CHANGED
@@ -38,12 +38,12 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
38
38
|
|
39
39
|
describe 'from a Sequel model' do
|
40
40
|
it "should create a correct input[:text] tag from Sequel model" do
|
41
|
-
@c.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="c"/></div>'
|
41
|
+
@c.input(:name).to_s.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>'
|
42
42
|
end
|
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" 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 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
|
@@ -185,12 +185,12 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
185
185
|
|
186
186
|
describe 'from a Sequel model' do
|
187
187
|
it "should create a correct input[:text] tag from Sequel model" do
|
188
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
188
|
+
@c.input(:name, :as=>:textarea).to_s.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>'
|
189
189
|
end
|
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" 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 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
|
@@ -31,18 +31,18 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should use a text field for strings" do
|
34
|
-
@b.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/></div>'
|
35
|
-
@c.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="c"/></div>'
|
34
|
+
@b.input(:name).to_s.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="b"/></div>'
|
35
|
+
@c.input(:name).to_s.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>'
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should allow :as=>:textarea to use a textarea" do
|
39
|
-
@b.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">b</textarea></div>'
|
40
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
39
|
+
@b.input(:name, :as=>:textarea).to_s.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]">b</textarea></div>'
|
40
|
+
@c.input(:name, :as=>:textarea).to_s.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>'
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should allow :type=>:textarea to use a textarea" do
|
44
|
-
@b.input(:name, :type=>:textarea).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">b</textarea></div>'
|
45
|
-
@c.input(:name, :type=>:textarea).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
44
|
+
@b.input(:name, :type=>:textarea).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">b</textarea></div>'
|
45
|
+
@c.input(:name, :type=>:textarea).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea></div>'
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should use number inputs for integers" do
|
@@ -65,22 +65,22 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
65
65
|
it "should include type as wrapper class" do
|
66
66
|
@ab.values[:created_at] = DateTime.new(2011, 6, 5)
|
67
67
|
f = Forme::Form.new(@ab, :config=>:bs3)
|
68
|
-
f.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/></div>'
|
68
|
+
f.input(:name).to_s.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="b"/></div>'
|
69
69
|
f.input(:release_date).to_s.must_equal '<div class="date form-group"><label for="album_release_date">Release date</label> <input class="form-control" id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></div>'
|
70
70
|
f.input(:created_at).to_s.must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>'
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should include required * in label if required" do
|
74
|
-
@b.input(:name, :required=>true).to_s.must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" name="album[name]" required="required" type="text" value="b"/></div>'
|
74
|
+
@b.input(:name, :required=>true).to_s.must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should add required to label even if :label option specified" do
|
78
|
-
@b.input(:name, :required=>true, :label=>'Foo').to_s.must_equal '<div class="form-group required string"><label for="album_name">Foo<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" name="album[name]" required="required" type="text" value="b"/></div>'
|
78
|
+
@b.input(:name, :required=>true, :label=>'Foo').to_s.must_equal '<div class="form-group required string"><label for="album_name">Foo<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should include required wrapper class if required" do
|
82
82
|
f = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
83
|
-
f.input(:name, :required=>true).to_s.must_equal '<li class="string required"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" name="album[name]" required="required" type="text" value="b"/></li>'
|
83
|
+
f.input(:name, :required=>true).to_s.must_equal '<li class="string required"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></li>'
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should use a select box for tri-valued boolean fields" do
|
@@ -323,7 +323,7 @@ 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" 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 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
|
@@ -357,90 +357,90 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
357
357
|
|
358
358
|
it "should add required attribute if the column doesn't support nil values" do
|
359
359
|
def @ab.db_schema; h = super.dup; h[:name] = h[:name].merge(:allow_null=>false); h end
|
360
|
-
@b.input(:name).to_s.must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" name="album[name]" required="required" type="text" value="b"/></div>'
|
360
|
+
@b.input(:name).to_s.must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
361
361
|
end
|
362
362
|
|
363
363
|
it "should use allow nested forms with many_to_one associations" do
|
364
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
364
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
365
365
|
end
|
366
366
|
|
367
367
|
it "should have #subform respect an :inputs option" do
|
368
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
368
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
369
369
|
end
|
370
370
|
|
371
371
|
it "should have #subform respect an :obj option overriding the object to use" do
|
372
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :obj=>Artist.new(:name=>'b'))}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="b"/></div></fieldset></form>'
|
372
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :obj=>Artist.new(:name=>'b'))}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="b"/></div></fieldset></form>'
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should have #subform respect a :legend option if :inputs is used" do
|
376
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>'Foo')}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
376
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>'Foo')}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should have #subform respect a callable :legend option if :inputs is used" do
|
380
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>proc{|o| "Foo - #{o.name}"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo - a</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
380
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>proc{|o| "Foo - #{o.name}"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo - a</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
381
381
|
end
|
382
382
|
|
383
383
|
it "should not add hidden primary key field for new many_to_one associated objects" do
|
384
384
|
@ab.associations[:artist] = Artist.new(:name=>'a')
|
385
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
385
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
386
386
|
end
|
387
387
|
|
388
388
|
it "should use allow nested forms with one_to_one associations" do
|
389
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:album_info, :obj=>AlbumInfo.new(:info=>'a')){f.input(:info)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Album info</legend><div class="form-group string"><label for="album_album_info_attributes_info">Info</label> <input class="form-control" id="album_album_info_attributes_info" name="album[album_info_attributes][info]" type="text" value="a"/></div></fieldset></form>'
|
389
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:album_info, :obj=>AlbumInfo.new(:info=>'a')){f.input(:info)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Album info</legend><div class="form-group string"><label for="album_album_info_attributes_info">Info</label> <input class="form-control" id="album_album_info_attributes_info" maxlength="255" name="album[album_info_attributes][info]" type="text" value="a"/></div></fieldset></form>'
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should use allow nested forms with one_to_many associations" do
|
393
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
393
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
394
394
|
end
|
395
395
|
|
396
396
|
it "should support :obj option for *_to_many associations" do
|
397
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
|
397
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
|
398
398
|
end
|
399
399
|
|
400
400
|
it "should auto number legends when using subform with inputs for *_to_many associations" do
|
401
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
401
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
402
402
|
end
|
403
403
|
|
404
404
|
it "should support callable :legend option when using subform with inputs for *_to_many associations" do
|
405
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track 0 (m)</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 1 (n)</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
405
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track 0 (m)</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 1 (n)</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
406
406
|
end
|
407
407
|
|
408
408
|
it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
|
409
409
|
@ab.associations[:tracks] = [Track.new(:name=>'m'), Track.new(:name=>'n')]
|
410
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
410
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
411
411
|
end
|
412
412
|
|
413
413
|
it "should use allow nested forms with many_to_many associations" do
|
414
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
414
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
415
415
|
end
|
416
416
|
|
417
417
|
it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
|
418
418
|
@ab.associations[:tags] = [Tag.new(:name=>'s'), Tag.new(:name=>'t')]
|
419
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
419
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
420
420
|
end
|
421
421
|
|
422
422
|
it "should handle multiple nested levels" do
|
423
|
-
Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_name" name="artist[albums_attributes][0][name]" type="text" value="b"/></div><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_0_name" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_1_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_1_name" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
|
423
|
+
Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></div><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_1_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
|
424
424
|
end
|
425
425
|
|
426
426
|
it "should have #subform :grid option create a grid" do
|
427
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
427
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
428
428
|
end
|
429
429
|
|
430
430
|
it "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
|
431
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
431
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
432
432
|
end
|
433
433
|
|
434
434
|
it "should have #subform :grid option handle :legend and :labels options" do
|
435
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
435
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should have #subform :grid option handle :legend and :labels nil values" do
|
439
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
439
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
440
440
|
end
|
441
441
|
|
442
442
|
it "should have #subform :grid option handle :skip_primary_key option" do
|
443
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
443
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
444
444
|
end
|
445
445
|
|
446
446
|
end
|
@@ -452,22 +452,22 @@ describe "Forme Sequel plugin default input types based on column names" do
|
|
452
452
|
end
|
453
453
|
|
454
454
|
it "should use password input with no value for string columns with name password" do
|
455
|
-
f(:password).to_s.must_equal '<div class="form-group string"><label for="test_password">Password</label> <input class="form-control" id="test_password" name="test[password]" type="password"/></div>'
|
455
|
+
f(:password).to_s.must_equal '<div class="form-group string"><label for="test_password">Password</label> <input class="form-control" id="test_password" maxlength="255" name="test[password]" type="password"/></div>'
|
456
456
|
end
|
457
457
|
|
458
458
|
it "should use email input for string columns with name email" do
|
459
|
-
f(:email).to_s.must_equal '<div class="form-group string"><label for="test_email">Email</label> <input class="form-control" id="test_email" name="test[email]" type="email" value="foo"/></div>'
|
459
|
+
f(:email).to_s.must_equal '<div class="form-group string"><label for="test_email">Email</label> <input class="form-control" id="test_email" maxlength="255" name="test[email]" type="email" value="foo"/></div>'
|
460
460
|
end
|
461
461
|
|
462
462
|
it "should use tel input for string columns with name phone or fax" do
|
463
|
-
f(:phone).to_s.must_equal '<div class="form-group string"><label for="test_phone">Phone</label> <input class="form-control" id="test_phone" name="test[phone]" type="tel" value="foo"/></div>'
|
464
|
-
f(:fax).to_s.must_equal '<div class="form-group string"><label for="test_fax">Fax</label> <input class="form-control" id="test_fax" name="test[fax]" type="tel" value="foo"/></div>'
|
463
|
+
f(:phone).to_s.must_equal '<div class="form-group string"><label for="test_phone">Phone</label> <input class="form-control" id="test_phone" maxlength="255" name="test[phone]" type="tel" value="foo"/></div>'
|
464
|
+
f(:fax).to_s.must_equal '<div class="form-group string"><label for="test_fax">Fax</label> <input class="form-control" id="test_fax" maxlength="255" name="test[fax]" type="tel" value="foo"/></div>'
|
465
465
|
end
|
466
466
|
|
467
467
|
it "should use url input for string columns with name url, uri, or website" do
|
468
|
-
f(:url).to_s.must_equal '<div class="form-group string"><label for="test_url">Url</label> <input class="form-control" id="test_url" name="test[url]" type="url" value="foo"/></div>'
|
469
|
-
f(:uri).to_s.must_equal '<div class="form-group string"><label for="test_uri">Uri</label> <input class="form-control" id="test_uri" name="test[uri]" type="url" value="foo"/></div>'
|
470
|
-
f(:website).to_s.must_equal '<div class="form-group string"><label for="test_website">Website</label> <input class="form-control" id="test_website" name="test[website]" type="url" value="foo"/></div>'
|
468
|
+
f(:url).to_s.must_equal '<div class="form-group string"><label for="test_url">Url</label> <input class="form-control" id="test_url" maxlength="255" name="test[url]" type="url" value="foo"/></div>'
|
469
|
+
f(:uri).to_s.must_equal '<div class="form-group string"><label for="test_uri">Uri</label> <input class="form-control" id="test_uri" maxlength="255" name="test[uri]" type="url" value="foo"/></div>'
|
470
|
+
f(:website).to_s.must_equal '<div class="form-group string"><label for="test_website">Website</label> <input class="form-control" id="test_website" maxlength="255" name="test[website]" type="url" value="foo"/></div>'
|
471
471
|
end
|
472
472
|
end
|
473
473
|
|
@@ -491,11 +491,11 @@ describe "Forme Sequel::Model validation parsing" do
|
|
491
491
|
end
|
492
492
|
|
493
493
|
it "should turn format into a pattern" do
|
494
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="[A-z]+" type="text"/></div>'
|
494
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).to_s.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]" pattern="[A-z]+" type="text"/></div>'
|
495
495
|
end
|
496
496
|
|
497
497
|
it "should respect :title option for format" do
|
498
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="[A-z]+" title="Foo" type="text"/></div>'
|
498
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).to_s.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]" pattern="[A-z]+" title="Foo" type="text"/></div>'
|
499
499
|
end
|
500
500
|
|
501
501
|
it "should use maxlength for length :maximum, :is, and :within" do
|
@@ -506,18 +506,18 @@ describe "Forme Sequel::Model validation parsing" do
|
|
506
506
|
end
|
507
507
|
|
508
508
|
it "should turn numericality into a pattern" do
|
509
|
-
f(:validates_numericality_of, :name).input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></div>'
|
509
|
+
f(:validates_numericality_of, :name).input(:name).to_s.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]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></div>'
|
510
510
|
end
|
511
511
|
|
512
512
|
it "should turn numericality :only_integer into a pattern" do
|
513
|
-
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></div>'
|
513
|
+
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).to_s.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]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></div>'
|
514
514
|
end
|
515
515
|
|
516
516
|
it "should respect :title option for numericality" do
|
517
|
-
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></div>'
|
517
|
+
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).to_s.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]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></div>'
|
518
518
|
end
|
519
519
|
|
520
520
|
it "should respect :placeholder option for any validation" do
|
521
|
-
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" placeholder="must be unique" type="text"/></div>'
|
521
|
+
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).to_s.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]" placeholder="must be unique" type="text"/></div>'
|
522
522
|
end
|
523
523
|
end
|
data/spec/bs3_spec.rb
CHANGED
@@ -628,7 +628,7 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
628
628
|
end
|
629
629
|
|
630
630
|
it "inputs should accept a :formatter option to use a custom formatter" do
|
631
|
-
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <span>1</span></div>'
|
631
|
+
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <span class="readonly-text">1</span></div>'
|
632
632
|
@f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" type="text" value="1"/></div>'
|
633
633
|
@f.input(:text, :formatter=>:bs3_readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<div class="form-group"><label>Foo</label> <input class="form-control" readonly="readonly" type="text" value="1"/></div>'
|
634
634
|
end
|
data/spec/erb_helper.rb
CHANGED
@@ -154,11 +154,11 @@ module FormeErbSpecs
|
|
154
154
|
end
|
155
155
|
|
156
156
|
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
157
|
-
sin_get('/nest_sep').must_equal
|
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
158
|
end
|
159
159
|
|
160
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
|
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
162
|
end
|
163
163
|
|
164
164
|
it "#form should accept two hashes instead of requiring obj as first argument" do
|
data/spec/forme_spec.rb
CHANGED
@@ -116,13 +116,13 @@ describe "Forme plain forms" do
|
|
116
116
|
|
117
117
|
it "should consider form's :errors hash based on the :key option" do
|
118
118
|
@f.opts[:errors] = { 'foo' => 'must be present' }
|
119
|
-
@f.input(:text, :key=>"foo").to_s.must_equal "<input class=\"error\" id=\"foo\" name=\"foo\" type=\"text\"/><span class=\"error_message\">must be present</span>"
|
119
|
+
@f.input(:text, :key=>"foo").to_s.must_equal "<input aria-describedby=\"foo_error_message\" aria-invalid=\"true\" class=\"error\" id=\"foo\" name=\"foo\" type=\"text\"/><span class=\"error_message\" id=\"foo_error_message\">must be present</span>"
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should consider form's :errors hash based on the :key option when using namespaces" do
|
123
123
|
@f.opts[:errors] = { 'bar' => { 'foo' => 'must be present' } }
|
124
124
|
@f.with_opts(:namespace=>['bar']) do
|
125
|
-
@f.input(:text, :key=>"foo").to_s.must_equal "<input class=\"error\" id=\"bar_foo\" name=\"bar[foo]\" type=\"text\"/><span class=\"error_message\">must be present</span>"
|
125
|
+
@f.input(:text, :key=>"foo").to_s.must_equal "<input aria-describedby=\"bar_foo_error_message\" aria-invalid=\"true\" class=\"error\" id=\"bar_foo\" name=\"bar[foo]\" type=\"text\"/><span class=\"error_message\" id=\"bar_foo_error_message\">must be present</span>"
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -301,6 +301,10 @@ describe "Forme plain forms" do
|
|
301
301
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
302
302
|
end
|
303
303
|
|
304
|
+
it "should use labels for select boxes for dates if the :as=>:select and :select_labels options are given" do
|
305
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_labels=>{:year=>'Y', :month=>'M', :day=>'D'}, :labeler=>:explicit).to_s.must_equal %{<label class="label-before" for="bar">Y</label><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<label class="label-before" for="bar_month">M</label><select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<label class="label-before" for="bar_day">D</label><select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
306
|
+
end
|
307
|
+
|
304
308
|
it "should allow ordering date select boxes via :order" do
|
305
309
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
|
306
310
|
end
|
@@ -313,6 +317,10 @@ describe "Forme plain forms" do
|
|
313
317
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
314
318
|
end
|
315
319
|
|
320
|
+
it "should support :select_options with both values and text for dates when :as=>:select is given" do
|
321
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>[[2011, 'A'], [2012, 'B']]}).to_s.must_equal %{<select id="bar" name="foo[year]"><option selected="selected" value="2011">A</option><option value="2012">B</option></select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
322
|
+
end
|
323
|
+
|
316
324
|
it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
|
317
325
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.must_equal %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
|
318
326
|
end
|
@@ -338,6 +346,10 @@ describe "Forme plain forms" do
|
|
338
346
|
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<select><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
|
339
347
|
end
|
340
348
|
|
349
|
+
it "should have select work with false values" do
|
350
|
+
@f.input(:select, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<select><option value="true">1</option><option selected="selected" value="false">2</option></select>'
|
351
|
+
end
|
352
|
+
|
341
353
|
it "should create select tag with option groups" do
|
342
354
|
@f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup label="e"><option value="3">c</option></optgroup></select>'
|
343
355
|
end
|
@@ -391,6 +403,10 @@ describe "Forme plain forms" do
|
|
391
403
|
@f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
|
392
404
|
end
|
393
405
|
|
406
|
+
it "should have radioset work with false values" do
|
407
|
+
@f.input(:radioset, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<label class="option"><input type="radio" value="true"/> 1</label><label class="option"><input checked="checked" type="radio" value="false"/> 2</label>'
|
408
|
+
end
|
409
|
+
|
394
410
|
it "should create set of radio buttons with options and values" do
|
395
411
|
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
|
396
412
|
end
|
@@ -425,7 +441,11 @@ describe "Forme plain forms" do
|
|
425
441
|
end
|
426
442
|
|
427
443
|
it "should create set of radio buttons with :error and :error_attr options" do
|
428
|
-
@f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input class="error" type="radio" value="3"/> 3</label><span bar="baz" class="error_message">foo</span>'
|
444
|
+
@f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input aria-invalid="true" class="error" type="radio" value="3"/> 3</label><span bar="baz" class="error_message">foo</span>'
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should support custom error_handler for set of radio buttons" do
|
448
|
+
@f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}, :error_handler=>lambda{|tag, input| input.tag(:div, {}, tag)}).to_s.must_equal '<div><label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label></div>'
|
429
449
|
end
|
430
450
|
|
431
451
|
it "should create set of checkbox buttons" do
|
@@ -437,6 +457,10 @@ describe "Forme plain forms" do
|
|
437
457
|
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
|
438
458
|
end
|
439
459
|
|
460
|
+
it "should have radioset work with false values" do
|
461
|
+
@f.input(:checkboxset, :options=>[[1, true], [2, false]], :value=>false).to_s.must_equal '<label class="option"><input type="checkbox" value="true"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="false"/> 2</label>'
|
462
|
+
end
|
463
|
+
|
440
464
|
it "should support :wrapper and :tag_wrapper for checkboxsets" do
|
441
465
|
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_wrapper=>:div, :wrapper=>:li).to_s.must_equal '<li><div><label class="option"><input type="checkbox" value="1"/> a</label></div><div><label class="option"><input type="checkbox" value="2"/> b</label></div><div><label class="option"><input type="checkbox" value="3"/> c</label></div></li>'
|
442
466
|
end
|
@@ -445,10 +469,26 @@ describe "Forme plain forms" do
|
|
445
469
|
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo').to_s.must_equal '<span class="label">foo</span><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
|
446
470
|
end
|
447
471
|
|
472
|
+
it "should support fieldset/legend for checkboxsets" do
|
473
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :labeler=>:legend, :wrapper=>:fieldset).to_s.must_equal '<fieldset><legend>foo</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should support legend with attributes for checkboxsets" do
|
477
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :label_attr=>{:class=>"baz"}, :tag_label_attr=>{:class=>"bar"}, :labeler=>:legend, :wrapper=>:fieldset).to_s.must_equal '<fieldset><legend class="baz">foo</legend><label class="bar"><input type="checkbox" value="1"/> a</label><label class="bar"><input type="checkbox" value="2"/> b</label><label class="bar"><input type="checkbox" value="3"/> c</label></fieldset>'
|
478
|
+
end
|
479
|
+
|
480
|
+
it "should support legend with attributes for checkboxsets, handling errors with :error_handler=>:after_legend" do
|
481
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :id=>:quux, :label=>'foo', :label_attr=>{:class=>"baz"}, :tag_label_attr=>{:class=>"bar"}, :labeler=>:legend, :wrapper=>:fieldset, :error=>'bar2', :error_handler=>:after_legend).to_s.must_equal '<fieldset><legend class="baz">foo</legend><span class="error_message" id="quux_1_error_message">bar2</span><label class="bar"><input aria-describedby="quux_1_error_message" aria-invalid="true" class="error" id="quux_1" type="checkbox" value="1"/> a</label><label class="bar"><input id="quux_2" type="checkbox" value="2"/> b</label><label class="bar"><input id="quux_3" type="checkbox" value="3"/> c</label></fieldset>'
|
482
|
+
end
|
483
|
+
|
448
484
|
it "should support :tag_labeler for checkboxsets" do
|
449
485
|
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_labeler=>:explicit).to_s.must_equal '<input type="checkbox" value="1"/><label class="option label-after">a</label><input type="checkbox" value="2"/><label class="option label-after">b</label><input type="checkbox" value="3"/><label class="option label-after">c</label>'
|
450
486
|
end
|
451
487
|
|
488
|
+
it "should support custom :labeler for checkboxsets" do
|
489
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo', :labeler=>lambda{|tag, input| input.tag(:div, {}, tag)}).to_s.must_equal '<div><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label></div>'
|
490
|
+
end
|
491
|
+
|
452
492
|
it "should create set of checkbox buttons with options and values with hashes" do
|
453
493
|
@f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
|
454
494
|
end
|
@@ -479,7 +519,7 @@ describe "Forme plain forms" do
|
|
479
519
|
end
|
480
520
|
|
481
521
|
it "should respect the :error option for checkbox sets" do
|
482
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
|
522
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input aria-invalid="true" class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
|
483
523
|
end
|
484
524
|
|
485
525
|
it "should create set of checkbox buttons with fieldsets and legends for optgroups" do
|
@@ -546,19 +586,23 @@ describe "Forme plain forms" do
|
|
546
586
|
end
|
547
587
|
|
548
588
|
it "should automatically note the input has errors if :error option is used" do
|
549
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<input class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
589
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<input aria-invalid="true" class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
550
590
|
end
|
551
591
|
|
552
592
|
it "should add an error message after the label" do
|
553
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<label>Foo: <input class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
|
593
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<label>Foo: <input aria-invalid="true" class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
|
554
594
|
end
|
555
595
|
|
556
596
|
it "should add to existing :class option if :error option is used" do
|
557
|
-
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<input class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
597
|
+
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<input aria-invalid="true" class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
558
598
|
end
|
559
599
|
|
560
600
|
it "should respect :error_attr option for setting the attributes for the error message span" do
|
561
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
|
601
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input aria-invalid="true" class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
|
602
|
+
end
|
603
|
+
|
604
|
+
it "should use aria-describedby and aria-invalid tags for errors with where the id attribute can be determined" do
|
605
|
+
@f.input(:text, :error=>'Bad Stuff!', :id=>:bar, :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input aria-describedby="bar_error_message" aria-invalid="true" class="error" id="bar" type="text" value="foo"/><span class="foo error_message" id="bar_error_message">Bad Stuff!</span>'
|
562
606
|
end
|
563
607
|
|
564
608
|
it "#open should return an opening tag" do
|
@@ -684,11 +728,11 @@ describe "Forme plain forms" do
|
|
684
728
|
end
|
685
729
|
|
686
730
|
it "inputs should have helper displayed inside wrapper, after error" do
|
687
|
-
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li><input class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
|
731
|
+
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li><input aria-invalid="true" class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
|
688
732
|
end
|
689
733
|
|
690
734
|
it "inputs should accept a :formatter option to use a custom formatter" do
|
691
|
-
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span>1</span></label>'
|
735
|
+
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span class="readonly-text">1</span></label>'
|
692
736
|
@f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <input type="text" value="1"/></label>'
|
693
737
|
end
|
694
738
|
|
@@ -717,7 +761,7 @@ describe "Forme plain forms" do
|
|
717
761
|
end
|
718
762
|
|
719
763
|
it "inputs should accept a :error_handler option to use a custom error_handler" do
|
720
|
-
@f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>!!! bar'
|
764
|
+
@f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo"></textarea>!!! bar'
|
721
765
|
end
|
722
766
|
|
723
767
|
it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
|
@@ -733,7 +777,7 @@ describe "Forme plain forms" do
|
|
733
777
|
end
|
734
778
|
|
735
779
|
it "inputs should accept a :error_handler=>nil option to not use an error_handler" do
|
736
|
-
@f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>'
|
780
|
+
@f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea aria-invalid="true" class="error" id="foo"></textarea>'
|
737
781
|
end
|
738
782
|
|
739
783
|
it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
|
@@ -807,7 +851,7 @@ describe "Forme custom" do
|
|
807
851
|
end
|
808
852
|
|
809
853
|
it "error_handlers can be specified as a proc" do
|
810
|
-
Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.must_equal '<textarea class="error" name="foo"></textarea>!!! bar'
|
854
|
+
Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.must_equal '<textarea aria-invalid="true" class="error" name="foo"></textarea>!!! bar'
|
811
855
|
end
|
812
856
|
|
813
857
|
it "wrappers can be specified as a proc" do
|
@@ -833,9 +877,8 @@ describe "Forme built-in custom" do
|
|
833
877
|
Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.must_equal '<textarea></textarea>'
|
834
878
|
end
|
835
879
|
|
836
|
-
it "formatter: readonly uses spans for
|
837
|
-
Forme::Form.new(:formatter=>:readonly).input(:
|
838
|
-
Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span>Bar</span></label>"
|
880
|
+
it "formatter: readonly uses spans for text input fields and disables radio/checkbox fields" do
|
881
|
+
Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span class=\"readonly-text\">Bar</span></label>"
|
839
882
|
Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
|
840
883
|
Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
|
841
884
|
Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
|
@@ -843,6 +886,20 @@ describe "Forme built-in custom" do
|
|
843
886
|
Forme::Form.new(:formatter=>:readonly).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "<label>Foo: <span>2</span></label>"
|
844
887
|
end
|
845
888
|
|
889
|
+
it "formatter: readonly removes hidden inputs" do
|
890
|
+
Forme::Form.new(:formatter=>:readonly).input(:hidden, :value=>"Bar").to_s.must_equal ""
|
891
|
+
end
|
892
|
+
|
893
|
+
it "formatter: readonly formats text into paragraphs for textarea inputs" do
|
894
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>"\n Bar\nBaz\n\nQuuz\n\n1\n2 \n").to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\"><p> Bar<br />Baz</p><p>Quuz</p><p>1<br />2 </p></div></label>"
|
895
|
+
end
|
896
|
+
|
897
|
+
it "formatter: readonly does not format nil, raw string, or non-string inputs" do
|
898
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo").to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\"></div></label>"
|
899
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>Forme.raw("Bar\n\nBaz")).to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\">Bar\n\nBaz</div></label>"
|
900
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>1).to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\">1</div></label>"
|
901
|
+
end
|
902
|
+
|
846
903
|
it "formatter: readonly should ignore submit buttons" do
|
847
904
|
Forme.form({}, :formatter=>:readonly, :button=>'a').to_s.must_equal '<form></form>'
|
848
905
|
end
|
@@ -856,7 +913,7 @@ describe "Forme built-in custom" do
|
|
856
913
|
end
|
857
914
|
|
858
915
|
it "labeler: explicit should handle tags with errors" do
|
859
|
-
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
|
916
|
+
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><input aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo" type="text" value="f"/><span class="error_message" id="foo_error_message">Bad Stuff!</span>'
|
860
917
|
end
|
861
918
|
|
862
919
|
it "wrapper: li wraps tag in an li" do
|
@@ -894,7 +951,7 @@ describe "Forme built-in custom" do
|
|
894
951
|
end
|
895
952
|
|
896
953
|
it "wrapper: trtd should use at most 2 td tags" do
|
897
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
|
954
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea aria-describedby="foo_error_message" aria-invalid="true" class="error" id="foo"></textarea><span class="error_message" id="foo_error_message">Bar</span></td></tr>'
|
898
955
|
end
|
899
956
|
|
900
957
|
it "wrapper: trtd should handle inputs with label after" do
|