forme 1.3.0 → 1.4.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 +16 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -1
- data/Rakefile +10 -39
- data/lib/forme.rb +8 -4
- data/lib/forme/bs3.rb +387 -0
- data/lib/forme/erb.rb +4 -2
- data/lib/forme/form.rb +2 -0
- data/lib/forme/input.rb +2 -0
- data/lib/forme/rails.rb +2 -0
- data/lib/forme/raw.rb +2 -0
- data/lib/forme/sinatra.rb +2 -0
- data/lib/forme/tag.rb +2 -0
- data/lib/forme/transformers/error_handler.rb +2 -0
- data/lib/forme/transformers/formatter.rb +37 -13
- data/lib/forme/transformers/helper.rb +3 -1
- data/lib/forme/transformers/inputs_wrapper.rb +2 -0
- data/lib/forme/transformers/labeler.rb +2 -0
- data/lib/forme/transformers/serializer.rb +2 -0
- data/lib/forme/transformers/wrapper.rb +3 -1
- data/lib/forme/version.rb +3 -1
- data/lib/roda/plugins/forme.rb +2 -0
- data/lib/sequel/plugins/forme.rb +6 -2
- data/spec/bs3_reference_spec.rb +358 -0
- data/spec/bs3_sequel_plugin_spec.rb +523 -0
- data/spec/bs3_spec.rb +690 -0
- data/spec/erb_helper.rb +27 -25
- data/spec/forme_spec.rb +542 -526
- data/spec/rails_integration_spec.rb +26 -26
- data/spec/roda_integration_spec.rb +14 -5
- data/spec/sequel_plugin_spec.rb +247 -233
- data/spec/sinatra_integration_spec.rb +12 -3
- data/spec/spec_helper.rb +1 -14
- metadata +120 -4
data/spec/erb_helper.rb
CHANGED
@@ -128,58 +128,60 @@ END
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
module FormeErbSpecs
|
132
|
+
extend Minitest::Spec::DSL
|
133
|
+
|
132
134
|
before do
|
133
135
|
o = Object.new
|
134
136
|
def o.puts(*) end
|
135
137
|
@rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o, 'SCRIPT_NAME'=>''}
|
136
138
|
end
|
137
139
|
|
138
|
-
|
139
|
-
sin_get('/').
|
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>'
|
140
142
|
end
|
141
143
|
|
142
|
-
|
143
|
-
sin_get('/inputs_block').
|
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>'
|
144
146
|
end
|
145
147
|
|
146
|
-
|
147
|
-
sin_get('/inputs_block_wrapper').
|
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>'
|
148
150
|
end
|
149
151
|
|
150
|
-
|
151
|
-
sin_get('/nest').
|
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>'
|
152
154
|
end
|
153
155
|
|
154
|
-
|
155
|
-
sin_get('/nest_sep').
|
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"
|
156
158
|
end
|
157
159
|
|
158
|
-
|
159
|
-
sin_get('/nest_seq').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").
|
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\" 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"
|
160
162
|
end
|
161
163
|
|
162
|
-
|
163
|
-
sin_get('/hash').
|
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>'
|
164
166
|
end
|
165
167
|
|
166
|
-
|
167
|
-
sin_get('/legend').
|
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>'
|
168
170
|
end
|
169
171
|
|
170
|
-
|
171
|
-
sin_get('/combined').
|
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>'
|
172
174
|
end
|
173
175
|
|
174
|
-
|
175
|
-
sin_get('/noblock').
|
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>'
|
176
178
|
end
|
177
179
|
|
178
|
-
|
179
|
-
sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").
|
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>'
|
180
182
|
end
|
181
183
|
|
182
|
-
|
183
|
-
sin_get('/noblock_empty').
|
184
|
+
it "#form with an empty form should work" do
|
185
|
+
sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
|
184
186
|
end
|
185
187
|
end
|
data/spec/forme_spec.rb
CHANGED
@@ -9,151 +9,163 @@ describe "Forme plain forms" do
|
|
9
9
|
@f = Forme::Form.new
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
Forme.version.
|
12
|
+
it "Forme.version should return version string" do
|
13
|
+
Forme.version.must_match /\A\d+\.\d+\.\d+\z/
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
@f.input(:text).to_s.
|
18
|
-
@f.input(:radio).to_s.
|
19
|
-
@f.input(:password).to_s.
|
20
|
-
@f.input(:checkbox).to_s.
|
21
|
-
@f.input(:submit).to_s.
|
16
|
+
it "should create a simple input tags" do
|
17
|
+
@f.input(:text).to_s.must_equal '<input type="text"/>'
|
18
|
+
@f.input(:radio).to_s.must_equal '<input type="radio"/>'
|
19
|
+
@f.input(:password).to_s.must_equal '<input type="password"/>'
|
20
|
+
@f.input(:checkbox).to_s.must_equal '<input type="checkbox"/>'
|
21
|
+
@f.input(:submit).to_s.must_equal '<input type="submit"/>'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
@f.input(:text, :
|
24
|
+
it "should use :html option if given" do
|
25
|
+
@f.input(:text, :html=>"<a>foo</a>").to_s.must_equal '<a>foo</a>'
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
@f.input(:text, :
|
28
|
+
it "should support a callable :html option" do
|
29
|
+
@f.input(:text, :html=>proc{|i| "<a>#{i.type}</a>"}).to_s.must_equal '<a>text</a>'
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
@f.input(:text, :
|
32
|
+
it "should still use labeler, wrapper, error_handler, and helper if :html option is given" do
|
33
|
+
@f.input(:text, :html=>"<a>foo</a>", :label=>'a', :error=>'b', :help=>'c', :wrapper=>:div).to_s.must_equal '<div><label>a: <a>foo</a></label><span class="error_message">b</span><span class="helper">c</span></div>'
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
@f.input(:text, :
|
36
|
+
it "should use :name option as attribute" do
|
37
|
+
@f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" type="text"/>'
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
@f.input(:text, :
|
40
|
+
it "should use :id option as attribute" do
|
41
|
+
@f.input(:text, :id=>"foo").to_s.must_equal '<input id="foo" type="text"/>'
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
@f.input(:text, :
|
44
|
+
it "should use :class option as attribute" do
|
45
|
+
@f.input(:text, :class=>"foo").to_s.must_equal '<input class="foo" type="text"/>'
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
@f.input(:text, :
|
48
|
+
it "should use :value option as attribute" do
|
49
|
+
@f.input(:text, :value=>"foo").to_s.must_equal '<input type="text" value="foo"/>'
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
@f.input(:text, :
|
52
|
+
it "should use :placeholder option as attribute" do
|
53
|
+
@f.input(:text, :placeholder=>"foo").to_s.must_equal '<input placeholder="foo" type="text"/>'
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
@f.input(:text, :
|
56
|
+
it "should use :style option as attribute" do
|
57
|
+
@f.input(:text, :style=>"foo").to_s.must_equal '<input style="foo" type="text"/>'
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
it "should use :key option as name and id attributes" do
|
61
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text"/>'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should use :key_id option as suffix for :key option id attributes" do
|
65
|
+
@f.input(:text, :key=>"foo", :key_id=>'bar').to_s.must_equal '<input id="foo_bar" name="foo" type="text"/>'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have :key option respect :multiple option" do
|
69
|
+
@f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="foo" name="foo[]" type="text"/>'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should use :key option respect form's current namespace" do
|
61
73
|
@f.with_opts(:namespace=>['bar']) do
|
62
|
-
@f.input(:text, :key=>"foo").to_s.
|
63
|
-
@f.input(:text, :key=>"foo", :multiple=>true).to_s.
|
74
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
|
75
|
+
@f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="bar_foo" name="bar[foo][]" type="text"/>'
|
64
76
|
@f.with_opts(:namespace=>['bar', 'baz']) do
|
65
|
-
@f.input(:text, :key=>"foo").to_s.
|
77
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_baz_foo" name="bar[baz][foo]" type="text"/>'
|
66
78
|
end
|
67
79
|
end
|
68
80
|
end
|
69
81
|
|
70
|
-
|
82
|
+
it "should consider form's :values hash for default values based on the :key option if :value is not present" do
|
71
83
|
@f.opts[:values] = {'foo'=>'baz'}
|
72
|
-
@f.input(:text, :key=>"foo").to_s.
|
73
|
-
@f.input(:text, :key=>"foo", :value=>'x').to_s.
|
84
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
|
85
|
+
@f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="foo" name="foo" type="text" value="x"/>'
|
74
86
|
|
75
|
-
@f.input(:text, :key=>:foo).to_s.
|
87
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
|
76
88
|
@f.opts[:values] = {:foo=>'baz'}
|
77
|
-
@f.input(:text, :key=>:foo).to_s.
|
89
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
|
78
90
|
end
|
79
91
|
|
80
|
-
|
92
|
+
it "should consider form's :values hash for default values based on the :key option when using namespaces" do
|
81
93
|
@f.opts[:values] = {'bar'=>{'foo'=>'baz'}}
|
82
94
|
@f.with_opts(:namespace=>['bar']) do
|
83
|
-
@f.input(:text, :key=>"foo").to_s.
|
84
|
-
@f.input(:text, :key=>"foo", :value=>'x').to_s.
|
85
|
-
@f.input(:text, :key=>:foo).to_s.
|
95
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
|
96
|
+
@f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="x"/>'
|
97
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
|
86
98
|
end
|
87
99
|
|
88
100
|
@f.with_opts(:namespace=>[:bar]) do
|
89
|
-
@f.input(:text, :key=>:foo).to_s.
|
101
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
|
90
102
|
|
91
103
|
@f.opts[:values] = {:bar=>{:foo=>'baz'}}
|
92
|
-
@f.input(:text, :key=>:foo).to_s.
|
104
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
|
93
105
|
@f.opts[:values] = {:bar=>{}}
|
94
|
-
@f.input(:text, :key=>:foo).to_s.
|
106
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
|
95
107
|
@f.opts[:values] = {}
|
96
|
-
@f.input(:text, :key=>:foo).to_s.
|
108
|
+
@f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
|
97
109
|
|
98
110
|
@f.opts[:values] = {'bar'=>{'quux'=>{'foo'=>'baz'}}}
|
99
111
|
@f.with_opts(:namespace=>['bar', 'quux']) do
|
100
|
-
@f.input(:text, :key=>"foo").to_s.
|
112
|
+
@f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/>'
|
101
113
|
end
|
102
114
|
end
|
103
115
|
end
|
104
116
|
|
105
|
-
|
117
|
+
it "should support a with_obj method that changes the object and namespace for the given block" do
|
106
118
|
@f.with_obj([:a, :c], 'bar') do
|
107
|
-
@f.input(:first).to_s.
|
119
|
+
@f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="a"/>'
|
108
120
|
@f.with_obj([:b], 'baz') do
|
109
|
-
@f.input(:first).to_s.
|
121
|
+
@f.input(:first).to_s.must_equal '<input id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/>'
|
110
122
|
end
|
111
123
|
@f.with_obj([:b], %w'baz quux') do
|
112
|
-
@f.input(:first).to_s.
|
124
|
+
@f.input(:first).to_s.must_equal '<input id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/>'
|
113
125
|
end
|
114
126
|
@f.with_obj([:b]) do
|
115
|
-
@f.input(:first).to_s.
|
127
|
+
@f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="b"/>'
|
116
128
|
end
|
117
|
-
@f.input(:last).to_s.
|
129
|
+
@f.input(:last).to_s.must_equal '<input id="bar_last" name="bar[last]" type="text" value="c"/>'
|
118
130
|
end
|
119
131
|
end
|
120
132
|
|
121
|
-
|
133
|
+
it "should support a each_obj method that changes the object and namespace for multiple objects for the given block" do
|
122
134
|
@f.tag(:form) do
|
123
135
|
@f.each_obj([[:a, :c], [:b, :d]], 'bar') do
|
124
136
|
@f.input(:first)
|
125
137
|
@f.input(:last)
|
126
138
|
end
|
127
|
-
end.to_s.
|
139
|
+
end.to_s.must_equal '<form><input id="bar_0_first" name="bar[0][first]" type="text" value="a"/><input id="bar_0_last" name="bar[0][last]" type="text" value="c"/><input id="bar_1_first" name="bar[1][first]" type="text" value="b"/><input id="bar_1_last" name="bar[1][last]" type="text" value="d"/></form>'
|
128
140
|
|
129
141
|
@f.tag(:form) do
|
130
142
|
@f.each_obj([[:a, :c], [:b, :d]], %w'bar baz') do
|
131
143
|
@f.input(:first)
|
132
144
|
@f.input(:last)
|
133
145
|
end
|
134
|
-
end.to_s.
|
146
|
+
end.to_s.must_equal '<form><input id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/><input id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/><input id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/><input id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></form>'
|
135
147
|
|
136
148
|
@f.tag(:form) do
|
137
149
|
@f.each_obj([[:a, :c], [:b, :d]]) do
|
138
150
|
@f.input(:first)
|
139
151
|
@f.input(:last)
|
140
152
|
end
|
141
|
-
end.to_s.
|
153
|
+
end.to_s.must_equal '<form><input id="0_first" name="0[first]" type="text" value="a"/><input id="0_last" name="0[last]" type="text" value="c"/><input id="1_first" name="1[first]" type="text" value="b"/><input id="1_last" name="1[last]" type="text" value="d"/></form>'
|
142
154
|
end
|
143
155
|
|
144
|
-
|
145
|
-
@f.input(:text).to_s.
|
146
|
-
@f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.
|
147
|
-
@f.with_opts(:wrapper=>:div){@f.input(:text).to_s.
|
156
|
+
it "should allow overriding form inputs on a per-block basis" do
|
157
|
+
@f.input(:text).to_s.must_equal '<input type="text"/>'
|
158
|
+
@f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.must_equal '<div><input type="text"/></div>'
|
159
|
+
@f.with_opts(:wrapper=>:div){@f.input(:text).to_s.must_equal '<div><input type="text"/></div>'}
|
148
160
|
@f.with_opts(:wrapper=>:div) do
|
149
|
-
@f.input(:text).to_s.
|
150
|
-
@f.with_opts(:wrapper=>:li){@f.input(:text).to_s.
|
151
|
-
@f.input(:text).to_s.
|
161
|
+
@f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
|
162
|
+
@f.with_opts(:wrapper=>:li){@f.input(:text).to_s.must_equal '<li><input type="text"/></li>'}
|
163
|
+
@f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
|
152
164
|
end
|
153
|
-
@f.input(:text).to_s.
|
165
|
+
@f.input(:text).to_s.must_equal '<input type="text"/>'
|
154
166
|
end
|
155
167
|
|
156
|
-
|
168
|
+
it "should handle delayed formatting when overriding form inputs on a per-block basis" do
|
157
169
|
@f.form do
|
158
170
|
@f.input(:text)
|
159
171
|
@f.with_opts(:wrapper=>:div) do
|
@@ -162,534 +174,534 @@ describe "Forme plain forms" do
|
|
162
174
|
@f.input(:text)
|
163
175
|
end
|
164
176
|
@f.input(:text)
|
165
|
-
end.to_s.
|
177
|
+
end.to_s.must_equal '<form><input type="text"/><div><input type="text"/></div><li><input type="text"/></li><div><input type="text"/></div><input type="text"/></form>'
|
166
178
|
end
|
167
179
|
|
168
|
-
|
180
|
+
it "should support :obj method to with_opts for changing the obj inside the block" do
|
169
181
|
@f.form do
|
170
182
|
@f.with_opts(:obj=>[:a, :c]) do
|
171
183
|
@f.input(:first)
|
172
184
|
@f.with_opts(:obj=>[:b]){@f.input(:first)}
|
173
185
|
@f.input(:last)
|
174
186
|
end
|
175
|
-
end.to_s.
|
187
|
+
end.to_s.must_equal '<form><input id="first" name="first" type="text" value="a"/><input id="first" name="first" type="text" value="b"/><input id="last" name="last" type="text" value="c"/></form>'
|
176
188
|
end
|
177
189
|
|
178
|
-
|
179
|
-
@f.input(:text, :attr=>{:bar=>"foo"}).to_s.
|
190
|
+
it "should allow arbitrary attributes using the :attr option" do
|
191
|
+
@f.input(:text, :attr=>{:bar=>"foo"}).to_s.must_equal '<input bar="foo" type="text"/>'
|
180
192
|
end
|
181
193
|
|
182
|
-
|
183
|
-
@f.input(:text, :data=>{:bar=>"foo"}).to_s.
|
194
|
+
it "should convert the :data option into attributes" do
|
195
|
+
@f.input(:text, :data=>{:bar=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
|
184
196
|
end
|
185
197
|
|
186
|
-
|
187
|
-
@f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.
|
198
|
+
it "should not have standard options override the :attr option" do
|
199
|
+
@f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.must_equal '<input name="foo" type="text"/>'
|
188
200
|
end
|
189
201
|
|
190
|
-
|
191
|
-
@f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.
|
202
|
+
it "should combine :class standard option with :attr option" do
|
203
|
+
@f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.must_equal '<input class="foo bar" type="text"/>'
|
192
204
|
end
|
193
205
|
|
194
|
-
|
195
|
-
@f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.
|
206
|
+
it "should not have :data options override the :attr option" do
|
207
|
+
@f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
|
196
208
|
end
|
197
209
|
|
198
|
-
|
199
|
-
@f.input(:text, :size=>5, :maxlength=>10).to_s.
|
200
|
-
@f.input(:textarea, :size=>5, :maxlength=>10).to_s.
|
210
|
+
it "should use :size and :maxlength options as attributes for text inputs" do
|
211
|
+
@f.input(:text, :size=>5, :maxlength=>10).to_s.must_equal '<input maxlength="10" size="5" type="text"/>'
|
212
|
+
@f.input(:textarea, :size=>5, :maxlength=>10).to_s.must_equal '<textarea></textarea>'
|
201
213
|
end
|
202
214
|
|
203
|
-
|
204
|
-
@f.input(:checkbox, :name=>"foo").to_s.
|
215
|
+
it "should create hidden input with value 0 for each checkbox with a name" do
|
216
|
+
@f.input(:checkbox, :name=>"foo").to_s.must_equal '<input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/>'
|
205
217
|
end
|
206
218
|
|
207
|
-
|
208
|
-
@f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.
|
219
|
+
it "should not create hidden input with value 0 for each checkbox with a name if :no_hidden option is used" do
|
220
|
+
@f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.must_equal '<input name="foo" type="checkbox"/>'
|
209
221
|
end
|
210
222
|
|
211
|
-
|
212
|
-
@f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.
|
223
|
+
it "should create hidden input with _hidden appened to id for each checkbox with a name and id" do
|
224
|
+
@f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.must_equal '<input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/>'
|
213
225
|
end
|
214
226
|
|
215
|
-
|
216
|
-
@f.input(:checkbox, :name=>"foo", :value=>"t").to_s.
|
227
|
+
it "should create hidden input with value f for each checkbox with a name and value t" do
|
228
|
+
@f.input(:checkbox, :name=>"foo", :value=>"t").to_s.must_equal '<input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/>'
|
217
229
|
end
|
218
230
|
|
219
|
-
|
220
|
-
@f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.
|
231
|
+
it "should use :hidden_value option for value of hidden input for checkbox" do
|
232
|
+
@f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
|
221
233
|
end
|
222
234
|
|
223
|
-
|
224
|
-
@f.input(:checkbox, :checked=>true).to_s.
|
225
|
-
@f.input(:checkbox, :checked=>false).to_s.
|
235
|
+
it "should handle :checked option" do
|
236
|
+
@f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
|
237
|
+
@f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
|
226
238
|
end
|
227
239
|
|
228
|
-
|
229
|
-
@f.input(:textarea).to_s.
|
230
|
-
@f.input(:textarea, :value=>'a').to_s.
|
240
|
+
it "should create textarea tag" do
|
241
|
+
@f.input(:textarea).to_s.must_equal '<textarea></textarea>'
|
242
|
+
@f.input(:textarea, :value=>'a').to_s.must_equal '<textarea>a</textarea>'
|
231
243
|
end
|
232
244
|
|
233
|
-
|
234
|
-
@f.input(:text, :cols=>5, :rows=>10).to_s.
|
235
|
-
@f.input(:textarea, :cols=>5, :rows=>10).to_s.
|
245
|
+
it "should use :cols and :rows options as attributes for textarea inputs" do
|
246
|
+
@f.input(:text, :cols=>5, :rows=>10).to_s.must_equal '<input type="text"/>'
|
247
|
+
@f.input(:textarea, :cols=>5, :rows=>10).to_s.must_equal '<textarea cols="5" rows="10"></textarea>'
|
236
248
|
end
|
237
249
|
|
238
|
-
|
239
|
-
@f.input(:select).to_s.
|
250
|
+
it "should create select tag" do
|
251
|
+
@f.input(:select).to_s.must_equal '<select></select>'
|
240
252
|
end
|
241
253
|
|
242
|
-
|
243
|
-
@f.input(:select, :multiple=>true, :size=>10).to_s.
|
254
|
+
it "should respect multiple and size options in select tag" do
|
255
|
+
@f.input(:select, :multiple=>true, :size=>10).to_s.must_equal '<select multiple="multiple" size="10"></select>'
|
244
256
|
end
|
245
257
|
|
246
|
-
|
247
|
-
@f.input(:date).to_s.
|
258
|
+
it "should create date tag" do
|
259
|
+
@f.input(:date).to_s.must_equal '<input type="date"/>'
|
248
260
|
end
|
249
261
|
|
250
|
-
|
251
|
-
@f.input(:datetime).to_s.
|
262
|
+
it "should create datetime-local tag" do
|
263
|
+
@f.input(:datetime).to_s.must_equal '<input type="datetime-local"/>'
|
252
264
|
end
|
253
265
|
|
254
|
-
|
255
|
-
@f.input(:input).to_s.
|
266
|
+
it "should not error for input type :input" do
|
267
|
+
@f.input(:input).to_s.must_equal '<input type="input"/>'
|
256
268
|
end
|
257
269
|
|
258
|
-
|
259
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.
|
270
|
+
it "should use multiple select boxes for dates if the :as=>:select option is given" do
|
271
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
260
272
|
end
|
261
273
|
|
262
|
-
|
263
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.
|
274
|
+
it "should allow ordering date select boxes via :order" do
|
275
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
|
264
276
|
end
|
265
277
|
|
266
|
-
|
267
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.
|
278
|
+
it "should allow only using specific date select boxes via :order" do
|
279
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
|
268
280
|
end
|
269
281
|
|
270
|
-
|
271
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.
|
282
|
+
it "should support :select_options for dates when :as=>:select is given" do
|
283
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
272
284
|
end
|
273
285
|
|
274
|
-
|
275
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.
|
286
|
+
it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
|
287
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.must_equal %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
|
276
288
|
end
|
277
289
|
|
278
|
-
|
279
|
-
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.
|
290
|
+
it "should use multiple select boxes for datetimes if the :as=>:select option is given" do
|
291
|
+
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
|
280
292
|
end
|
281
293
|
|
282
|
-
|
283
|
-
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2), :order=>[:day, '/', :month, 'T', :hour, ':', :minute]).to_s.
|
294
|
+
it "should allow ordering select boxes for datetimes via :order" do
|
295
|
+
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2), :order=>[:day, '/', :month, 'T', :hour, ':', :minute]).to_s.must_equal %{<select id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>}
|
284
296
|
end
|
285
297
|
|
286
|
-
|
287
|
-
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 10, 3, 2), :select_options=>{:year=>1970..2020, :hour=>9..17}).to_s.
|
298
|
+
it "should support :select_options for datetimes when :as=>:select option is given" do
|
299
|
+
@f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 10, 3, 2), :select_options=>{:year=>1970..2020, :hour=>9..17}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
|
288
300
|
end
|
289
301
|
|
290
|
-
|
291
|
-
@f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.
|
292
|
-
@f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.
|
302
|
+
it "should create select tag with options" do
|
303
|
+
@f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
|
304
|
+
@f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
|
293
305
|
end
|
294
306
|
|
295
|
-
|
296
|
-
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.
|
307
|
+
it "should create select tag with options and values" do
|
308
|
+
@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>'
|
297
309
|
end
|
298
310
|
|
299
|
-
|
300
|
-
@f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.
|
311
|
+
it "should create select tag with option groups" do
|
312
|
+
@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>'
|
301
313
|
end
|
302
314
|
|
303
|
-
|
304
|
-
@f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.
|
315
|
+
it "should create select tag with option groups with attributes" do
|
316
|
+
@f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup class="f" label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup class="g" label="e"><option value="3">c</option></optgroup></select>'
|
305
317
|
end
|
306
318
|
|
307
|
-
|
308
|
-
@f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.
|
319
|
+
it "should create select tag with options and values with hashes" do
|
320
|
+
@f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.must_equal '<select><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select>'
|
309
321
|
end
|
310
322
|
|
311
|
-
|
312
|
-
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.
|
313
|
-
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.
|
323
|
+
it "should create select tag with options and values using given method" do
|
324
|
+
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
|
325
|
+
@f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<select><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select>'
|
314
326
|
end
|
315
327
|
|
316
|
-
|
317
|
-
@f.input(:text, :value=>'foo', :name=>'bar').to_s.
|
318
|
-
@f.input(:textarea, :value=>'foo', :name=>'bar').to_s.
|
319
|
-
@f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.
|
328
|
+
it "should use html attributes specified in options" do
|
329
|
+
@f.input(:text, :value=>'foo', :name=>'bar').to_s.must_equal '<input name="bar" type="text" value="foo"/>'
|
330
|
+
@f.input(:textarea, :value=>'foo', :name=>'bar').to_s.must_equal '<textarea name="bar">foo</textarea>'
|
331
|
+
@f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.must_equal '<select name="bar"><option>1</option><option>2</option><option>3</option></select>'
|
320
332
|
end
|
321
333
|
|
322
|
-
|
323
|
-
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.
|
334
|
+
it "should support :add_blank option for select inputs" do
|
335
|
+
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
|
324
336
|
end
|
325
337
|
|
326
|
-
|
338
|
+
it "should use Forme.default_add_blank_prompt value if :add_blank option is true" do
|
327
339
|
begin
|
328
340
|
Forme.default_add_blank_prompt = 'foo'
|
329
|
-
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.
|
341
|
+
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
|
330
342
|
ensure
|
331
343
|
Forme.default_add_blank_prompt = nil
|
332
344
|
end
|
333
345
|
end
|
334
346
|
|
335
|
-
|
336
|
-
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.
|
347
|
+
it "should use :add_blank option value as prompt if it is a String" do
|
348
|
+
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<select><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
|
337
349
|
end
|
338
350
|
|
339
|
-
|
340
|
-
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.
|
351
|
+
it "should support :add_blank option with :blank_position :after for select inputs" do
|
352
|
+
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.must_equal '<select><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select>'
|
341
353
|
end
|
342
354
|
|
343
|
-
|
344
|
-
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.
|
355
|
+
it "should support :add_blank option with :blank_attr option for select inputs" do
|
356
|
+
@f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.must_equal '<select><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
|
345
357
|
end
|
346
358
|
|
347
|
-
|
348
|
-
@f.input(:radioset, :options=>[1, 2, 3], :selected=>2).to_s.
|
349
|
-
@f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.
|
359
|
+
it "should create set of radio buttons" do
|
360
|
+
@f.input(:radioset, :options=>[1, 2, 3], :selected=>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>'
|
361
|
+
@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>'
|
350
362
|
end
|
351
363
|
|
352
|
-
|
353
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.
|
364
|
+
it "should create set of radio buttons with options and values" do
|
365
|
+
@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>'
|
354
366
|
end
|
355
367
|
|
356
|
-
|
357
|
-
@f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.
|
368
|
+
it "should create set of radio buttons with options and values with hashes" do
|
369
|
+
@f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="radio" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label><label class="option"><input id="baz" type="radio" value="c"/> c</label>'
|
358
370
|
end
|
359
371
|
|
360
|
-
|
361
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.
|
362
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.
|
372
|
+
it "should create set of radio buttons with options and values using given method" do
|
373
|
+
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>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>'
|
374
|
+
@f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="radio" value="a"/> 1</label><label class="option"><input checked="checked" type="radio" value="b"/> 2</label><label class="option"><input type="radio" value="c"/> 3</label>'
|
363
375
|
end
|
364
376
|
|
365
|
-
|
366
|
-
@f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.
|
377
|
+
it "should support :add_blank option for radioset inputs" do
|
378
|
+
@f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> </label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
|
367
379
|
end
|
368
380
|
|
369
|
-
|
370
|
-
@f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.
|
381
|
+
it "should use :add_blank option value as prompt if it is a String" do
|
382
|
+
@f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
|
371
383
|
end
|
372
384
|
|
373
|
-
|
374
|
-
@f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.
|
385
|
+
it "should respect the :key option for radio sets" do
|
386
|
+
@f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label>'
|
375
387
|
end
|
376
388
|
|
377
|
-
|
378
|
-
@f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.
|
389
|
+
it "should create set of radio buttons with fieldsets and legends for :optgroups" do
|
390
|
+
@f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="radio" value="3"/> c</label></fieldset>'
|
379
391
|
end
|
380
392
|
|
381
|
-
|
382
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.
|
383
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.
|
393
|
+
it "should create set of checkbox buttons" do
|
394
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
|
395
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
|
384
396
|
end
|
385
397
|
|
386
|
-
|
387
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.
|
398
|
+
it "should create set of checkbox buttons with options and values" do
|
399
|
+
@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>'
|
388
400
|
end
|
389
401
|
|
390
|
-
|
391
|
-
@f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.
|
402
|
+
it "should create set of checkbox buttons with options and values with hashes" do
|
403
|
+
@f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
|
392
404
|
end
|
393
405
|
|
394
|
-
|
395
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.
|
396
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.
|
406
|
+
it "should create set of checkbox buttons with options and values using given method" do
|
407
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
|
408
|
+
@f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="checkbox" value="a"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label><label class="option"><input type="checkbox" value="c"/> 3</label>'
|
397
409
|
end
|
398
410
|
|
399
|
-
|
400
|
-
@f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.
|
411
|
+
it "should support :add_blank option for checkboxset inputs" do
|
412
|
+
@f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> </label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
|
401
413
|
end
|
402
414
|
|
403
|
-
|
404
|
-
@f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.
|
415
|
+
it "should use :add_blank option value as prompt if it is a String" do
|
416
|
+
@f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
|
405
417
|
end
|
406
418
|
|
407
|
-
|
408
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.
|
419
|
+
it "should respect the :key option for checkbox sets" do
|
420
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label>'
|
409
421
|
end
|
410
422
|
|
411
|
-
|
412
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.
|
423
|
+
it "should prefer the :name option to :key option for checkbox sets" do
|
424
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
|
413
425
|
end
|
414
426
|
|
415
|
-
|
416
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.
|
427
|
+
it "should prefer the :name and :id option to :key option for checkbox sets" do
|
428
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.must_equal '<label class="option"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
|
417
429
|
end
|
418
430
|
|
419
|
-
|
420
|
-
@f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.
|
431
|
+
it "should respect the :error option for checkbox sets" do
|
432
|
+
@f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
|
421
433
|
end
|
422
434
|
|
423
|
-
|
424
|
-
@f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.
|
435
|
+
it "should create set of checkbox buttons with fieldsets and legends for optgroups" do
|
436
|
+
@f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
|
425
437
|
end
|
426
438
|
|
427
|
-
|
428
|
-
@f.input(:checkboxset, :options=>[], :error=>'foo', :value=>2).to_s.
|
439
|
+
it "should raise an Error for empty checkbox sets" do
|
440
|
+
@f.input(:checkboxset, :options=>[], :error=>'foo', :value=>2).to_s.must_equal '<span class="error_message">foo</span>'
|
429
441
|
end
|
430
442
|
|
431
|
-
|
432
|
-
@f.input(:radio, :checked=>true).to_s.
|
433
|
-
@f.input(:radio, :checked=>false).to_s.
|
434
|
-
@f.input(:checkbox, :checked=>true).to_s.
|
435
|
-
@f.input(:checkbox, :checked=>false).to_s.
|
443
|
+
it "radio and checkbox inputs should handle :checked option" do
|
444
|
+
@f.input(:radio, :checked=>true).to_s.must_equal '<input checked="checked" type="radio"/>'
|
445
|
+
@f.input(:radio, :checked=>false).to_s.must_equal '<input type="radio"/>'
|
446
|
+
@f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
|
447
|
+
@f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
|
436
448
|
end
|
437
449
|
|
438
|
-
|
439
|
-
@f.input(:text, :autofocus=>true).to_s.
|
440
|
-
@f.input(:text, :autofocus=>false).to_s.
|
450
|
+
it "inputs should handle :autofocus option" do
|
451
|
+
@f.input(:text, :autofocus=>true).to_s.must_equal '<input autofocus="autofocus" type="text"/>'
|
452
|
+
@f.input(:text, :autofocus=>false).to_s.must_equal '<input type="text"/>'
|
441
453
|
end
|
442
454
|
|
443
|
-
|
444
|
-
@f.input(:text, :required=>true).to_s.
|
445
|
-
@f.input(:text, :required=>false).to_s.
|
455
|
+
it "inputs should handle :required option" do
|
456
|
+
@f.input(:text, :required=>true).to_s.must_equal '<input required="required" type="text"/>'
|
457
|
+
@f.input(:text, :required=>false).to_s.must_equal '<input type="text"/>'
|
446
458
|
end
|
447
459
|
|
448
|
-
|
449
|
-
@f.input(:text, :disabled=>true).to_s.
|
450
|
-
@f.input(:text, :disabled=>false).to_s.
|
460
|
+
it "inputs should handle :disabled option" do
|
461
|
+
@f.input(:text, :disabled=>true).to_s.must_equal '<input disabled="disabled" type="text"/>'
|
462
|
+
@f.input(:text, :disabled=>false).to_s.must_equal '<input type="text"/>'
|
451
463
|
end
|
452
464
|
|
453
|
-
|
454
|
-
@f.input(:text, :name=>nil).to_s.
|
455
|
-
@f.input(:textarea, :name=>nil).to_s.
|
465
|
+
it "inputs should not include options with nil values" do
|
466
|
+
@f.input(:text, :name=>nil).to_s.must_equal '<input type="text"/>'
|
467
|
+
@f.input(:textarea, :name=>nil).to_s.must_equal '<textarea></textarea>'
|
456
468
|
end
|
457
469
|
|
458
|
-
|
459
|
-
@f.input(:text, :name=>false).to_s.
|
470
|
+
it "inputs should include options with false values" do
|
471
|
+
@f.input(:text, :name=>false).to_s.must_equal '<input name="false" type="text"/>'
|
460
472
|
end
|
461
473
|
|
462
|
-
|
463
|
-
@f.input(:text, :label=>'Foo', :value=>'foo').to_s.
|
474
|
+
it "should automatically create a label if a :label option is used" do
|
475
|
+
@f.input(:text, :label=>'Foo', :value=>'foo').to_s.must_equal '<label>Foo: <input type="text" value="foo"/></label>'
|
464
476
|
end
|
465
477
|
|
466
|
-
|
467
|
-
@f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.
|
478
|
+
it "should set label attributes with :label_attr option" do
|
479
|
+
@f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.must_equal '<label class="bar">Foo: <input type="text" value="foo"/></label>'
|
468
480
|
end
|
469
481
|
|
470
|
-
|
471
|
-
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.
|
482
|
+
it "should handle implicit labels with checkboxes" do
|
483
|
+
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.must_equal '<input name="a" type="hidden" value="0"/><label><input name="a" type="checkbox" value="foo"/> Foo</label>'
|
472
484
|
end
|
473
485
|
|
474
|
-
|
475
|
-
@f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.
|
486
|
+
it "should handle implicit labels with :label_position=>:after" do
|
487
|
+
@f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.must_equal '<label><input type="text" value="foo"/> Foo</label>'
|
476
488
|
end
|
477
489
|
|
478
|
-
|
479
|
-
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.
|
490
|
+
it "should handle implicit labels with checkboxes with :label_position=>:before" do
|
491
|
+
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.must_equal '<input name="a" type="hidden" value="0"/><label>Foo <input name="a" type="checkbox" value="foo"/></label>'
|
480
492
|
end
|
481
493
|
|
482
|
-
|
483
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.
|
494
|
+
it "should automatically note the input has errors if :error option is used" do
|
495
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<input class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
484
496
|
end
|
485
497
|
|
486
|
-
|
487
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.
|
498
|
+
it "should add an error message after the label" do
|
499
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<label>Foo: <input class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
|
488
500
|
end
|
489
501
|
|
490
|
-
|
491
|
-
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.
|
502
|
+
it "should add to existing :class option if :error option is used" do
|
503
|
+
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<input class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
492
504
|
end
|
493
505
|
|
494
|
-
|
495
|
-
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.
|
506
|
+
it "should respect :error_attr option for setting the attributes for the error message span" do
|
507
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
|
496
508
|
end
|
497
509
|
|
498
|
-
|
499
|
-
@f.open(:action=>'foo', :method=>'post').to_s.
|
510
|
+
it "#open should return an opening tag" do
|
511
|
+
@f.open(:action=>'foo', :method=>'post').to_s.must_equal '<form action="foo" method="post">'
|
500
512
|
end
|
501
513
|
|
502
|
-
|
503
|
-
@f.close.to_s.
|
514
|
+
it "#close should return a closing tag" do
|
515
|
+
@f.close.to_s.must_equal '</form>'
|
504
516
|
end
|
505
517
|
|
506
|
-
|
507
|
-
@f.button.to_s.
|
518
|
+
it "#button should return a submit tag" do
|
519
|
+
@f.button.to_s.must_equal '<input type="submit"/>'
|
508
520
|
end
|
509
521
|
|
510
|
-
|
511
|
-
@f.button(:name=>'foo', :value=>'bar').to_s.
|
522
|
+
it "#button should accept an options hash" do
|
523
|
+
@f.button(:name=>'foo', :value=>'bar').to_s.must_equal '<input name="foo" type="submit" value="bar"/>'
|
512
524
|
end
|
513
525
|
|
514
|
-
|
515
|
-
@f.button('foo').to_s.
|
526
|
+
it "#button should accept a string to use as a value" do
|
527
|
+
@f.button('foo').to_s.must_equal '<input type="submit" value="foo"/>'
|
516
528
|
end
|
517
529
|
|
518
|
-
|
519
|
-
@f.tag(:textarea).to_s.
|
520
|
-
@f.tag(:textarea, :name=>:foo).to_s.
|
521
|
-
@f.tag(:textarea, {:name=>:foo}, :bar).to_s.
|
530
|
+
it "#tag should return a serialized_tag" do
|
531
|
+
@f.tag(:textarea).to_s.must_equal '<textarea></textarea>'
|
532
|
+
@f.tag(:textarea, :name=>:foo).to_s.must_equal '<textarea name="foo"></textarea>'
|
533
|
+
@f.tag(:textarea, {:name=>:foo}, :bar).to_s.must_equal '<textarea name="foo">bar</textarea>'
|
522
534
|
end
|
523
535
|
|
524
|
-
|
525
|
-
@f.tag(:div, {:class=>"foo"}, lambda{|t| t.form.tag(:input, :class=>t.attr[:class])}).to_s.
|
536
|
+
it "#tag should accept children as procs" do
|
537
|
+
@f.tag(:div, {:class=>"foo"}, lambda{|t| t.form.tag(:input, :class=>t.attr[:class])}).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
|
526
538
|
end
|
527
539
|
|
528
|
-
|
540
|
+
it "#tag should accept children as methods" do
|
529
541
|
o = Object.new
|
530
542
|
def o.foo(t) t.form.tag(:input, :class=>t.attr[:class]) end
|
531
|
-
@f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.
|
543
|
+
@f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
|
532
544
|
end
|
533
545
|
|
534
|
-
|
535
|
-
@f.inputs([:textarea, :text]).to_s.
|
546
|
+
it "should have an #inputs method for multiple inputs wrapped in a fieldset" do
|
547
|
+
@f.inputs([:textarea, :text]).to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
|
536
548
|
end
|
537
549
|
|
538
|
-
|
539
|
-
@f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.
|
550
|
+
it "should have default #inputs method accept an :attr option" do
|
551
|
+
@f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.must_equal '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
|
540
552
|
end
|
541
553
|
|
542
|
-
|
543
|
-
@f.inputs([:textarea, :text], :legend=>'Inputs').to_s.
|
554
|
+
it "should have default #inputs method accept a :legend option" do
|
555
|
+
@f.inputs([:textarea, :text], :legend=>'Inputs').to_s.must_equal '<fieldset class="inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
|
544
556
|
end
|
545
557
|
|
546
|
-
|
547
|
-
@f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.
|
558
|
+
it "should have default #inputs method accept a :legend_attr option" do
|
559
|
+
@f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<fieldset class="inputs"><legend class="foo">Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
|
548
560
|
end
|
549
561
|
|
550
|
-
|
551
|
-
@f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.
|
562
|
+
it "should have an #inputs method take a block and yield to it" do
|
563
|
+
@f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
|
552
564
|
end
|
553
565
|
|
554
|
-
|
555
|
-
@f.inputs([:textarea]){@f.input(:text)}.to_s.
|
566
|
+
it "should have an #inputs method work with both args and block" do
|
567
|
+
@f.inputs([:textarea]){@f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
|
556
568
|
end
|
557
569
|
|
558
|
-
|
559
|
-
@f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.
|
570
|
+
it "should have an #inputs method support array arguments and creating inputs with the array as argument list" do
|
571
|
+
@f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.must_equal '<fieldset class="inputs"><textarea name="foo"></textarea><input id="bar" type="text"/></fieldset>'
|
560
572
|
end
|
561
573
|
|
562
|
-
|
563
|
-
@f.inputs([:textarea, :text], :wrapper=>:div).to_s.
|
574
|
+
it "should have #inputs accept transformer options to modify the options inside the inputs" do
|
575
|
+
@f.inputs([:textarea, :text], :wrapper=>:div).to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea></div><div><input type="text"/></div></fieldset>'
|
564
576
|
end
|
565
577
|
|
566
|
-
|
567
|
-
@f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.
|
578
|
+
it "should have #inputs accept :nested_inputs_wrapper options to modify the :input_wrapper option inside the inputs" do
|
579
|
+
@f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea><input type="text"/></div></fieldset>'
|
568
580
|
end
|
569
581
|
|
570
|
-
|
571
|
-
@f.tag(:div, {}, ['<p></p>']).to_s.
|
582
|
+
it "should escape tag content" do
|
583
|
+
@f.tag(:div, {}, ['<p></p>']).to_s.must_equal '<div><p></p></div>'
|
572
584
|
end
|
573
585
|
|
574
|
-
|
575
|
-
@f.tag(:div, {}, ['<p></p>'.extend(Forme::Raw)]).to_s.
|
586
|
+
it "should not escape raw tag content using Forme::Raw" do
|
587
|
+
@f.tag(:div, {}, ['<p></p>'.dup.extend(Forme::Raw)]).to_s.must_equal '<div><p></p></div>'
|
576
588
|
end
|
577
589
|
|
578
|
-
|
579
|
-
@f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.
|
590
|
+
it "should not escape raw tag content using Forme.raw" do
|
591
|
+
@f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
|
580
592
|
end
|
581
593
|
|
582
|
-
|
583
|
-
@f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.
|
594
|
+
it "should not escape raw tag content using Form#raw" do
|
595
|
+
@f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
|
584
596
|
end
|
585
597
|
|
586
|
-
|
587
|
-
@f.tag(:div, :foo=>'<p></p>').to_s.
|
598
|
+
it "should escape tag content in attribute values" do
|
599
|
+
@f.tag(:div, :foo=>'<p></p>').to_s.must_equal '<div foo="<p></p>"></div>'
|
588
600
|
end
|
589
601
|
|
590
|
-
|
591
|
-
@f.tag(:div, :foo=>'<p></p>'
|
602
|
+
it "should not escape raw tag content in attribute values" do
|
603
|
+
@f.tag(:div, :foo=>Forme.raw('<p></p>')).to_s.must_equal '<div foo="<p></p>"></div>'
|
592
604
|
end
|
593
605
|
|
594
|
-
|
595
|
-
@f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.
|
596
|
-
@f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.
|
597
|
-
@f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.
|
606
|
+
it "should format dates, times, and datetimes in ISO format" do
|
607
|
+
@f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
|
608
|
+
@f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
|
609
|
+
@f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_match /<div foo="2011-06-05T04:03:02.000000"><\/div>/
|
598
610
|
end
|
599
611
|
|
600
|
-
|
601
|
-
@f.tag(:div, :foo=>BigDecimal.new('10000.010')).to_s.
|
612
|
+
it "should format bigdecimals in standard notation" do
|
613
|
+
@f.tag(:div, :foo=>BigDecimal.new('10000.010')).to_s.must_equal '<div foo="10000.01"></div>'
|
602
614
|
end
|
603
615
|
|
604
|
-
|
605
|
-
@f.input(:text, :wrapper=>:li).to_s.
|
616
|
+
it "inputs should accept a :wrapper option to use a custom wrapper" do
|
617
|
+
@f.input(:text, :wrapper=>:li).to_s.must_equal '<li><input type="text"/></li>'
|
606
618
|
end
|
607
619
|
|
608
|
-
|
609
|
-
@f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.
|
620
|
+
it "inputs should accept a :wrapper_attr option to use custom wrapper attributes" do
|
621
|
+
@f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.must_equal '<li class="foo"><input type="text"/></li>'
|
610
622
|
end
|
611
623
|
|
612
|
-
|
613
|
-
@f.input(:text, :help=>"List type of foo").to_s.
|
624
|
+
it "inputs should accept a :help option to use custom helper text" do
|
625
|
+
@f.input(:text, :help=>"List type of foo").to_s.must_equal '<input type="text"/><span class="helper">List type of foo</span>'
|
614
626
|
end
|
615
627
|
|
616
|
-
|
617
|
-
@f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.
|
628
|
+
it "inputs should accept a :helper_attr option for custom helper attributes" do
|
629
|
+
@f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.must_equal '<input type="text"/><span class="foo helper">List type of foo</span>'
|
618
630
|
end
|
619
631
|
|
620
|
-
|
621
|
-
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.
|
632
|
+
it "inputs should have helper displayed inside wrapper, after error" do
|
633
|
+
@f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li><input class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
|
622
634
|
end
|
623
635
|
|
624
|
-
|
625
|
-
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.
|
626
|
-
@f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.
|
636
|
+
it "inputs should accept a :formatter option to use a custom formatter" do
|
637
|
+
@f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span>1</span></label>'
|
638
|
+
@f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <input type="text" value="1"/></label>'
|
627
639
|
end
|
628
640
|
|
629
|
-
|
630
|
-
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.
|
641
|
+
it "inputs should accept a :labeler option to use a custom labeler" do
|
642
|
+
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
|
631
643
|
end
|
632
644
|
|
633
|
-
|
634
|
-
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.
|
645
|
+
it "inputs handle explicit labels with :label_position=>:after" do
|
646
|
+
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.must_equal '<textarea id="foo"></textarea><label class="label-after" for="foo">bar</label>'
|
635
647
|
end
|
636
648
|
|
637
|
-
|
638
|
-
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.
|
649
|
+
it "should handle explicit labels with checkboxes" do
|
650
|
+
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.must_equal '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label class="label-after" for="bar">Foo</label>'
|
639
651
|
end
|
640
652
|
|
641
|
-
|
642
|
-
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.
|
653
|
+
it "should handle explicit labels with checkboxes with :label_position=>:before" do
|
654
|
+
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.must_equal '<label class="label-before" for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
|
643
655
|
end
|
644
656
|
|
645
|
-
|
646
|
-
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.
|
657
|
+
it "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
|
658
|
+
@f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.must_equal '<label>Foo <input id="bar" name="a" type="checkbox" value="foo"/></label>'
|
647
659
|
end
|
648
660
|
|
649
|
-
|
650
|
-
@f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.
|
661
|
+
it "inputs should accept a :error_handler option to use a custom error_handler" do
|
662
|
+
@f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>!!! bar'
|
651
663
|
end
|
652
664
|
|
653
|
-
|
654
|
-
@f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.
|
665
|
+
it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
|
666
|
+
@f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.must_equal '<ol><textarea></textarea></ol>'
|
655
667
|
end
|
656
668
|
|
657
|
-
|
658
|
-
Forme::Form.new(:wrapper=>:li).input(:text, :wrapper=>nil).to_s.
|
669
|
+
it "inputs should accept a :wrapper=>nil option to not use a wrapper" do
|
670
|
+
Forme::Form.new(:wrapper=>:li).input(:text, :wrapper=>nil).to_s.must_equal '<input type="text"/>'
|
659
671
|
end
|
660
672
|
|
661
|
-
|
662
|
-
@f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.
|
673
|
+
it "inputs should accept a :labeler=>nil option to not use a labeler" do
|
674
|
+
@f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.must_equal '<textarea id="foo"></textarea>'
|
663
675
|
end
|
664
676
|
|
665
|
-
|
666
|
-
@f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.
|
677
|
+
it "inputs should accept a :error_handler=>nil option to not use an error_handler" do
|
678
|
+
@f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>'
|
667
679
|
end
|
668
680
|
|
669
|
-
|
670
|
-
@f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.
|
681
|
+
it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
|
682
|
+
@f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.must_equal '<form><textarea></textarea></form>'
|
671
683
|
end
|
672
684
|
|
673
|
-
|
674
|
-
@f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.
|
685
|
+
it "#inputs should treat a single hash argument as an options hash with no default inputs" do
|
686
|
+
@f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.must_equal '<ol><textarea></textarea></ol>'
|
675
687
|
end
|
676
688
|
|
677
|
-
|
689
|
+
it "should support setting defaults for inputs at the form level" do
|
678
690
|
f = Forme::Form.new(:input_defaults=>{'text'=>{:size=>20}, 'textarea'=>{:cols=>80, :rows=>6}})
|
679
|
-
f.input(:text, :name=>"foo").to_s.
|
680
|
-
f.input(:textarea, :name=>"foo").to_s.
|
691
|
+
f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
|
692
|
+
f.input(:textarea, :name=>"foo").to_s.must_equal '<textarea cols="80" name="foo" rows="6"></textarea>'
|
681
693
|
end
|
682
694
|
|
683
|
-
|
695
|
+
it "should work with input_defaults with symbol keys using using inputs with symbol keys" do
|
684
696
|
f = Forme::Form.new(:input_defaults=>{:text=>{:size=>20}, 'text'=>{:size=>30}})
|
685
|
-
f.input(:text, :name=>"foo").to_s.
|
686
|
-
f.input('text', :name=>"foo").to_s.
|
697
|
+
f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
|
698
|
+
f.input('text', :name=>"foo").to_s.must_equal '<input name="foo" size="30" type="text"/>'
|
687
699
|
end
|
688
700
|
|
689
|
-
|
690
|
-
proc{Forme::Form.new(:wrapper=>Object.new).input(:text).to_s}.
|
691
|
-
proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.
|
692
|
-
proc{@f.input(:textarea, :formatter=>nil).to_s}.
|
701
|
+
it "invalid custom transformers should raise an Error" do
|
702
|
+
proc{Forme::Form.new(:wrapper=>Object.new).input(:text).to_s}.must_raise(Forme::Error)
|
703
|
+
proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.must_raise(Forme::Error)
|
704
|
+
proc{@f.input(:textarea, :formatter=>nil).to_s}.must_raise(Forme::Error)
|
693
705
|
end
|
694
706
|
end
|
695
707
|
|
@@ -698,251 +710,255 @@ describe "Forme::Form :hidden_tags option " do
|
|
698
710
|
@f = Forme::Form.new
|
699
711
|
end
|
700
712
|
|
701
|
-
|
702
|
-
Forme.form({}, :hidden_tags=>[{:a=>'b'}]).to_s.
|
713
|
+
it "should handle hash" do
|
714
|
+
Forme.form({}, :hidden_tags=>[{:a=>'b'}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
|
703
715
|
end
|
704
716
|
|
705
|
-
|
706
|
-
Forme.form({}, :hidden_tags=>[["a ", "b"]]).to_s.
|
717
|
+
it "should handle array" do
|
718
|
+
Forme.form({}, :hidden_tags=>[["a ", "b"]]).to_s.must_equal '<form>a b</form>'
|
707
719
|
end
|
708
720
|
|
709
|
-
|
710
|
-
Forme.form({}, :hidden_tags=>["a "]).to_s.
|
721
|
+
it "should handle string" do
|
722
|
+
Forme.form({}, :hidden_tags=>["a "]).to_s.must_equal '<form>a </form>'
|
711
723
|
end
|
712
724
|
|
713
|
-
|
714
|
-
Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]).to_s.
|
725
|
+
it "should handle proc return hash" do
|
726
|
+
Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
|
715
727
|
end
|
716
728
|
|
717
|
-
|
718
|
-
Forme.form({:method=>'post'}, :hidden_tags=>[lambda{|tag| tag.form._tag(tag.attr[:method])}]).to_s.
|
729
|
+
it "should handle proc return tag" do
|
730
|
+
Forme.form({:method=>'post'}, :hidden_tags=>[lambda{|tag| tag.form._tag(tag.attr[:method])}]).to_s.must_equal '<form method="post"><post></post></form>'
|
719
731
|
end
|
720
732
|
|
721
|
-
|
722
|
-
proc{Forme.form({}, :hidden_tags=>[Object.new])}.
|
733
|
+
it "should raise error for unhandled object" do
|
734
|
+
proc{Forme.form({}, :hidden_tags=>[Object.new])}.must_raise Forme::Error
|
723
735
|
end
|
724
736
|
end
|
725
737
|
|
726
738
|
describe "Forme custom" do
|
727
|
-
|
728
|
-
Forme::Form.new(:formatter=>proc{|i| i.form._tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.
|
739
|
+
it "formatters can be specified as a proc" do
|
740
|
+
Forme::Form.new(:formatter=>proc{|i| i.form._tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.must_equal '<textarea foo="name"></textarea>'
|
729
741
|
end
|
730
742
|
|
731
|
-
|
732
|
-
Forme::Form.new(:serializer=>proc{|t| "#{t.type} = #{t.opts[:name]}"}).input(:textarea, :name=>'foo').to_s.
|
743
|
+
it "serializers can be specified as a proc" do
|
744
|
+
Forme::Form.new(:serializer=>proc{|t| "#{t.type} = #{t.opts[:name]}"}).input(:textarea, :name=>'foo').to_s.must_equal 'textarea = foo'
|
733
745
|
end
|
734
746
|
|
735
|
-
|
736
|
-
Forme::Form.new(:labeler=>proc{|t, i| ["#{i.opts[:label]}: ", t]}).input(:textarea, :name=>'foo', :label=>'bar').to_s.
|
747
|
+
it "labelers can be specified as a proc" do
|
748
|
+
Forme::Form.new(:labeler=>proc{|t, i| ["#{i.opts[:label]}: ", t]}).input(:textarea, :name=>'foo', :label=>'bar').to_s.must_equal 'bar: <textarea name="foo"></textarea>'
|
737
749
|
end
|
738
750
|
|
739
|
-
|
740
|
-
Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.
|
751
|
+
it "error_handlers can be specified as a proc" do
|
752
|
+
Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.must_equal '<textarea class="error" name="foo"></textarea>!!! bar'
|
741
753
|
end
|
742
754
|
|
743
|
-
|
744
|
-
Forme::Form.new(:wrapper=>proc{|t, i| t.tag(:div, {:bar=>i.opts[:name]}, t)}).input(:textarea, :name=>'foo').to_s.
|
755
|
+
it "wrappers can be specified as a proc" do
|
756
|
+
Forme::Form.new(:wrapper=>proc{|t, i| t.tag(:div, {:bar=>i.opts[:name]}, t)}).input(:textarea, :name=>'foo').to_s.must_equal '<div bar="foo"><textarea name="foo"></textarea></div>'
|
745
757
|
end
|
746
758
|
|
747
|
-
|
748
|
-
Forme::Form.new(:inputs_wrapper=>proc{|f, opts, &block| f.tag(:div, &block)}).inputs([:textarea]).to_s.
|
759
|
+
it "inputs_wrappers can be specified as a proc" do
|
760
|
+
Forme::Form.new(:inputs_wrapper=>proc{|f, opts, &block| f.tag(:div, &block)}).inputs([:textarea]).to_s.must_equal '<div><textarea></textarea></div>'
|
749
761
|
end
|
750
762
|
|
751
|
-
|
752
|
-
Forme::Form.new(:labeler=>nil).input(:textarea, :label=>'foo').to_s.
|
763
|
+
it "can use nil as value to disable default transformer" do
|
764
|
+
Forme::Form.new(:labeler=>nil).input(:textarea, :label=>'foo').to_s.must_equal '<textarea></textarea>'
|
753
765
|
end
|
754
766
|
end
|
755
767
|
|
756
768
|
describe "Forme built-in custom" do
|
757
|
-
|
758
|
-
proc{Forme::Form.new(:formatter=>:foo).input(:text).to_s}.
|
769
|
+
it "transformers should raise if the there is no matching transformer" do
|
770
|
+
proc{Forme::Form.new(:formatter=>:foo).input(:text).to_s}.must_raise(Forme::Error)
|
771
|
+
end
|
772
|
+
|
773
|
+
it "formatter: disabled disables all inputs unless :disabled=>false option" do
|
774
|
+
Forme::Form.new(:formatter=>:disabled).input(:textarea).to_s.must_equal '<textarea disabled="disabled"></textarea>'
|
775
|
+
Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.must_equal '<textarea></textarea>'
|
759
776
|
end
|
760
777
|
|
761
|
-
|
762
|
-
Forme::Form.new(:formatter=>:
|
763
|
-
Forme::Form.new(:formatter=>:
|
778
|
+
it "formatter: readonly uses spans for most input fields and disables radio/checkbox fields" do
|
779
|
+
Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span>Bar</span></label>"
|
780
|
+
Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span>Bar</span></label>"
|
781
|
+
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>"
|
782
|
+
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>"
|
783
|
+
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>"
|
784
|
+
Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
|
785
|
+
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>"
|
764
786
|
end
|
765
787
|
|
766
|
-
|
767
|
-
Forme
|
768
|
-
Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.should == "<label>Foo: <span>Bar</span></label>"
|
769
|
-
Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar").to_s.should == "<label><input disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
|
770
|
-
Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "<label><input checked=\"checked\" disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
|
771
|
-
Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.should == "<label><input disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
|
772
|
-
Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "<label><input checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
|
773
|
-
Forme::Form.new(:formatter=>:readonly).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.should == "<label>Foo: <span>2</span></label>"
|
788
|
+
it "formatter: readonly should ignore submit buttons" do
|
789
|
+
Forme.form({}, :formatter=>:readonly, :button=>'a').to_s.must_equal '<form></form>'
|
774
790
|
end
|
775
791
|
|
776
|
-
|
777
|
-
Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.
|
792
|
+
it "labeler: explicit uses an explicit label with for attribute" do
|
793
|
+
Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
|
778
794
|
end
|
779
795
|
|
780
|
-
|
781
|
-
Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.
|
796
|
+
it "labeler: explicit handles the key option correctly" do
|
797
|
+
Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
|
782
798
|
end
|
783
799
|
|
784
|
-
|
785
|
-
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.
|
800
|
+
it "labeler: explicit should handle tags with errors" do
|
801
|
+
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
|
786
802
|
end
|
787
803
|
|
788
|
-
|
789
|
-
Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo').to_s.
|
790
|
-
Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
804
|
+
it "wrapper: li wraps tag in an li" do
|
805
|
+
Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo').to_s.must_equal '<li><textarea id="foo"></textarea></li>'
|
806
|
+
Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<li id="bar"><textarea id="foo"></textarea></li>'
|
791
807
|
end
|
792
808
|
|
793
|
-
|
794
|
-
Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo').to_s.
|
795
|
-
Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
809
|
+
it "wrapper: p wraps tag in an p" do
|
810
|
+
Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo').to_s.must_equal '<p><textarea id="foo"></textarea></p>'
|
811
|
+
Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<p id="bar"><textarea id="foo"></textarea></p>'
|
796
812
|
end
|
797
813
|
|
798
|
-
|
799
|
-
Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo').to_s.
|
800
|
-
Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
814
|
+
it "wrapper: div wraps tag in an div" do
|
815
|
+
Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo').to_s.must_equal '<div><textarea id="foo"></textarea></div>'
|
816
|
+
Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<div id="bar"><textarea id="foo"></textarea></div>'
|
801
817
|
end
|
802
818
|
|
803
|
-
|
804
|
-
Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo').to_s.
|
805
|
-
Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
819
|
+
it "wrapper: span wraps tag in an span" do
|
820
|
+
Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo').to_s.must_equal '<span><textarea id="foo"></textarea></span>'
|
821
|
+
Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<span id="bar"><textarea id="foo"></textarea></span>'
|
806
822
|
end
|
807
823
|
|
808
|
-
|
809
|
-
Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo').to_s.
|
810
|
-
Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
824
|
+
it "wrapper: td wraps tag in an td" do
|
825
|
+
Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo').to_s.must_equal '<td><textarea id="foo"></textarea></td>'
|
826
|
+
Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<td id="bar"><textarea id="foo"></textarea></td>'
|
811
827
|
end
|
812
828
|
|
813
|
-
|
814
|
-
Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo').to_s.
|
815
|
-
Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.
|
829
|
+
it "wrapper: trtd wraps tag in an tr/td" do
|
830
|
+
Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo').to_s.must_equal '<tr><td><textarea id="foo"></textarea></td><td></td></tr>'
|
831
|
+
Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<tr id="bar"><td><textarea id="foo"></textarea></td><td></td></tr>'
|
816
832
|
end
|
817
833
|
|
818
|
-
|
819
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.
|
834
|
+
it "wrapper: trtd supports multiple tags in separate tds" do
|
835
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
|
820
836
|
end
|
821
837
|
|
822
|
-
|
823
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.
|
838
|
+
it "wrapper: trtd should use at most 2 td tags" do
|
839
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
|
824
840
|
end
|
825
841
|
|
826
|
-
|
827
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.
|
842
|
+
it "wrapper: trtd should handle inputs with label after" do
|
843
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-after" for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
|
828
844
|
end
|
829
845
|
|
830
|
-
|
831
|
-
Forme::Form.new(:wrapper=>:tr).inputs([:textarea]).to_s.
|
846
|
+
it "wrapper: tr should use a td wrapper and tr inputs_wrapper" do
|
847
|
+
Forme::Form.new(:wrapper=>:tr).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
|
832
848
|
f = Forme::Form.new
|
833
|
-
f.with_opts(:wrapper=>:tr){f.inputs([:textarea])}.to_s.
|
849
|
+
f.with_opts(:wrapper=>:tr){f.inputs([:textarea])}.to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
|
834
850
|
end
|
835
851
|
|
836
|
-
|
837
|
-
Forme::Form.new(:wrapper=>:table).inputs([:textarea]).to_s.
|
852
|
+
it "wrapper: table should use a trtd wrapper and table inputs_wrapper" do
|
853
|
+
Forme::Form.new(:wrapper=>:table).inputs([:textarea]).to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
|
838
854
|
f = Forme::Form.new
|
839
|
-
f.with_opts(:wrapper=>:table){f.inputs([:textarea])}.to_s.
|
855
|
+
f.with_opts(:wrapper=>:table){f.inputs([:textarea])}.to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
|
840
856
|
end
|
841
857
|
|
842
|
-
|
843
|
-
Forme::Form.new(:wrapper=>:ol).inputs([:textarea]).to_s.
|
858
|
+
it "wrapper: ol should use an li wrapper and ol inputs_wrapper" do
|
859
|
+
Forme::Form.new(:wrapper=>:ol).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
|
844
860
|
f = Forme::Form.new
|
845
|
-
f.with_opts(:wrapper=>:ol){f.inputs([:textarea])}.to_s.
|
861
|
+
f.with_opts(:wrapper=>:ol){f.inputs([:textarea])}.to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
|
846
862
|
end
|
847
863
|
|
848
|
-
|
849
|
-
Forme::Form.new(:wrapper=>:fieldset_ol).inputs([:textarea]).to_s.
|
864
|
+
it "wrapper: fieldset_ol should use an li wrapper and fieldset_ol inputs_wrapper" do
|
865
|
+
Forme::Form.new(:wrapper=>:fieldset_ol).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
|
850
866
|
f = Forme::Form.new
|
851
|
-
f.with_opts(:wrapper=>:fieldset_ol){f.inputs([:textarea])}.to_s.
|
867
|
+
f.with_opts(:wrapper=>:fieldset_ol){f.inputs([:textarea])}.to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
|
852
868
|
end
|
853
869
|
|
854
|
-
|
855
|
-
Forme::Form.new(:wrapper=>:tr, :inputs_wrapper=>:div).inputs([:textarea]).to_s.
|
870
|
+
it "wrapper should not override inputs_wrapper if both given" do
|
871
|
+
Forme::Form.new(:wrapper=>:tr, :inputs_wrapper=>:div).inputs([:textarea]).to_s.must_equal '<div><td><textarea></textarea></td></div>'
|
856
872
|
f = Forme::Form.new
|
857
|
-
f.with_opts(:wrapper=>:tr, :inputs_wrapper=>:div){f.inputs([:textarea])}.to_s.
|
873
|
+
f.with_opts(:wrapper=>:tr, :inputs_wrapper=>:div){f.inputs([:textarea])}.to_s.must_equal '<div><td><textarea></textarea></td></div>'
|
858
874
|
end
|
859
875
|
|
860
|
-
|
861
|
-
Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea]).to_s.
|
862
|
-
Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.
|
876
|
+
it "inputs_wrapper: ol wraps tags in an ol" do
|
877
|
+
Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
|
878
|
+
Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<ol foo="1"><li><textarea></textarea></li></ol>'
|
863
879
|
end
|
864
880
|
|
865
|
-
|
866
|
-
Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea]).to_s.
|
867
|
-
Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.
|
881
|
+
it "inputs_wrapper: fieldset_ol wraps tags in a fieldset and an ol" do
|
882
|
+
Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
|
883
|
+
Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<fieldset class="inputs" foo="1"><ol><li><textarea></textarea></li></ol></fieldset>'
|
868
884
|
end
|
869
885
|
|
870
|
-
|
871
|
-
Forme.form({}, :inputs_wrapper=>:fieldset_ol, :wrapper=>:li, :legend=>'Foo', :inputs=>[:textarea]).to_s.
|
886
|
+
it "inputs_wrapper: fieldset_ol supports a :legend option" do
|
887
|
+
Forme.form({}, :inputs_wrapper=>:fieldset_ol, :wrapper=>:li, :legend=>'Foo', :inputs=>[:textarea]).to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><ol><li><textarea></textarea></li></ol></fieldset></form>'
|
872
888
|
end
|
873
889
|
|
874
|
-
|
875
|
-
Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea]).to_s.
|
876
|
-
Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea], :attr=>{:foo=>1}).to_s.
|
890
|
+
it "inputs_wrapper: div wraps tags in a div" do
|
891
|
+
Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea]).to_s.must_equal '<div><span><textarea></textarea></span></div>'
|
892
|
+
Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<div foo="1"><span><textarea></textarea></span></div>'
|
877
893
|
end
|
878
894
|
|
879
|
-
|
880
|
-
Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea]).to_s.
|
881
|
-
Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea], :attr=>{:foo=>1}).to_s.
|
895
|
+
it "inputs_wrapper: tr wraps tags in an tr" do
|
896
|
+
Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
|
897
|
+
Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<tr foo="1"><td><textarea></textarea></td></tr>'
|
882
898
|
end
|
883
899
|
|
884
|
-
|
885
|
-
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea]).to_s.
|
886
|
-
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :attr=>{:foo=>1}).to_s.
|
900
|
+
it "inputs_wrapper: table wraps tags in an table" do
|
901
|
+
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea]).to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
|
902
|
+
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<table foo="1"><tr><td><textarea></textarea></td><td></td></tr></table>'
|
887
903
|
end
|
888
904
|
|
889
|
-
|
890
|
-
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs').to_s.
|
905
|
+
it "inputs_wrapper: table accepts a :legend option" do
|
906
|
+
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs').to_s.must_equal '<table><caption>Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
|
891
907
|
end
|
892
908
|
|
893
|
-
|
894
|
-
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.
|
909
|
+
it "inputs_wrapper: table accepts a :legend_attr option" do
|
910
|
+
Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<table><caption class="foo">Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
|
895
911
|
end
|
896
912
|
|
897
|
-
|
898
|
-
Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.
|
913
|
+
it "inputs_wrapper: table accepts a :labels option" do
|
914
|
+
Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.must_equal '<table><tr><th>A</th><th>B</th><th>C</th></tr></table>'
|
899
915
|
end
|
900
916
|
|
901
|
-
|
902
|
-
Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>[]).to_s.
|
917
|
+
it "inputs_wrapper: table doesn't add empty header row for :labels=>[]" do
|
918
|
+
Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>[]).to_s.must_equal '<table></table>'
|
903
919
|
end
|
904
920
|
|
905
|
-
|
906
|
-
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.
|
907
|
-
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.
|
908
|
-
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.
|
921
|
+
it "serializer: html_usa formats dates and datetimes in American format without timezones" do
|
922
|
+
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="06/05/2011"></div>'
|
923
|
+
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02PM"></div>'
|
924
|
+
Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02AM"></div>'
|
909
925
|
end
|
910
926
|
|
911
|
-
|
912
|
-
Forme::Form.new(:serializer=>:html_usa).input(:date, :value=>Date.new(2011, 6, 5)).to_s.
|
913
|
-
Forme::Form.new(:serializer=>:html_usa).input(:datetime, :value=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.
|
927
|
+
it "serializer: html_usa should convert date and datetime inputs into text inputs" do
|
928
|
+
Forme::Form.new(:serializer=>:html_usa).input(:date, :value=>Date.new(2011, 6, 5)).to_s.must_equal '<input type="text" value="06/05/2011"/>'
|
929
|
+
Forme::Form.new(:serializer=>:html_usa).input(:datetime, :value=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<input type="text" value="06/05/2011 04:03:02PM"/>'
|
914
930
|
end
|
915
931
|
|
916
|
-
|
917
|
-
Forme::Form.new(:serializer=>:text).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.
|
918
|
-
Forme::Form.new(:serializer=>:text).input(:text, :label=>"Foo", :value=>"Bar").to_s.
|
919
|
-
Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar").to_s.
|
920
|
-
Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.
|
921
|
-
Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.
|
922
|
-
Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.
|
923
|
-
Forme::Form.new(:serializer=>:text).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.
|
924
|
-
Forme::Form.new(:serializer=>:text).input(:password, :label=>"Pass").to_s.
|
925
|
-
Forme::Form.new(:serializer=>:text).button().to_s.
|
926
|
-
Forme::Form.new(:serializer=>:text).inputs([[:textarea, {:label=>"Foo", :value=>"Bar"}]], :legend=>'Baz').to_s.
|
927
|
-
Forme::Form.new(:serializer=>:text).tag(:p){|f| f.input(:textarea, :label=>"Foo", :value=>"Bar")}.to_s.
|
932
|
+
it "serializer: text uses plain text output instead of html" do
|
933
|
+
Forme::Form.new(:serializer=>:text).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
|
934
|
+
Forme::Form.new(:serializer=>:text).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
|
935
|
+
Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
|
936
|
+
Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
|
937
|
+
Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
|
938
|
+
Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
|
939
|
+
Forme::Form.new(:serializer=>:text).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "Foo: \n___ 1\n_X_ 2\n___ 3\n\n"
|
940
|
+
Forme::Form.new(:serializer=>:text).input(:password, :label=>"Pass").to_s.must_equal "Pass: ********\n\n"
|
941
|
+
Forme::Form.new(:serializer=>:text).button().to_s.must_equal ""
|
942
|
+
Forme::Form.new(:serializer=>:text).inputs([[:textarea, {:label=>"Foo", :value=>"Bar"}]], :legend=>'Baz').to_s.must_equal "Baz\n---\nFoo: Bar\n\n"
|
943
|
+
Forme::Form.new(:serializer=>:text).tag(:p){|f| f.input(:textarea, :label=>"Foo", :value=>"Bar")}.to_s.must_equal "Foo: Bar\n\n"
|
928
944
|
end
|
929
945
|
end
|
930
946
|
|
931
947
|
describe "Forme registering custom transformers" do
|
932
|
-
|
948
|
+
it "should have #register_transformer register a transformer object for later use" do
|
933
949
|
Forme.register_transformer(:wrapper, :div2, proc{|t, i| i.tag(:div2, {}, [t])})
|
934
|
-
Forme::Form.new(:wrapper=>:div2).input(:textarea).to_s.
|
950
|
+
Forme::Form.new(:wrapper=>:div2).input(:textarea).to_s.must_equal '<div2><textarea></textarea></div2>'
|
935
951
|
end
|
936
952
|
|
937
|
-
|
953
|
+
it "should have #register_transformer register a transformer block for later use" do
|
938
954
|
Forme.register_transformer(:wrapper, :div1){|t, i| i.tag(:div1, {}, [t])}
|
939
|
-
Forme::Form.new(:wrapper=>:div1).input(:textarea).to_s.
|
955
|
+
Forme::Form.new(:wrapper=>:div1).input(:textarea).to_s.must_equal '<div1><textarea></textarea></div1>'
|
940
956
|
end
|
941
957
|
|
942
|
-
|
958
|
+
it "should have #register_transformer raise an error if given a block and an object" do
|
943
959
|
proc do
|
944
960
|
Forme.register_transformer(:wrapper, :div1, proc{|t, i| t}){|t, i| i.tag(:div1, {}, [t])}
|
945
|
-
end.
|
961
|
+
end.must_raise(Forme::Error)
|
946
962
|
end
|
947
963
|
end
|
948
964
|
|
@@ -951,34 +967,34 @@ describe "Forme configurations" do
|
|
951
967
|
Forme.default_config = :default
|
952
968
|
end
|
953
969
|
|
954
|
-
|
955
|
-
Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.
|
970
|
+
it "config: :formastic uses fieldset_ol inputs_wrapper and li wrapper, and explicit labeler" do
|
971
|
+
Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
956
972
|
end
|
957
973
|
|
958
|
-
|
974
|
+
it "should be able to set a default configuration with Forme.default_config=" do
|
959
975
|
Forme.default_config = :formtastic
|
960
|
-
Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.
|
976
|
+
Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
961
977
|
end
|
962
978
|
|
963
|
-
|
979
|
+
it "should have #register_config register a configuration for later use" do
|
964
980
|
Forme.register_config(:foo, :wrapper=>:li, :labeler=>:explicit)
|
965
|
-
Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.
|
981
|
+
Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.must_equal '<li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li>'
|
966
982
|
end
|
967
983
|
|
968
|
-
|
984
|
+
it "should have #register_config support a :base option to base it on an existing config" do
|
969
985
|
Forme.register_config(:foo2, :labeler=>:default, :base=>:formtastic)
|
970
|
-
Forme::Form.new(:config=>:foo2).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.
|
986
|
+
Forme::Form.new(:config=>:foo2).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label>Foo: <textarea id="foo"></textarea></label></li></ol></fieldset>'
|
971
987
|
end
|
972
988
|
|
973
989
|
end
|
974
990
|
|
975
991
|
describe "Forme object forms" do
|
976
|
-
|
992
|
+
it "should handle a simple case" do
|
977
993
|
obj = Class.new{def forme_input(form, field, opts) form._input(:text, :name=>"obj[#{field}]", :id=>"obj_#{field}", :value=>"#{field}_foo") end}.new
|
978
|
-
Forme::Form.new(obj).input(:field).to_s.
|
994
|
+
Forme::Form.new(obj).input(:field).to_s.must_equal '<input id="obj_field" name="obj[field]" type="text" value="field_foo"/>'
|
979
995
|
end
|
980
996
|
|
981
|
-
|
997
|
+
it "should handle more complex case with multiple different types and opts" do
|
982
998
|
obj = Class.new do
|
983
999
|
def self.name() "Foo" end
|
984
1000
|
|
@@ -995,93 +1011,93 @@ describe "Forme object forms" do
|
|
995
1011
|
end
|
996
1012
|
end.new('&foo', 3)
|
997
1013
|
f = Forme::Form.new(obj)
|
998
|
-
f.input(:x).to_s.
|
999
|
-
f.input(:y, :attr=>{:brain=>'no'}).to_s.
|
1014
|
+
f.input(:x).to_s.must_equal '<label>X: <textarea id="foo_x" name="foo[x]">&foo</textarea></label>'
|
1015
|
+
f.input(:y, :attr=>{:brain=>'no'}).to_s.must_equal '<label>Y: <input brain="no" id="foo_y" name="foo[y]" type="text" value="3"/></label>'
|
1000
1016
|
end
|
1001
1017
|
|
1002
|
-
|
1003
|
-
Forme::Form.new([:foo]).input(:first).to_s.
|
1018
|
+
it "should handle case where obj doesn't respond to forme_input" do
|
1019
|
+
Forme::Form.new([:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
|
1004
1020
|
obj = Class.new{attr_accessor :foo}.new
|
1005
1021
|
obj.foo = 'bar'
|
1006
|
-
Forme::Form.new(obj).input(:foo).to_s.
|
1022
|
+
Forme::Form.new(obj).input(:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="bar"/>'
|
1007
1023
|
end
|
1008
1024
|
|
1009
|
-
|
1010
|
-
Forme::Form.new([:foo]).input(:first, :name=>'bar').to_s.
|
1011
|
-
Forme::Form.new([:foo]).input(:first, :id=>'bar').to_s.
|
1012
|
-
Forme::Form.new([:foo]).input(:first, :value=>'bar').to_s.
|
1013
|
-
Forme::Form.new([:foo]).input(:first, :attr=>{:x=>'bar'}).to_s.
|
1025
|
+
it "should respect opts hash when obj doesn't respond to forme_input" do
|
1026
|
+
Forme::Form.new([:foo]).input(:first, :name=>'bar').to_s.must_equal '<input id="first" name="bar" type="text" value="foo"/>'
|
1027
|
+
Forme::Form.new([:foo]).input(:first, :id=>'bar').to_s.must_equal '<input id="bar" name="first" type="text" value="foo"/>'
|
1028
|
+
Forme::Form.new([:foo]).input(:first, :value=>'bar').to_s.must_equal '<input id="first" name="first" type="text" value="bar"/>'
|
1029
|
+
Forme::Form.new([:foo]).input(:first, :attr=>{:x=>'bar'}).to_s.must_equal '<input id="first" name="first" type="text" value="foo" x="bar"/>'
|
1014
1030
|
end
|
1015
1031
|
|
1016
|
-
|
1017
|
-
Forme::Form.new([:foo], :namespace=>'a').input(:first).to_s.
|
1032
|
+
it "should respect current namespace" do
|
1033
|
+
Forme::Form.new([:foo], :namespace=>'a').input(:first).to_s.must_equal '<input id="a_first" name="a[first]" type="text" value="foo"/>'
|
1018
1034
|
end
|
1019
1035
|
|
1020
|
-
|
1021
|
-
Forme::Form.new(:obj=>{:bar=>:foo}, :namespace=>'a').input(:bar).to_s.
|
1036
|
+
it "should get values for hashes using #[]" do
|
1037
|
+
Forme::Form.new(:obj=>{:bar=>:foo}, :namespace=>'a').input(:bar).to_s.must_equal '<input id="a_bar" name="a[bar]" type="text" value="foo"/>'
|
1022
1038
|
end
|
1023
1039
|
|
1024
|
-
|
1025
|
-
Forme::Form.new(:obj=>[:foo]).input(:first).to_s.
|
1040
|
+
it "should handle obj passed in via :obj hash key" do
|
1041
|
+
Forme::Form.new(:obj=>[:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
|
1026
1042
|
end
|
1027
1043
|
|
1028
|
-
|
1029
|
-
Forme::Form.new([:foo]).input(:checkbox, :name=>"foo", :hidden_value=>"no", :obj=>nil).to_s.
|
1044
|
+
it "should be able to turn off obj handling per input using :obj=>nil option" do
|
1045
|
+
Forme::Form.new([:foo]).input(:checkbox, :name=>"foo", :hidden_value=>"no", :obj=>nil).to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
|
1030
1046
|
end
|
1031
1047
|
end
|
1032
1048
|
|
1033
1049
|
describe "Forme.form DSL" do
|
1034
|
-
|
1035
|
-
Forme.form.to_s.
|
1050
|
+
it "should return a form tag" do
|
1051
|
+
Forme.form.to_s.must_equal '<form></form>'
|
1036
1052
|
end
|
1037
1053
|
|
1038
|
-
|
1039
|
-
Forme.form{|f| f.
|
1054
|
+
it "should yield a Form object to the block" do
|
1055
|
+
Forme.form{|f| f.must_be_kind_of(Forme::Form)}
|
1040
1056
|
end
|
1041
1057
|
|
1042
|
-
|
1043
|
-
Forme.form(:class=>[:foo, :bar]).to_s.
|
1044
|
-
Forme.form(:class=>[:foo, [:bar, :baz]]).to_s.
|
1058
|
+
it "should respect an array of classes" do
|
1059
|
+
Forme.form(:class=>[:foo, :bar]).to_s.must_equal '<form class="foo bar"></form>'
|
1060
|
+
Forme.form(:class=>[:foo, [:bar, :baz]]).to_s.must_equal '<form class="foo bar baz"></form>'
|
1045
1061
|
end
|
1046
1062
|
|
1047
|
-
|
1048
|
-
Forme.form{|f| f.input(:text)}.to_s.
|
1063
|
+
it "should have inputs called instead the block be added to the existing form" do
|
1064
|
+
Forme.form{|f| f.input(:text)}.to_s.must_equal '<form><input type="text"/></form>'
|
1049
1065
|
end
|
1050
1066
|
|
1051
|
-
|
1052
|
-
Forme.form{|f| f.tag(:div){f.input(:text)}}.to_s.
|
1053
|
-
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text)}}}.to_s.
|
1054
|
-
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.tag(:span){f.input(:text)}}}}.to_s.
|
1055
|
-
Forme.form{|f| f.tag(:div){f.input(:text)}; f.input(:radio)}.to_s.
|
1056
|
-
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text); f.input(:radio)}; f.input(:checkbox)}}.to_s.
|
1067
|
+
it "should be able to nest inputs inside tags" do
|
1068
|
+
Forme.form{|f| f.tag(:div){f.input(:text)}}.to_s.must_equal '<form><div><input type="text"/></div></form>'
|
1069
|
+
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text)}}}.to_s.must_equal '<form><div><fieldset><input type="text"/></fieldset></div></form>'
|
1070
|
+
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.tag(:span){f.input(:text)}}}}.to_s.must_equal '<form><div><fieldset><span><input type="text"/></span></fieldset></div></form>'
|
1071
|
+
Forme.form{|f| f.tag(:div){f.input(:text)}; f.input(:radio)}.to_s.must_equal '<form><div><input type="text"/></div><input type="radio"/></form>'
|
1072
|
+
Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text); f.input(:radio)}; f.input(:checkbox)}}.to_s.must_equal '<form><div><fieldset><input type="text"/><input type="radio"/></fieldset><input type="checkbox"/></div></form>'
|
1057
1073
|
end
|
1058
1074
|
|
1059
|
-
|
1060
|
-
Forme.form({}, :inputs=>[:text, :textarea]).to_s.
|
1075
|
+
it "should handle an :inputs option to automatically create inputs" do
|
1076
|
+
Forme.form({}, :inputs=>[:text, :textarea]).to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset></form>'
|
1061
1077
|
end
|
1062
1078
|
|
1063
|
-
|
1064
|
-
Forme.form({}, :inputs=>[:text, :textarea], :legend=>'Foo').to_s.
|
1079
|
+
it "should handle a :legend option if inputs is used" do
|
1080
|
+
Forme.form({}, :inputs=>[:text, :textarea], :legend=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><input type="text"/><textarea></textarea></fieldset></form>'
|
1065
1081
|
end
|
1066
1082
|
|
1067
|
-
|
1068
|
-
Forme.form({}, :inputs=>[:text]){|f| f.input(:textarea)}.to_s.
|
1083
|
+
it "should still work with a block if :inputs is used" do
|
1084
|
+
Forme.form({}, :inputs=>[:text]){|f| f.input(:textarea)}.to_s.must_equal '<form><fieldset class="inputs"><input type="text"/></fieldset><textarea></textarea></form>'
|
1069
1085
|
end
|
1070
1086
|
|
1071
|
-
|
1072
|
-
Forme.form({}, :button=>'Foo').to_s.
|
1087
|
+
it "should handle an :button option to automatically create a button" do
|
1088
|
+
Forme.form({}, :button=>'Foo').to_s.must_equal '<form><input type="submit" value="Foo"/></form>'
|
1073
1089
|
end
|
1074
1090
|
|
1075
|
-
|
1076
|
-
Forme.form({}, :button=>{:value=>'Foo', :name=>'bar'}).to_s.
|
1091
|
+
it "should allow :button option value to be a hash" do
|
1092
|
+
Forme.form({}, :button=>{:value=>'Foo', :name=>'bar'}).to_s.must_equal '<form><input name="bar" type="submit" value="Foo"/></form>'
|
1077
1093
|
end
|
1078
1094
|
|
1079
|
-
|
1080
|
-
Forme.form({}, :button=>'Foo'){|f| f.input(:textarea)}.to_s.
|
1095
|
+
it "should handle an :button option work with a block" do
|
1096
|
+
Forme.form({}, :button=>'Foo'){|f| f.input(:textarea)}.to_s.must_equal '<form><textarea></textarea><input type="submit" value="Foo"/></form>'
|
1081
1097
|
end
|
1082
1098
|
|
1083
|
-
|
1084
|
-
Forme.form({}, :inputs=>[:text, :textarea], :button=>'Foo').to_s.
|
1099
|
+
it "should have an :button and :inputs option work together" do
|
1100
|
+
Forme.form({}, :inputs=>[:text, :textarea], :button=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset><input type="submit" value="Foo"/></form>'
|
1085
1101
|
end
|
1086
1102
|
|
1087
1103
|
end
|