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