forme 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +14 -0
- data/lib/forme.rb +25 -0
- data/lib/forme/transformers/formatter.rb +22 -9
- data/lib/forme/transformers/serializer.rb +1 -12
- data/lib/forme/version.rb +1 -1
- data/lib/sequel/plugins/forme.rb +5 -1
- data/lib/sequel/plugins/forme_set.rb +1 -1
- 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 +25 -4
- data/spec/rails_integration_spec.rb +4 -4
- data/spec/sequel_i18n_plugin_spec.rb +4 -4
- data/spec/sequel_plugin_spec.rb +48 -49
- data/spec/sequel_set_plugin_spec.rb +55 -13
- metadata +2 -2
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
@@ -338,6 +338,10 @@ describe "Forme plain forms" do
|
|
338
338
|
@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
339
|
end
|
340
340
|
|
341
|
+
it "should have select work with false values" do
|
342
|
+
@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>'
|
343
|
+
end
|
344
|
+
|
341
345
|
it "should create select tag with option groups" do
|
342
346
|
@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
347
|
end
|
@@ -391,6 +395,10 @@ describe "Forme plain forms" do
|
|
391
395
|
@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
396
|
end
|
393
397
|
|
398
|
+
it "should have radioset work with false values" do
|
399
|
+
@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>'
|
400
|
+
end
|
401
|
+
|
394
402
|
it "should create set of radio buttons with options and values" do
|
395
403
|
@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
404
|
end
|
@@ -437,6 +445,10 @@ describe "Forme plain forms" do
|
|
437
445
|
@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
446
|
end
|
439
447
|
|
448
|
+
it "should have radioset work with false values" do
|
449
|
+
@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>'
|
450
|
+
end
|
451
|
+
|
440
452
|
it "should support :wrapper and :tag_wrapper for checkboxsets" do
|
441
453
|
@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
454
|
end
|
@@ -688,7 +700,7 @@ describe "Forme plain forms" do
|
|
688
700
|
end
|
689
701
|
|
690
702
|
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>'
|
703
|
+
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span class="readonly-text">1</span></label>'
|
692
704
|
@f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <input type="text" value="1"/></label>'
|
693
705
|
end
|
694
706
|
|
@@ -833,9 +845,8 @@ describe "Forme built-in custom" do
|
|
833
845
|
Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.must_equal '<textarea></textarea>'
|
834
846
|
end
|
835
847
|
|
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>"
|
848
|
+
it "formatter: readonly uses spans for text input fields and disables radio/checkbox fields" do
|
849
|
+
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
850
|
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
851
|
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
852
|
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 +854,16 @@ describe "Forme built-in custom" do
|
|
843
854
|
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
855
|
end
|
845
856
|
|
857
|
+
it "formatter: readonly formats text into paragraphs for textarea inputs" do
|
858
|
+
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>"
|
859
|
+
end
|
860
|
+
|
861
|
+
it "formatter: readonly does not format nil, raw string, or non-string inputs" do
|
862
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo").to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\"></div></label>"
|
863
|
+
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>"
|
864
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>1).to_s.must_equal "<label>Foo: <div class=\"readonly-textarea\">1</div></label>"
|
865
|
+
end
|
866
|
+
|
846
867
|
it "formatter: readonly should ignore submit buttons" do
|
847
868
|
Forme.form({}, :formatter=>:readonly, :button=>'a').to_s.must_equal '<form></form>'
|
848
869
|
end
|
@@ -219,20 +219,20 @@ describe "Forme Rails integration" do
|
|
219
219
|
end
|
220
220
|
|
221
221
|
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
222
|
-
sin_get('/nest_sep').must_equal
|
222
|
+
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'
|
223
223
|
end
|
224
224
|
|
225
225
|
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
226
|
-
sin_get('/nest_inputs').must_equal
|
226
|
+
sin_get('/nest_inputs').must_equal '0 <form action="/baz"> 1 <p>FBB</p> 2 n1 <fieldset class="inputs"> n2 <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> n3 </fieldset> 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'
|
227
227
|
end
|
228
228
|
|
229
229
|
unless defined?(JRUBY_VERSION) && JRUBY_VERSION =~ /\A9\.0/ && defined?(ActionPack::VERSION::STRING) && ActionPack::VERSION::STRING >= '5.1'
|
230
230
|
it "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
|
231
|
-
sin_get('/nest_seq').sub(%r{<input name
|
231
|
+
sin_get('/nest_seq').sub(%r{<input name="authenticity_token" type="hidden" value="([^"]+)"/>}, '<input name="authenticity_token" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="authenticity_token" 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'
|
232
232
|
end
|
233
233
|
|
234
234
|
it "#form should work without a block with hidden tags" do
|
235
|
-
sin_get('/noblock_post').sub(%r{<input name
|
235
|
+
sin_get('/noblock_post').sub(%r{<input name="authenticity_token" type="hidden" value="([^"]+)"/>}, '<input name="authenticity_token" type="hidden" value="csrf"/>').must_equal '<form method="post"><input name="authenticity_token" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
@@ -12,19 +12,19 @@ describe "Forme Sequel::Model forms" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should not change the usual label input if translation is not present" do
|
15
|
-
@b.input(:name).to_s.must_equal '<label>Name: <input id="invoice_name" name="invoice[name]" type="text" value="b"/></label>'
|
15
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input id="invoice_name" maxlength="255" name="invoice[name]" type="text" value="b"/></label>'
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should use the translation for the label if present" do
|
19
|
-
@b.input(:summary).to_s.must_equal '<label>Brief Description: <input id="invoice_summary" name="invoice[summary]" type="text" value="a brief summary"/></label>'
|
19
|
+
@b.input(:summary).to_s.must_equal '<label>Brief Description: <input id="invoice_summary" maxlength="255" name="invoice[summary]" type="text" value="a brief summary"/></label>'
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not change the usual legend for the subform if the translation is not present" do
|
23
|
-
Forme.form(Firm[1]){|f| f.subform(:invoices){ f.input(:name) }}.to_s.must_equal
|
23
|
+
Forme.form(Firm[1]){|f| f.subform(:invoices){ f.input(:name) }}.to_s.must_equal '<form class="forme firm" method="post"><input id="firm_invoices_attributes_0_id" name="firm[invoices_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Invoice #1</legend><label>Name: <input id="firm_invoices_attributes_0_name" maxlength="255" name="firm[invoices_attributes][0][name]" type="text" value="b"/></label></fieldset></form>'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should use the translation for the legend on the subform if present" do
|
27
|
-
Forme.form(Firm[1]){|f| f.subform(:clients){ f.input(:name) }}.to_s.must_equal
|
27
|
+
Forme.form(Firm[1]){|f| f.subform(:clients){ f.input(:name) }}.to_s.must_equal '<form class="forme firm" method="post"><input id="firm_clients_attributes_0_id" name="firm[clients_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Clientes</legend><label>Name: <input id="firm_clients_attributes_0_name" maxlength="255" name="firm[clients_attributes][0][name]" type="text" value="a great client"/></label></fieldset></form>'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/sequel_plugin_spec.rb
CHANGED
@@ -30,18 +30,18 @@ describe "Forme Sequel::Model forms" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should use a text field for strings" do
|
33
|
-
@b.input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" type="text" value="b"/></label>'
|
34
|
-
@c.input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" type="text" value="c"/></label>'
|
33
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label>'
|
34
|
+
@c.input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text" value="c"/></label>'
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should allow :as=>:textarea to use a textarea" do
|
38
|
-
@b.input(:name, :as=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" name="album[name]">b</textarea></label>'
|
39
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" name="album[name]">c</textarea></label>'
|
38
|
+
@b.input(:name, :as=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" maxlength="255" name="album[name]">b</textarea></label>'
|
39
|
+
@c.input(:name, :as=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" maxlength="255" name="album[name]">c</textarea></label>'
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should allow :type=>:textarea to use a textarea" do
|
43
|
-
@b.input(:name, :type=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" name="album[name]">b</textarea></label>'
|
44
|
-
@c.input(:name, :type=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" name="album[name]">c</textarea></label>'
|
43
|
+
@b.input(:name, :type=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" maxlength="255" name="album[name]">b</textarea></label>'
|
44
|
+
@c.input(:name, :type=>:textarea).to_s.must_equal '<label>Name: <textarea id="album_name" maxlength="255" name="album[name]">c</textarea></label>'
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not include labels for hidden inputs" do
|
@@ -72,26 +72,26 @@ describe "Forme Sequel::Model forms" do
|
|
72
72
|
it "should include type as wrapper class" do
|
73
73
|
@ab.values[:created_at] = DateTime.new(2011, 6, 5)
|
74
74
|
f = Forme::Form.new(@ab, :wrapper=>:li)
|
75
|
-
f.input(:name).to_s.must_equal '<li class="string"><label>Name: <input id="album_name" name="album[name]" type="text" value="b"/></label></li>'
|
75
|
+
f.input(:name).to_s.must_equal '<li class="string"><label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label></li>'
|
76
76
|
f.input(:release_date).to_s.must_equal '<li class="date"><label>Release date: <input id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></label></li>'
|
77
77
|
f.input(:created_at).to_s.must_equal '<li class="datetime"><label>Created at: <input id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></label></li>'
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should include required * in label if required" do
|
81
|
-
@b.input(:name, :required=>true).to_s.must_equal '<label>Name<abbr title="required">*</abbr>: <input id="album_name" name="album[name]" required="required" type="text" value="b"/></label>'
|
81
|
+
@b.input(:name, :required=>true).to_s.must_equal '<label>Name<abbr title="required">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label>'
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should add required to label even if :label option specified" do
|
85
|
-
@b.input(:name, :required=>true, :label=>'Foo').to_s.must_equal '<label>Foo<abbr title="required">*</abbr>: <input id="album_name" name="album[name]" required="required" type="text" value="b"/></label>'
|
85
|
+
@b.input(:name, :required=>true, :label=>'Foo').to_s.must_equal '<label>Foo<abbr title="required">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label>'
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should not add required to label even if :label option is nil" do
|
89
|
-
@b.input(:name, :required=>true, :label=>nil).to_s.must_equal '<input id="album_name" name="album[name]" required="required" type="text" value="b"/>'
|
89
|
+
@b.input(:name, :required=>true, :label=>nil).to_s.must_equal '<input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/>'
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should include required wrapper class if required" do
|
93
93
|
f = Forme::Form.new(@ab, :wrapper=>:li)
|
94
|
-
f.input(:name, :required=>true).to_s.must_equal '<li class="string required"><label>Name<abbr title="required">*</abbr>: <input id="album_name" name="album[name]" required="required" type="text" value="b"/></label></li>'
|
94
|
+
f.input(:name, :required=>true).to_s.must_equal '<li class="string required"><label>Name<abbr title="required">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label></li>'
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should use a select box for tri-valued boolean fields" do
|
@@ -333,7 +333,7 @@ describe "Forme Sequel::Model forms" do
|
|
333
333
|
|
334
334
|
it "should correctly show an error message if there is one" do
|
335
335
|
@ab.errors.add(:name, 'tis not valid')
|
336
|
-
@b.input(:name).to_s.must_equal '<label>Name: <input class="error" id="album_name" name="album[name]" type="text" value="b"/></label><span class="error_message">tis not valid</span>'
|
336
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input class="error" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label><span class="error_message">tis not valid</span>'
|
337
337
|
end
|
338
338
|
|
339
339
|
it "should correctly show an error message for many_to_one associations if there is one" do
|
@@ -367,90 +367,90 @@ describe "Forme Sequel::Model forms" do
|
|
367
367
|
|
368
368
|
it "should add required attribute if the column doesn't support nil values" do
|
369
369
|
def @ab.db_schema; h = super.dup; h[:name] = h[:name].merge(:allow_null=>false); h end
|
370
|
-
@b.input(:name).to_s.must_equal '<label>Name<abbr title="required">*</abbr>: <input id="album_name" name="album[name]" required="required" type="text" value="b"/></label>'
|
370
|
+
@b.input(:name).to_s.must_equal '<label>Name<abbr title="required">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label>'
|
371
371
|
end
|
372
372
|
|
373
373
|
it "should use allow nested forms with many_to_one associations" do
|
374
|
-
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
374
|
+
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
375
375
|
end
|
376
376
|
|
377
377
|
it "should have #subform respect an :inputs option" do
|
378
|
-
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
378
|
+
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
379
379
|
end
|
380
380
|
|
381
381
|
it "should have #subform respect an :obj option overriding the object to use" do
|
382
|
-
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="b"/></label></fieldset></form>'
|
382
|
+
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="b"/></label></fieldset></form>'
|
383
383
|
end
|
384
384
|
|
385
385
|
it "should have #subform respect a :legend option if :inputs is used" do
|
386
|
-
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
386
|
+
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
387
387
|
end
|
388
388
|
|
389
389
|
it "should have #subform respect a callable :legend option if :inputs is used" do
|
390
|
-
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
390
|
+
Forme.form(@ab){|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><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
391
391
|
end
|
392
392
|
|
393
393
|
it "should not add hidden primary key field for new many_to_one associated objects" do
|
394
394
|
@ab.associations[:artist] = Artist.new(:name=>'a')
|
395
|
-
Forme.form(@ab){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><label>Name: <input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
395
|
+
Forme.form(@ab){|f| f.subform(:artist){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></label></fieldset></form>'
|
396
396
|
end
|
397
397
|
|
398
398
|
it "should use allow nested forms with one_to_one associations" do
|
399
|
-
Forme.form(@ab){|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><label>Info: <input id="album_album_info_attributes_info" name="album[album_info_attributes][info]" type="text" value="a"/></label></fieldset></form>'
|
399
|
+
Forme.form(@ab){|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><label>Info: <input id="album_album_info_attributes_info" maxlength="255" name="album[album_info_attributes][info]" type="text" value="a"/></label></fieldset></form>'
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should use allow nested forms with one_to_many associations" do
|
403
|
-
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
403
|
+
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
404
404
|
end
|
405
405
|
|
406
406
|
it "should support :obj option for *_to_many associations" do
|
407
|
-
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="x"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="y"/></label></fieldset></form>'
|
407
|
+
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></label></fieldset></form>'
|
408
408
|
end
|
409
409
|
|
410
410
|
it "should auto number legends when using subform with inputs for *_to_many associations" do
|
411
|
-
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
411
|
+
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
412
412
|
end
|
413
413
|
|
414
414
|
it "should support callable :legend option when using subform with inputs for *_to_many associations" do
|
415
|
-
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
415
|
+
Forme.form(@ab){|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><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
416
416
|
end
|
417
417
|
|
418
418
|
it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
|
419
419
|
@ab.associations[:tracks] = [Track.new(:name=>'m'), Track.new(:name=>'n')]
|
420
|
-
Forme.form(@ab){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
420
|
+
Forme.form(@ab){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
|
421
421
|
end
|
422
422
|
|
423
423
|
it "should use allow nested forms with many_to_many associations" do
|
424
|
-
Forme.form(@ab){|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><label>Name: <input id="album_tags_attributes_0_name" name="album[tags_attributes][0][name]" type="text" value="s"/></label></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><label>Name: <input id="album_tags_attributes_1_name" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
|
424
|
+
Forme.form(@ab){|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><label>Name: <input id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></label></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><label>Name: <input id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
|
425
425
|
end
|
426
426
|
|
427
427
|
it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
|
428
428
|
@ab.associations[:tags] = [Tag.new(:name=>'s'), Tag.new(:name=>'t')]
|
429
|
-
Forme.form(@ab){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Tag #1</legend><label>Name: <input id="album_tags_attributes_0_name" name="album[tags_attributes][0][name]" type="text" value="s"/></label></fieldset><fieldset class="inputs"><legend>Tag #2</legend><label>Name: <input id="album_tags_attributes_1_name" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
|
429
|
+
Forme.form(@ab){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Tag #1</legend><label>Name: <input id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></label></fieldset><fieldset class="inputs"><legend>Tag #2</legend><label>Name: <input id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
|
430
430
|
end
|
431
431
|
|
432
432
|
it "should handle multiple nested levels" do
|
433
|
-
Forme.form(Artist[1]){|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><label>Name: <input id="artist_albums_attributes_0_name" name="artist[albums_attributes][0][name]" type="text" value="b"/></label><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><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_0_name" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_1_name" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></fieldset></form>'
|
433
|
+
Forme.form(Artist[1]){|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><label>Name: <input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></label><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><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></label></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><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></fieldset></form>'
|
434
434
|
end
|
435
435
|
|
436
436
|
it "should have #subform :grid option create a grid" do
|
437
|
-
Forme.form(@ab){|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 id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
437
|
+
Forme.form(@ab){|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 id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
438
438
|
end
|
439
439
|
|
440
440
|
it "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
|
441
|
-
Forme.form(@ab){|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 id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
441
|
+
Forme.form(@ab){|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 id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
442
442
|
end
|
443
443
|
|
444
444
|
it "should have #subform :grid option handle :legend and :labels options" do
|
445
|
-
Forme.form(@ab){|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 id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
445
|
+
Forme.form(@ab){|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 id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
446
446
|
end
|
447
447
|
|
448
448
|
it "should have #subform :grid option handle :legend and :labels nil values" do
|
449
|
-
Forme.form(@ab){|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 id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
449
|
+
Forme.form(@ab){|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 id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
450
450
|
end
|
451
451
|
|
452
452
|
it "should have #subform :grid option handle :skip_primary_key option" do
|
453
|
-
Forme.form(@ab){|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 id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
453
|
+
Forme.form(@ab){|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 id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
454
454
|
end
|
455
455
|
|
456
456
|
end
|
@@ -462,22 +462,22 @@ describe "Forme Sequel plugin default input types based on column names" do
|
|
462
462
|
end
|
463
463
|
|
464
464
|
it "should use password input with no value for string columns with name password" do
|
465
|
-
f(:password).to_s.must_equal '<label>Password: <input id="test_password" name="test[password]" type="password"/></label>'
|
465
|
+
f(:password).to_s.must_equal '<label>Password: <input id="test_password" maxlength="255" name="test[password]" type="password"/></label>'
|
466
466
|
end
|
467
467
|
|
468
468
|
it "should use email input for string columns with name email" do
|
469
|
-
f(:email).to_s.must_equal '<label>Email: <input id="test_email" name="test[email]" type="email" value="foo"/></label>'
|
469
|
+
f(:email).to_s.must_equal '<label>Email: <input id="test_email" maxlength="255" name="test[email]" type="email" value="foo"/></label>'
|
470
470
|
end
|
471
471
|
|
472
472
|
it "should use tel input for string columns with name phone or fax" do
|
473
|
-
f(:phone).to_s.must_equal '<label>Phone: <input id="test_phone" name="test[phone]" type="tel" value="foo"/></label>'
|
474
|
-
f(:fax).to_s.must_equal '<label>Fax: <input id="test_fax" name="test[fax]" type="tel" value="foo"/></label>'
|
473
|
+
f(:phone).to_s.must_equal '<label>Phone: <input id="test_phone" maxlength="255" name="test[phone]" type="tel" value="foo"/></label>'
|
474
|
+
f(:fax).to_s.must_equal '<label>Fax: <input id="test_fax" maxlength="255" name="test[fax]" type="tel" value="foo"/></label>'
|
475
475
|
end
|
476
476
|
|
477
477
|
it "should use url input for string columns with name url, uri, or website" do
|
478
|
-
f(:url).to_s.must_equal '<label>Url: <input id="test_url" name="test[url]" type="url" value="foo"/></label>'
|
479
|
-
f(:uri).to_s.must_equal '<label>Uri: <input id="test_uri" name="test[uri]" type="url" value="foo"/></label>'
|
480
|
-
f(:website).to_s.must_equal '<label>Website: <input id="test_website" name="test[website]" type="url" value="foo"/></label>'
|
478
|
+
f(:url).to_s.must_equal '<label>Url: <input id="test_url" maxlength="255" name="test[url]" type="url" value="foo"/></label>'
|
479
|
+
f(:uri).to_s.must_equal '<label>Uri: <input id="test_uri" maxlength="255" name="test[uri]" type="url" value="foo"/></label>'
|
480
|
+
f(:website).to_s.must_equal '<label>Website: <input id="test_website" maxlength="255" name="test[website]" type="url" value="foo"/></label>'
|
481
481
|
end
|
482
482
|
end
|
483
483
|
|
@@ -501,11 +501,11 @@ describe "Forme Sequel::Model validation parsing" do
|
|
501
501
|
end
|
502
502
|
|
503
503
|
it "should turn format into a pattern" do
|
504
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" pattern="[A-z]+" type="text"/></label>'
|
504
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" pattern="[A-z]+" type="text"/></label>'
|
505
505
|
end
|
506
506
|
|
507
507
|
it "should respect :title option for format" do
|
508
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" pattern="[A-z]+" title="Foo" type="text"/></label>'
|
508
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" pattern="[A-z]+" title="Foo" type="text"/></label>'
|
509
509
|
end
|
510
510
|
|
511
511
|
it "should use maxlength for length :maximum, :is, and :within" do
|
@@ -516,19 +516,19 @@ describe "Forme Sequel::Model validation parsing" do
|
|
516
516
|
end
|
517
517
|
|
518
518
|
it "should turn numericality into a pattern" do
|
519
|
-
f(:validates_numericality_of, :name).input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></label>'
|
519
|
+
f(:validates_numericality_of, :name).input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></label>'
|
520
520
|
end
|
521
521
|
|
522
522
|
it "should turn numericality :only_integer into a pattern" do
|
523
|
-
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></label>'
|
523
|
+
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></label>'
|
524
524
|
end
|
525
525
|
|
526
526
|
it "should respect :title option for numericality" do
|
527
|
-
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></label>'
|
527
|
+
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></label>'
|
528
528
|
end
|
529
529
|
|
530
530
|
it "should respect :placeholder option for any validation" do
|
531
|
-
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).to_s.must_equal '<label>Name: <input id="album_name" name="album[name]" placeholder="must be unique" type="text"/></label>'
|
531
|
+
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" placeholder="must be unique" type="text"/></label>'
|
532
532
|
end
|
533
533
|
|
534
534
|
end
|
@@ -552,7 +552,7 @@ describe "Forme Sequel::Model default namespacing" do
|
|
552
552
|
end
|
553
553
|
|
554
554
|
it "namespaces the input id and name" do
|
555
|
-
@b.input(:name).to_s.must_equal '<label>Name: <input id="foo/album_name" name="foo/album[name]" type="text" value="b"/></label>'
|
555
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input id="foo/album_name" maxlength="255" name="foo/album[name]" type="text" value="b"/></label>'
|
556
556
|
end
|
557
557
|
end
|
558
558
|
|
@@ -578,7 +578,6 @@ describe "Forme Sequel::Model custom namespacing" do
|
|
578
578
|
end
|
579
579
|
|
580
580
|
it "namespaces the form input and name" do
|
581
|
-
@b.input(:name).to_s.must_equal '<label>Name: <input id="bar_album_name" name="bar_album[name]" type="text" value="b"/></label>'
|
581
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input id="bar_album_name" maxlength="255" name="bar_album[name]" type="text" value="b"/></label>'
|
582
582
|
end
|
583
|
-
|
584
583
|
end
|
@@ -46,32 +46,74 @@ describe "Sequel forme_set plugin" do
|
|
46
46
|
@ab.name.must_be_nil
|
47
47
|
end
|
48
48
|
|
49
|
-
it "#forme_set should skip inputs with disabled/readonly formatter" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@ab.forme_set(:name=>'Foo')
|
56
|
-
@ab.name.must_be_nil
|
49
|
+
it "#forme_set should skip inputs with disabled/readonly formatter set on input" do
|
50
|
+
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
51
|
+
@f.input(:name, :formatter=>formatter)
|
52
|
+
@ab.forme_set(:name=>'Foo')
|
53
|
+
@ab.name.must_be_nil
|
54
|
+
end
|
57
55
|
|
58
56
|
@f.input(:name, :formatter=>:default)
|
59
57
|
@ab.forme_set(:name=>'Foo')
|
60
58
|
@ab.name.must_equal 'Foo'
|
61
59
|
end
|
62
60
|
|
63
|
-
it "#forme_set should skip inputs with disabled/readonly formatter" do
|
64
|
-
|
61
|
+
it "#forme_set should skip inputs with disabled/readonly formatter set on Form" do
|
62
|
+
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
63
|
+
@f = Forme::Form.new(@ab, :formatter=>:disabled)
|
64
|
+
@f.input(:name)
|
65
|
+
@ab.forme_set(:name=>'Foo')
|
66
|
+
@ab.name.must_be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
@f = Forme::Form.new(@ab, :formatter=>:default)
|
65
70
|
@f.input(:name)
|
66
71
|
@ab.forme_set(:name=>'Foo')
|
72
|
+
@ab.name.must_equal 'Foo'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "#forme_set should skip inputs with disabled/readonly formatter set using with_opts" do
|
76
|
+
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
77
|
+
@f.with_opts(:formatter=>formatter) do
|
78
|
+
@f.input(:name)
|
79
|
+
end
|
80
|
+
@ab.forme_set(:name=>'Foo')
|
81
|
+
@ab.name.must_be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
@f.with_opts(:formatter=>:default) do
|
85
|
+
@f.input(:name)
|
86
|
+
end
|
87
|
+
@ab.forme_set(:name=>'Foo')
|
88
|
+
@ab.name.must_equal 'Foo'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "#forme_set should prefer input formatter to with_opts formatter" do
|
92
|
+
@f.with_opts(:formatter=>:default) do
|
93
|
+
@f.input(:name, :formatter=>:readonly)
|
94
|
+
end
|
95
|
+
@ab.forme_set(:name=>'Foo')
|
67
96
|
@ab.name.must_be_nil
|
68
97
|
|
69
|
-
@f
|
70
|
-
|
98
|
+
@f.with_opts(:formatter=>:readonly) do
|
99
|
+
@f.input(:name, :formatter=>:default)
|
100
|
+
end
|
101
|
+
@ab.forme_set(:name=>'Foo')
|
102
|
+
@ab.name.must_equal 'Foo'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "#forme_set should prefer with_opts formatter to form formatter" do
|
106
|
+
@f = Forme::Form.new(@ab, :formatter=>:default)
|
107
|
+
@f.with_opts(:formatter=>:readonly) do
|
108
|
+
@f.input(:name)
|
109
|
+
end
|
71
110
|
@ab.forme_set(:name=>'Foo')
|
72
111
|
@ab.name.must_be_nil
|
73
112
|
|
74
|
-
@f.
|
113
|
+
@f = Forme::Form.new(@ab, :formatter=>:readonly)
|
114
|
+
@f.with_opts(:formatter=>:default) do
|
115
|
+
@f.input(:name)
|
116
|
+
end
|
75
117
|
@ab.forme_set(:name=>'Foo')
|
76
118
|
@ab.name.must_equal 'Foo'
|
77
119
|
end
|