forme 1.8.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +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
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
2
2
|
|
3
3
|
begin
|
4
|
+
raise LoadError if defined?(JRUBY_VERSION) && /\A9\.2\./.match(JRUBY_VERSION)
|
4
5
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'sequel_i18n_helper.rb')
|
5
6
|
rescue LoadError
|
6
7
|
warn "unable to load i18n, skipping i18n Sequel plugin spec"
|
@@ -12,19 +13,19 @@ describe "Forme Sequel::Model forms" do
|
|
12
13
|
end
|
13
14
|
|
14
15
|
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>'
|
16
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input id="invoice_name" maxlength="255" name="invoice[name]" type="text" value="b"/></label>'
|
16
17
|
end
|
17
18
|
|
18
19
|
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>'
|
20
|
+
@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
21
|
end
|
21
22
|
|
22
23
|
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
|
24
|
+
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
25
|
end
|
25
26
|
|
26
27
|
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
|
28
|
+
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
29
|
end
|
29
30
|
end
|
30
31
|
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
|
@@ -134,7 +134,7 @@ describe "Forme Sequel::Model forms" do
|
|
134
134
|
|
135
135
|
it "should handle errors on radio buttons for boolean fields if :as=>:radio is used" do
|
136
136
|
@ab.errors.add(:platinum, 'foo')
|
137
|
-
@b.input(:platinum, :as=>:radio).to_s.must_equal '<span class="label">Platinum</span><label class="option"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label><label class="option"><input checked="checked" class="error" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label><span class="error_message">foo</span>'
|
137
|
+
@b.input(:platinum, :as=>:radio).to_s.must_equal '<span class="label">Platinum</span><label class="option"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label><label class="option"><input aria-describedby="album_platinum_no_error_message" aria-invalid="true" checked="checked" class="error" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label><span class="error_message" id="album_platinum_no_error_message">foo</span>'
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should handle Raw :label options if :as=>:radio is used" do
|
@@ -272,8 +272,8 @@ describe "Forme Sequel::Model forms" do
|
|
272
272
|
|
273
273
|
it "should handle an error message on the underlying column for pg_array_to_many associations" do
|
274
274
|
@ab.errors.add(:atag_ids, 'tis not valid')
|
275
|
-
@b.input(:atags).to_s.must_equal '<label>Atags: <select class="error" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></label><span class="error_message">tis not valid</span>'
|
276
|
-
@b.input(:atags, :as=>:checkbox).to_s.must_equal '<span class="label">Atags</span><label class="option"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label><label class="option"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label><label class="option"><input class="error" id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label><span class="error_message">tis not valid</span>'
|
275
|
+
@b.input(:atags).to_s.must_equal '<label>Atags: <select aria-describedby="album_atag_ids_error_message" aria-invalid="true" class="error" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></label><span class="error_message" id="album_atag_ids_error_message">tis not valid</span>'
|
276
|
+
@b.input(:atags, :as=>:checkbox).to_s.must_equal '<span class="label">Atags</span><label class="option"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label><label class="option"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label><label class="option"><input aria-describedby="album_atag_ids_3_error_message" aria-invalid="true" class="error" id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label><span class="error_message" id="album_atag_ids_3_error_message">tis not valid</span>'
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should use a regular select box for *_to_many associations if multiple if false" do
|
@@ -318,7 +318,7 @@ describe "Forme Sequel::Model forms" do
|
|
318
318
|
|
319
319
|
it "should handle errors on methods not backed by columns" do
|
320
320
|
@ab.errors.add(:artist_name, 'foo')
|
321
|
-
@b.input(:artist_name).to_s.must_equal '<label>Artist name: <input class="error" id="album_artist_name" name="album[artist_name]" type="text" value="a"/></label><span class="error_message">foo</span>'
|
321
|
+
@b.input(:artist_name).to_s.must_equal '<label>Artist name: <input aria-describedby="album_artist_name_error_message" aria-invalid="true" class="error" id="album_artist_name" name="album[artist_name]" type="text" value="a"/></label><span class="error_message" id="album_artist_name_error_message">foo</span>'
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should respect a :type option with a schema type as the input type for methods not backed by columns" do
|
@@ -331,14 +331,19 @@ describe "Forme Sequel::Model forms" do
|
|
331
331
|
@b.input(:foo, :type=>:phone).to_s.must_equal '<label>Foo: <input id="album_foo" name="album[foo]" type="phone" value="bar"/></label>'
|
332
332
|
end
|
333
333
|
|
334
|
+
it "should not override an explicit :error setting" do
|
335
|
+
@ab.errors.add(:name, 'tis not valid')
|
336
|
+
@b.input(:name, :error=>nil).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label>'
|
337
|
+
end
|
338
|
+
|
334
339
|
it "should correctly show an error message if there is one" do
|
335
340
|
@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>'
|
341
|
+
@b.input(:name).to_s.must_equal '<label>Name: <input aria-describedby="album_name_error_message" aria-invalid="true" class="error" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label><span class="error_message" id="album_name_error_message">tis not valid</span>'
|
337
342
|
end
|
338
343
|
|
339
344
|
it "should correctly show an error message for many_to_one associations if there is one" do
|
340
345
|
@ab.errors.add(:artist_id, 'tis not valid')
|
341
|
-
@b.input(:artist).to_s.must_equal '<label>Artist: <select class="error" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></label><span class="error_message">tis not valid</span>'
|
346
|
+
@b.input(:artist).to_s.must_equal '<label>Artist: <select aria-describedby="album_artist_id_error_message" aria-invalid="true" class="error" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></label><span class="error_message" id="album_artist_id_error_message">tis not valid</span>'
|
342
347
|
end
|
343
348
|
|
344
349
|
it "should raise an error for unhandled associations" do
|
@@ -367,92 +372,95 @@ describe "Forme Sequel::Model forms" do
|
|
367
372
|
|
368
373
|
it "should add required attribute if the column doesn't support nil values" do
|
369
374
|
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>'
|
375
|
+
@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
376
|
end
|
372
377
|
|
373
378
|
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>'
|
379
|
+
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
380
|
end
|
376
381
|
|
377
382
|
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>'
|
383
|
+
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
384
|
end
|
380
385
|
|
381
386
|
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>'
|
387
|
+
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
388
|
end
|
384
389
|
|
385
390
|
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>'
|
391
|
+
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
392
|
end
|
388
393
|
|
389
394
|
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>'
|
395
|
+
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
396
|
end
|
392
397
|
|
393
398
|
it "should not add hidden primary key field for new many_to_one associated objects" do
|
394
399
|
@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>'
|
400
|
+
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
401
|
end
|
397
402
|
|
398
403
|
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>'
|
404
|
+
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
405
|
end
|
401
406
|
|
402
407
|
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>'
|
408
|
+
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
409
|
end
|
405
410
|
|
406
411
|
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>'
|
412
|
+
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
413
|
end
|
409
414
|
|
410
415
|
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>'
|
416
|
+
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
417
|
end
|
413
418
|
|
414
419
|
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>'
|
420
|
+
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
421
|
end
|
417
422
|
|
418
423
|
it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
|
419
424
|
@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>'
|
425
|
+
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
426
|
end
|
422
427
|
|
423
428
|
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>'
|
429
|
+
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
430
|
end
|
426
431
|
|
427
432
|
it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
|
428
433
|
@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>'
|
434
|
+
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
435
|
end
|
431
436
|
|
432
437
|
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>'
|
438
|
+
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
439
|
end
|
435
440
|
|
436
441
|
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>'
|
442
|
+
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
443
|
end
|
439
444
|
|
440
445
|
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>'
|
446
|
+
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
447
|
end
|
443
448
|
|
444
449
|
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>'
|
450
|
+
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
451
|
end
|
447
452
|
|
448
453
|
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>'
|
454
|
+
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
455
|
end
|
451
456
|
|
452
457
|
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>'
|
458
|
+
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
459
|
end
|
455
460
|
|
461
|
+
it "should handle non-Sequel forms with Sequel inputs" do
|
462
|
+
Forme.form{|f| f.input(:name, :obj=>@ab).to_s.must_equal '<label>Name: <input id="name" maxlength="255" name="name" type="text" value="b"/></label>'}
|
463
|
+
end
|
456
464
|
end
|
457
465
|
|
458
466
|
describe "Forme Sequel plugin default input types based on column names" do
|
@@ -462,22 +470,22 @@ describe "Forme Sequel plugin default input types based on column names" do
|
|
462
470
|
end
|
463
471
|
|
464
472
|
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>'
|
473
|
+
f(:password).to_s.must_equal '<label>Password: <input id="test_password" maxlength="255" name="test[password]" type="password"/></label>'
|
466
474
|
end
|
467
475
|
|
468
476
|
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>'
|
477
|
+
f(:email).to_s.must_equal '<label>Email: <input id="test_email" maxlength="255" name="test[email]" type="email" value="foo"/></label>'
|
470
478
|
end
|
471
479
|
|
472
480
|
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>'
|
481
|
+
f(:phone).to_s.must_equal '<label>Phone: <input id="test_phone" maxlength="255" name="test[phone]" type="tel" value="foo"/></label>'
|
482
|
+
f(:fax).to_s.must_equal '<label>Fax: <input id="test_fax" maxlength="255" name="test[fax]" type="tel" value="foo"/></label>'
|
475
483
|
end
|
476
484
|
|
477
485
|
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>'
|
486
|
+
f(:url).to_s.must_equal '<label>Url: <input id="test_url" maxlength="255" name="test[url]" type="url" value="foo"/></label>'
|
487
|
+
f(:uri).to_s.must_equal '<label>Uri: <input id="test_uri" maxlength="255" name="test[uri]" type="url" value="foo"/></label>'
|
488
|
+
f(:website).to_s.must_equal '<label>Website: <input id="test_website" maxlength="255" name="test[website]" type="url" value="foo"/></label>'
|
481
489
|
end
|
482
490
|
end
|
483
491
|
|
@@ -501,11 +509,11 @@ describe "Forme Sequel::Model validation parsing" do
|
|
501
509
|
end
|
502
510
|
|
503
511
|
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>'
|
512
|
+
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
513
|
end
|
506
514
|
|
507
515
|
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>'
|
516
|
+
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
517
|
end
|
510
518
|
|
511
519
|
it "should use maxlength for length :maximum, :is, and :within" do
|
@@ -516,19 +524,19 @@ describe "Forme Sequel::Model validation parsing" do
|
|
516
524
|
end
|
517
525
|
|
518
526
|
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>'
|
527
|
+
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
528
|
end
|
521
529
|
|
522
530
|
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>'
|
531
|
+
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
532
|
end
|
525
533
|
|
526
534
|
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>'
|
535
|
+
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
536
|
end
|
529
537
|
|
530
538
|
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>'
|
539
|
+
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
540
|
end
|
533
541
|
|
534
542
|
end
|
@@ -552,7 +560,7 @@ describe "Forme Sequel::Model default namespacing" do
|
|
552
560
|
end
|
553
561
|
|
554
562
|
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>'
|
563
|
+
@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
564
|
end
|
557
565
|
end
|
558
566
|
|
@@ -578,7 +586,6 @@ describe "Forme Sequel::Model custom namespacing" do
|
|
578
586
|
end
|
579
587
|
|
580
588
|
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>'
|
589
|
+
@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
590
|
end
|
583
|
-
|
584
591
|
end
|
@@ -26,7 +26,7 @@ describe "Sequel forme_set plugin" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "#forme_set should handle different ways to specify parameter names" do
|
29
|
-
[{:attr=>{:name=>'foo'}}, {:attr=>{'name'=>:foo}}, {:name=>'foo'}, {:name=>'bar[foo]'}, {:key=>:foo}].each do |opts|
|
29
|
+
[{:attr=>{:name=>'foo'}}, {:attr=>{'name'=>:foo}}, {:name=>'foo'}, {:name=>'foo[]'}, {:name=>'bar[foo][]'}, {:name=>'bar[foo]'}, {:key=>:foo}].each do |opts|
|
30
30
|
@f.input(:name, opts)
|
31
31
|
|
32
32
|
@ab.forme_set(:name=>'Foo')
|
@@ -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
|
@@ -180,4 +222,11 @@ describe "Sequel forme_set plugin" do
|
|
180
222
|
@ab.forme_validations[:name] = [:bar, []]
|
181
223
|
proc{@ab.valid?}.must_raise Sequel::Plugins::Forme::Error
|
182
224
|
end
|
225
|
+
|
226
|
+
it "should handle frozen instances as form inputs" do
|
227
|
+
@ab.freeze
|
228
|
+
@ab.forme_inputs.must_equal({})
|
229
|
+
@ab.forme_validations.must_equal({})
|
230
|
+
@f.input(:name).must_be_kind_of(Forme::Input)
|
231
|
+
end
|
183
232
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'li
|
|
2
2
|
|
3
3
|
if ENV['WARNING']
|
4
4
|
require 'warning'
|
5
|
-
Warning.ignore([:missing_ivar, :not_reached])
|
5
|
+
Warning.ignore([:missing_ivar, :not_reached, :method_redefined])
|
6
6
|
end
|
7
7
|
|
8
8
|
if ENV['COVERAGE']
|
@@ -15,4 +15,4 @@ require 'forme'
|
|
15
15
|
require 'rubygems'
|
16
16
|
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
17
17
|
gem 'minitest'
|
18
|
-
require 'minitest/autorun'
|
18
|
+
require 'minitest/global_expectations/autorun'
|