padrino-helpers 0.12.9 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/padrino-helpers.rb +2 -2
- data/lib/padrino-helpers/asset_tag_helpers.rb +18 -26
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +3 -56
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +1 -1
- data/lib/padrino-helpers/form_helpers.rb +11 -227
- data/lib/padrino-helpers/form_helpers/options.rb +5 -7
- data/lib/padrino-helpers/output_helpers.rb +1 -1
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +1 -2
- data/lib/padrino-helpers/render_helpers.rb +2 -23
- data/lib/padrino-helpers/tag_helpers.rb +1 -14
- data/lib/padrino/rendering.rb +4 -56
- data/lib/padrino/rendering/erb_template.rb +0 -12
- data/lib/padrino/rendering/erubis_template.rb +1 -1
- data/padrino-helpers.gemspec +1 -1
- data/test/fixtures/markup_app/views/form_for.erb +0 -28
- data/test/fixtures/markup_app/views/form_for.haml +0 -22
- data/test/fixtures/markup_app/views/form_for.slim +0 -21
- data/test/fixtures/markup_app/views/form_tag.erb +0 -21
- data/test/fixtures/markup_app/views/form_tag.haml +0 -14
- data/test/fixtures/markup_app/views/form_tag.slim +0 -14
- data/test/helper.rb +17 -6
- data/test/test_asset_tag_helpers.rb +92 -110
- data/test/test_form_builder.rb +450 -691
- data/test/test_form_helpers.rb +457 -770
- data/test/test_format_helpers.rb +37 -17
- data/test/test_helpers.rb +0 -8
- data/test/test_output_helpers.rb +72 -72
- data/test/test_render_helpers.rb +100 -142
- data/test/test_rendering.rb +1 -58
- data/test/test_tag_helpers.rb +39 -41
- metadata +118 -34
- data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +0 -79
data/test/test_form_helpers.rb
CHANGED
@@ -15,665 +15,664 @@ describe "FormHelpers" do
|
|
15
15
|
describe 'for #form_tag method' do
|
16
16
|
it 'should display correct forms in ruby' do
|
17
17
|
actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test', :method => "post") { "Demo" }
|
18
|
-
|
19
|
-
|
18
|
+
assert_has_tag(:form, :"accept-charset" => "UTF-8", :class => "test") { actual_html }
|
19
|
+
assert_has_tag('form input', :type => 'hidden', :name => '_method', :count => 0) { actual_html }
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should display correct text inputs within form_tag' do
|
23
23
|
actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test') { text_field_tag(:username) }
|
24
|
-
|
25
|
-
assert_html_has_no_tag(actual_html, 'form input', :type => 'hidden', :name => "_method")
|
24
|
+
assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'should display correct form with remote' do
|
29
28
|
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :remote => true) { "Demo" }
|
30
|
-
|
31
|
-
|
29
|
+
assert_has_tag(:form, :class => "put-form", :"accept-charset" => "UTF-8", :"data-remote" => 'true') { actual_html }
|
30
|
+
assert_has_no_tag(:form, "data-method" => 'post') { actual_html }
|
32
31
|
end
|
33
32
|
|
34
33
|
it 'should display correct form with remote and method is put' do
|
35
34
|
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :method => 'put', :remote => true) { "Demo" }
|
36
|
-
|
37
|
-
|
35
|
+
assert_has_tag(:form, "data-remote" => 'true', :"accept-charset" => "UTF-8") { actual_html }
|
36
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'should display correct form with method :put' do
|
41
40
|
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :method => "put") { "Demo" }
|
42
|
-
|
43
|
-
|
41
|
+
assert_has_tag(:form, :class => "put-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
|
42
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
|
44
43
|
end
|
45
44
|
|
46
45
|
it 'should display correct form with method :delete and charset' do
|
47
46
|
actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :class => 'delete-form', :method => "delete") { "Demo" }
|
48
|
-
|
49
|
-
|
47
|
+
assert_has_tag(:form, :class => "delete-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
|
48
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
|
50
49
|
end
|
51
50
|
|
52
51
|
it 'should display correct form with charset' do
|
53
52
|
actual_html = form_tag('/charset', :"accept-charset" => "UTF-8", :class => 'charset-form') { "Demo" }
|
54
|
-
|
53
|
+
assert_has_tag(:form, :class => "charset-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'should display correct form with multipart encoding' do
|
58
57
|
actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
|
59
|
-
|
58
|
+
assert_has_tag(:form, :enctype => "multipart/form-data") { actual_html }
|
60
59
|
end
|
61
60
|
|
62
61
|
it 'should have an authenticity_token for method :post, :put or :delete' do
|
63
62
|
%w(post put delete).each do |method|
|
64
63
|
actual_html = form_tag('/modify', :method => method) { "Demo" }
|
65
|
-
|
64
|
+
assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
it 'should not have an authenticity_token if method: :get' do
|
70
69
|
actual_html = form_tag('/get', :method => :get) { "Demo" }
|
71
|
-
|
70
|
+
assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
|
72
71
|
end
|
73
72
|
|
74
73
|
it 'should have an authenticity_token by default' do
|
75
74
|
actual_html = form_tag('/superadmindelete') { "Demo" }
|
76
|
-
|
75
|
+
assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
|
77
76
|
end
|
78
77
|
|
79
78
|
it 'should create csrf meta tags with token and param - #csrf_meta_tags' do
|
80
79
|
actual_html = csrf_meta_tags
|
81
|
-
|
82
|
-
|
80
|
+
assert_has_tag(:meta, :name => 'csrf-param') { actual_html }
|
81
|
+
assert_has_tag(:meta, :name => 'csrf-token') { actual_html }
|
83
82
|
end
|
84
83
|
|
85
84
|
it 'should have an authenticity_token by default' do
|
86
85
|
actual_html = form_tag('/superadmindelete') { "Demo" }
|
87
|
-
|
86
|
+
assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
|
88
87
|
end
|
89
88
|
|
90
89
|
it 'should not have an authenticity_token if passing protect_from_csrf: false' do
|
91
90
|
actual_html = form_tag('/superadmindelete', :protect_from_csrf => false) { "Demo" }
|
92
|
-
|
91
|
+
assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
|
93
92
|
end
|
94
93
|
|
95
94
|
it 'should not have an authenticity_token if protect_from_csrf is false on app settings' do
|
96
95
|
self.expects(:settings).returns(UnprotectedApp.new)
|
97
96
|
actual_html = form_tag('/superadmindelete') { "Demo" }
|
98
|
-
|
97
|
+
assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
|
99
98
|
end
|
100
99
|
|
101
100
|
it 'should not include protect_from_csrf as an attribute of form element' do
|
102
101
|
actual_html = form_tag('/superadmindelete', :protect_from_csrf => true){ "Demo" }
|
103
|
-
|
102
|
+
assert_has_no_tag(:form, protect_from_csrf: "true"){ actual_html }
|
104
103
|
end
|
105
104
|
|
106
105
|
it 'should display correct forms in erb' do
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
visit '/erb/form_tag'
|
107
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
108
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
109
|
+
assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
|
110
|
+
assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
|
112
111
|
end
|
113
112
|
|
114
113
|
it 'should display correct forms in haml' do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
visit '/haml/form_tag'
|
115
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
116
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
117
|
+
assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
|
118
|
+
assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
|
120
119
|
end
|
121
120
|
|
122
121
|
it 'should display correct forms in slim' do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
visit '/slim/form_tag'
|
123
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
124
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
125
|
+
assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
|
126
|
+
assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
|
128
127
|
end
|
129
128
|
end
|
130
129
|
|
131
130
|
describe 'for #field_set_tag method' do
|
132
131
|
it 'should display correct field_sets in ruby' do
|
133
132
|
actual_html = field_set_tag("Basic", :class => 'basic') { "Demo" }
|
134
|
-
|
135
|
-
|
133
|
+
assert_has_tag(:fieldset, :class => 'basic') { actual_html }
|
134
|
+
assert_has_tag('fieldset legend', :content => "Basic") { actual_html }
|
136
135
|
end
|
137
136
|
|
138
137
|
it 'should display correct field_sets in erb' do
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
138
|
+
visit '/erb/form_tag'
|
139
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
140
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
141
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
142
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
144
143
|
end
|
145
144
|
|
146
145
|
it 'should display correct field_sets in haml' do
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
visit '/haml/form_tag'
|
147
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
148
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
149
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
150
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
152
151
|
end
|
153
152
|
|
154
153
|
it 'should display correct field_sets in slim' do
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
154
|
+
visit '/slim/form_tag'
|
155
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
156
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
157
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
158
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
163
162
|
describe 'for #error_messages_for method' do
|
164
163
|
it 'should display correct error messages list in ruby' do
|
165
|
-
user = mock_model("User", :errors => { :a => "1", :b => "2" })
|
164
|
+
user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
|
166
165
|
actual_html = error_messages_for(user)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
166
|
+
assert_has_tag('div.field-errors') { actual_html }
|
167
|
+
assert_has_tag('div.field-errors h2', :content => "2 errors prohibited this User from being saved") { actual_html }
|
168
|
+
assert_has_tag('div.field-errors p', :content => "There were problems with the following fields:") { actual_html }
|
169
|
+
assert_has_tag('div.field-errors ul') { actual_html }
|
170
|
+
assert_has_tag('div.field-errors ul li', :count => 2) { actual_html }
|
172
171
|
end
|
173
172
|
|
174
173
|
it 'should display correct error messages list in erb' do
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
174
|
+
visit '/erb/form_tag'
|
175
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
176
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
177
|
+
assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
|
178
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
|
179
|
+
assert_have_selector 'form.advanced-form .field-errors ul'
|
180
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
|
181
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
|
182
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
|
183
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
|
184
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
|
186
185
|
end
|
187
186
|
|
188
187
|
it 'should display correct error messages list in haml' do
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
188
|
+
visit '/haml/form_tag'
|
189
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
190
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
191
|
+
assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
|
192
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
|
193
|
+
assert_have_selector 'form.advanced-form .field-errors ul'
|
194
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
|
195
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
|
196
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
|
197
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
|
198
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
|
200
199
|
end
|
201
200
|
|
202
201
|
it 'should display correct error messages list in slim' do
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
202
|
+
visit '/slim/form_tag'
|
203
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
204
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
205
|
+
assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
|
206
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
|
207
|
+
assert_have_selector 'form.advanced-form .field-errors ul'
|
208
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
|
209
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
|
210
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
|
211
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
|
212
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
|
214
213
|
end
|
215
214
|
end
|
216
215
|
|
217
216
|
describe 'for #error_message_on method' do
|
218
217
|
it 'should display correct error message on specified model name in ruby' do
|
219
|
-
@user = mock_model("User", :errors => { :a => "1", :b => "2" })
|
218
|
+
@user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
|
220
219
|
actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
|
221
|
-
|
220
|
+
assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
|
222
221
|
end
|
223
222
|
|
224
223
|
it 'should display correct error message on specified object in ruby' do
|
225
|
-
@bob = mock_model("User", :errors => { :a => "1", :b => "2" })
|
224
|
+
@bob = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
|
226
225
|
actual_html = error_message_on(@bob, :a, :prepend => "foo", :append => "bar")
|
227
|
-
|
226
|
+
assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
|
228
227
|
end
|
229
228
|
|
230
229
|
it 'should display no message when error is not present' do
|
231
|
-
@user = mock_model("User", :errors => { :a => "1", :b => "2" })
|
230
|
+
@user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
|
232
231
|
actual_html = error_message_on(:user, :fake, :prepend => "foo", :append => "bar")
|
233
|
-
|
232
|
+
assert actual_html.blank?
|
234
233
|
end
|
235
234
|
|
236
235
|
it 'should display no message when error is not present in an Array' do
|
237
|
-
@user = mock_model("User", :errors => { :a => [], :b => "2" })
|
236
|
+
@user = mock_model("User", :errors => { :a => [], :b => "2" }, :blank? => false)
|
238
237
|
actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
|
239
|
-
|
238
|
+
assert actual_html.blank?
|
240
239
|
end
|
241
240
|
end
|
242
241
|
|
243
242
|
describe 'for #label_tag method' do
|
244
243
|
it 'should display label tag in ruby' do
|
245
244
|
actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
|
246
|
-
|
245
|
+
assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname") { actual_html }
|
247
246
|
end
|
248
247
|
|
249
248
|
it 'should display label tag in ruby with required' do
|
250
249
|
actual_html = label_tag(:username, :caption => "Nickname", :required => true)
|
251
|
-
|
252
|
-
|
250
|
+
assert_has_tag(:label, :for => 'username', :content => 'Nickname') { actual_html }
|
251
|
+
assert_has_tag('label[for=username] span.required', :content => "*") { actual_html }
|
253
252
|
end
|
254
253
|
|
255
254
|
it 'should display label tag in ruby with a block' do
|
256
255
|
actual_html = label_tag(:admin, :class => 'long-label') { input_tag :checkbox }
|
257
|
-
|
258
|
-
|
256
|
+
assert_has_tag(:label, :for => 'admin', :class => 'long-label', :content => "Admin") { actual_html }
|
257
|
+
assert_has_tag('label input[type=checkbox]') { actual_html }
|
259
258
|
end
|
260
259
|
|
261
260
|
it 'should display label tag in erb for simple form' do
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
261
|
+
visit '/erb/form_tag'
|
262
|
+
assert_have_selector 'form.simple-form label', :count => 9
|
263
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
264
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
265
|
+
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
267
266
|
end
|
268
267
|
|
269
268
|
it 'should display label tag in erb for advanced form' do
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
269
|
+
visit '/erb/form_tag'
|
270
|
+
assert_have_selector 'form.advanced-form label', :count => 11
|
271
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
272
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
273
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
274
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
275
|
+
assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
|
277
276
|
end
|
278
277
|
|
279
278
|
it 'should display label tag in haml for simple form' do
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
279
|
+
visit '/haml/form_tag'
|
280
|
+
assert_have_selector 'form.simple-form label', :count => 9
|
281
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
282
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
283
|
+
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
285
284
|
end
|
286
285
|
|
287
286
|
it 'should display label tag in haml for advanced form' do
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
287
|
+
visit '/haml/form_tag'
|
288
|
+
assert_have_selector 'form.advanced-form label', :count => 11
|
289
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
290
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
291
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
292
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
293
|
+
assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
|
295
294
|
end
|
296
295
|
|
297
296
|
it 'should display label tag in slim for simple form' do
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
297
|
+
visit '/slim/form_tag'
|
298
|
+
assert_have_selector 'form.simple-form label', :count => 9
|
299
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
300
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
301
|
+
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
303
302
|
end
|
304
303
|
|
305
304
|
it 'should display label tag in slim for advanced form' do
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
305
|
+
visit '/slim/form_tag'
|
306
|
+
assert_have_selector 'form.advanced-form label', :count => 11
|
307
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
308
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
309
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
310
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
311
|
+
assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
|
313
312
|
end
|
314
313
|
end
|
315
314
|
|
316
315
|
describe 'for #hidden_field_tag method' do
|
317
316
|
it 'should display hidden field in ruby' do
|
318
317
|
actual_html = hidden_field_tag(:session_key, :id => 'session_id', :value => '56768')
|
319
|
-
|
318
|
+
assert_has_tag(:input, :type => 'hidden', :id => "session_id", :name => 'session_key', :value => '56768') { actual_html }
|
320
319
|
end
|
321
320
|
|
322
321
|
it 'should display hidden field in erb' do
|
323
|
-
|
324
|
-
|
325
|
-
|
322
|
+
visit '/erb/form_tag'
|
323
|
+
assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
324
|
+
assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
326
325
|
end
|
327
326
|
|
328
327
|
it 'should display hidden field in haml' do
|
329
|
-
|
330
|
-
|
331
|
-
|
328
|
+
visit '/haml/form_tag'
|
329
|
+
assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
330
|
+
assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
332
331
|
end
|
333
332
|
|
334
333
|
it 'should display hidden field in slim' do
|
335
|
-
|
336
|
-
|
337
|
-
|
334
|
+
visit '/slim/form_tag'
|
335
|
+
assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
336
|
+
assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
338
337
|
end
|
339
338
|
end
|
340
339
|
|
341
340
|
describe 'for #text_field_tag method' do
|
342
341
|
it 'should display text field in ruby' do
|
343
342
|
actual_html = text_field_tag(:username, :class => 'long')
|
344
|
-
|
343
|
+
assert_has_tag(:input, :type => 'text', :class => "long", :name => 'username') { actual_html }
|
345
344
|
end
|
346
345
|
|
347
346
|
it 'should display text field in erb' do
|
348
|
-
|
349
|
-
|
350
|
-
|
347
|
+
visit '/erb/form_tag'
|
348
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
349
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
351
350
|
end
|
352
351
|
|
353
352
|
it 'should display text field in haml' do
|
354
|
-
|
355
|
-
|
356
|
-
|
353
|
+
visit '/haml/form_tag'
|
354
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
355
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
357
356
|
end
|
358
357
|
|
359
358
|
it 'should display text field in slim' do
|
360
|
-
|
361
|
-
|
362
|
-
|
359
|
+
visit '/slim/form_tag'
|
360
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
361
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
363
362
|
end
|
364
363
|
end
|
365
364
|
|
366
365
|
describe 'for #number_field_tag method' do
|
367
366
|
it 'should display number field in ruby' do
|
368
367
|
actual_html = number_field_tag(:age, :class => 'numeric')
|
369
|
-
|
368
|
+
assert_has_tag(:input, :type => 'number', :class => 'numeric', :name => 'age') { actual_html }
|
370
369
|
end
|
371
370
|
|
372
371
|
it 'should display number field in erb' do
|
373
|
-
|
374
|
-
|
375
|
-
|
372
|
+
visit '/erb/form_tag'
|
373
|
+
assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
|
374
|
+
assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
|
376
375
|
end
|
377
376
|
|
378
377
|
it 'should display number field in haml' do
|
379
|
-
|
380
|
-
|
381
|
-
|
378
|
+
visit '/haml/form_tag'
|
379
|
+
assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
|
380
|
+
assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
|
382
381
|
end
|
383
382
|
|
384
383
|
it 'should display number field in slim' do
|
385
|
-
|
386
|
-
|
387
|
-
|
384
|
+
visit '/slim/form_tag'
|
385
|
+
assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
|
386
|
+
assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
|
388
387
|
end
|
389
388
|
end
|
390
389
|
|
391
390
|
describe 'for #telephone_field_tag method' do
|
392
391
|
it 'should display number field in ruby' do
|
393
392
|
actual_html = telephone_field_tag(:telephone, :class => 'numeric')
|
394
|
-
|
393
|
+
assert_has_tag(:input, :type => 'tel', :class => 'numeric', :name => 'telephone') { actual_html }
|
395
394
|
end
|
396
395
|
|
397
396
|
it 'should display telephone field in erb' do
|
398
|
-
|
399
|
-
|
400
|
-
|
397
|
+
visit '/erb/form_tag'
|
398
|
+
assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
|
399
|
+
assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
|
401
400
|
end
|
402
401
|
|
403
402
|
it 'should display telephone field in haml' do
|
404
|
-
|
405
|
-
|
406
|
-
|
403
|
+
visit '/haml/form_tag'
|
404
|
+
assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
|
405
|
+
assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
|
407
406
|
end
|
408
407
|
|
409
408
|
it 'should display telephone field in slim' do
|
410
|
-
|
411
|
-
|
412
|
-
|
409
|
+
visit '/slim/form_tag'
|
410
|
+
assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
|
411
|
+
assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
|
413
412
|
end
|
414
413
|
end
|
415
414
|
|
416
415
|
describe 'for #search_field_tag method' do
|
417
416
|
it 'should display search field in ruby' do
|
418
417
|
actual_html = search_field_tag(:search, :class => 'string')
|
419
|
-
|
418
|
+
assert_has_tag(:input, :type => 'search', :class => 'string', :name => 'search') { actual_html }
|
420
419
|
end
|
421
420
|
|
422
421
|
it 'should display search field in erb' do
|
423
|
-
|
424
|
-
|
425
|
-
|
422
|
+
visit '/erb/form_tag'
|
423
|
+
assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
|
424
|
+
assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
|
426
425
|
end
|
427
426
|
|
428
427
|
it 'should display search field in haml' do
|
429
|
-
|
430
|
-
|
431
|
-
|
428
|
+
visit '/haml/form_tag'
|
429
|
+
assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
|
430
|
+
assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
|
432
431
|
end
|
433
432
|
|
434
433
|
it 'should display search field in slim' do
|
435
|
-
|
436
|
-
|
437
|
-
|
434
|
+
visit '/slim/form_tag'
|
435
|
+
assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
|
436
|
+
assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
|
438
437
|
end
|
439
438
|
end
|
440
439
|
|
441
440
|
describe 'for #email_field_tag method' do
|
442
441
|
it 'should display email field in ruby' do
|
443
442
|
actual_html = email_field_tag(:email, :class => 'string')
|
444
|
-
|
443
|
+
assert_has_tag(:input, :type => 'email', :class => 'string', :name => 'email') { actual_html }
|
445
444
|
end
|
446
445
|
|
447
446
|
it 'should display email field in erb' do
|
448
|
-
|
449
|
-
|
450
|
-
|
447
|
+
visit '/erb/form_tag'
|
448
|
+
assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
|
449
|
+
assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
|
451
450
|
end
|
452
451
|
|
453
452
|
it 'should display email field in haml' do
|
454
|
-
|
455
|
-
|
456
|
-
|
453
|
+
visit '/haml/form_tag'
|
454
|
+
assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
|
455
|
+
assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
|
457
456
|
end
|
458
457
|
|
459
458
|
it 'should display email field in slim' do
|
460
|
-
|
461
|
-
|
462
|
-
|
459
|
+
visit '/slim/form_tag'
|
460
|
+
assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
|
461
|
+
assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
|
463
462
|
end
|
464
463
|
end
|
465
464
|
|
466
465
|
describe 'for #url_field_tag method' do
|
467
466
|
it 'should display url field in ruby' do
|
468
467
|
actual_html = url_field_tag(:webpage, :class => 'string')
|
469
|
-
|
468
|
+
assert_has_tag(:input, :type => 'url', :class => 'string', :name => 'webpage') { actual_html }
|
470
469
|
end
|
471
470
|
|
472
471
|
it 'should display url field in erb' do
|
473
|
-
|
474
|
-
|
475
|
-
|
472
|
+
visit '/erb/form_tag'
|
473
|
+
assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
|
474
|
+
assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
|
476
475
|
end
|
477
476
|
|
478
477
|
it 'should display url field in haml' do
|
479
|
-
|
480
|
-
|
481
|
-
|
478
|
+
visit '/haml/form_tag'
|
479
|
+
assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
|
480
|
+
assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
|
482
481
|
end
|
483
482
|
|
484
483
|
it 'should display url field in slim' do
|
485
|
-
|
486
|
-
|
487
|
-
|
484
|
+
visit '/slim/form_tag'
|
485
|
+
assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
|
486
|
+
assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
|
488
487
|
end
|
489
488
|
end
|
490
489
|
|
491
490
|
describe 'for #text_area_tag method' do
|
492
491
|
it 'should display text area in ruby' do
|
493
492
|
actual_html = text_area_tag(:about, :class => 'long')
|
494
|
-
|
493
|
+
assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
|
495
494
|
end
|
496
495
|
|
497
496
|
it 'should display text area in ruby with specified content' do
|
498
497
|
actual_html = text_area_tag(:about, :value => "a test", :rows => 5, :cols => 6)
|
499
|
-
|
498
|
+
assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
|
500
499
|
end
|
501
500
|
|
502
501
|
it 'should insert newline to before of content' do
|
503
502
|
actual_html = text_area_tag(:about, :value => "\na test&".html_safe)
|
504
|
-
|
503
|
+
assert_has_tag(:textarea, :content => "\na test&".html_safe, :name => 'about') { actual_html }
|
505
504
|
assert_match(%r{<textarea[^>]*>\n\na test&</textarea>}, actual_html)
|
506
505
|
end
|
507
506
|
|
508
507
|
it 'should display text area in erb' do
|
509
|
-
|
510
|
-
|
508
|
+
visit '/erb/form_tag'
|
509
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
511
510
|
end
|
512
511
|
|
513
512
|
it 'should display text area in haml' do
|
514
|
-
|
515
|
-
|
513
|
+
visit '/haml/form_tag'
|
514
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
516
515
|
end
|
517
516
|
|
518
517
|
it 'should display text area in slim' do
|
519
|
-
|
520
|
-
|
518
|
+
visit '/slim/form_tag'
|
519
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
521
520
|
end
|
522
521
|
end
|
523
522
|
|
524
523
|
describe 'for #password_field_tag method' do
|
525
524
|
it 'should display password field in ruby' do
|
526
525
|
actual_html = password_field_tag(:password, :class => 'long')
|
527
|
-
|
526
|
+
assert_has_tag(:input, :type => 'password', :class => "long", :name => 'password') { actual_html }
|
528
527
|
end
|
529
528
|
|
530
529
|
it 'should display password field in erb' do
|
531
|
-
|
532
|
-
|
533
|
-
|
530
|
+
visit '/erb/form_tag'
|
531
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
532
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
534
533
|
end
|
535
534
|
|
536
535
|
it 'should display password field in haml' do
|
537
|
-
|
538
|
-
|
539
|
-
|
536
|
+
visit '/haml/form_tag'
|
537
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
538
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
540
539
|
end
|
541
540
|
|
542
541
|
it 'should display password field in slim' do
|
543
|
-
|
544
|
-
|
545
|
-
|
542
|
+
visit '/slim/form_tag'
|
543
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
544
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
546
545
|
end
|
547
546
|
end
|
548
547
|
|
549
548
|
describe 'for #file_field_tag method' do
|
550
549
|
it 'should display file field in ruby' do
|
551
550
|
actual_html = file_field_tag(:photo, :class => 'photo')
|
552
|
-
|
551
|
+
assert_has_tag(:input, :type => 'file', :class => "photo", :name => 'photo') { actual_html }
|
553
552
|
end
|
554
553
|
|
555
554
|
it 'should have an array name with multiple option' do
|
556
555
|
actual_html = file_field_tag(:photos, :multiple => true)
|
557
|
-
|
556
|
+
assert_has_tag(:input, :name => 'photos[]') { actual_html }
|
558
557
|
end
|
559
558
|
|
560
559
|
it 'should display file field in erb' do
|
561
|
-
|
562
|
-
|
560
|
+
visit '/erb/form_tag'
|
561
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
563
562
|
end
|
564
563
|
|
565
564
|
it 'should display file field in haml' do
|
566
|
-
|
567
|
-
|
565
|
+
visit '/haml/form_tag'
|
566
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
568
567
|
end
|
569
568
|
|
570
569
|
it 'should display file field in slim' do
|
571
|
-
|
572
|
-
|
570
|
+
visit '/slim/form_tag'
|
571
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
573
572
|
end
|
574
573
|
end
|
575
574
|
|
576
575
|
describe "for #check_box_tag method" do
|
577
576
|
it 'should display check_box tag in ruby' do
|
578
577
|
actual_html = check_box_tag("clear_session")
|
579
|
-
|
580
|
-
|
578
|
+
assert_has_tag(:input, :type => 'checkbox', :value => '1', :name => 'clear_session') { actual_html }
|
579
|
+
assert_has_no_tag(:input, :type => 'hidden') { actual_html }
|
581
580
|
end
|
582
581
|
|
583
582
|
it 'should display check_box tag in ruby with extended attributes' do
|
584
583
|
actual_html = check_box_tag("clear_session", :disabled => true, :checked => true)
|
585
|
-
|
584
|
+
assert_has_tag(:input, :type => 'checkbox', :disabled => 'disabled', :checked => 'checked') { actual_html }
|
586
585
|
end
|
587
586
|
|
588
587
|
it 'should display check_box tag in erb' do
|
589
|
-
|
590
|
-
|
591
|
-
|
588
|
+
visit '/erb/form_tag'
|
589
|
+
assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
|
590
|
+
assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
|
592
591
|
end
|
593
592
|
|
594
593
|
it 'should display check_box tag in haml' do
|
595
|
-
|
596
|
-
|
597
|
-
|
594
|
+
visit '/haml/form_tag'
|
595
|
+
assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
|
596
|
+
assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
|
598
597
|
end
|
599
598
|
|
600
599
|
it 'should display check_box tag in slim' do
|
601
|
-
|
602
|
-
|
603
|
-
|
600
|
+
visit '/slim/form_tag'
|
601
|
+
assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
|
602
|
+
assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
|
604
603
|
end
|
605
604
|
end
|
606
605
|
|
607
606
|
describe "for #radio_button_tag method" do
|
608
607
|
it 'should display radio_button tag in ruby' do
|
609
608
|
actual_html = radio_button_tag("gender", :value => 'male')
|
610
|
-
|
609
|
+
assert_has_tag(:input, :type => 'radio', :value => 'male', :name => 'gender') { actual_html }
|
611
610
|
end
|
612
611
|
|
613
612
|
it 'should display radio_button tag in ruby with extended attributes' do
|
614
613
|
actual_html = radio_button_tag("gender", :disabled => true, :checked => true)
|
615
|
-
|
614
|
+
assert_has_tag(:input, :type => 'radio', :disabled => 'disabled', :checked => 'checked') { actual_html }
|
616
615
|
end
|
617
616
|
|
618
617
|
it 'should display radio_button tag in erb' do
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
618
|
+
visit '/erb/form_tag'
|
619
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
|
620
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
|
621
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
|
622
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
|
624
623
|
end
|
625
624
|
|
626
625
|
it 'should display radio_button tag in haml' do
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
626
|
+
visit '/haml/form_tag'
|
627
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
|
628
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
|
629
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
|
630
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
|
632
631
|
end
|
633
632
|
|
634
633
|
it 'should display radio_button tag in slim' do
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
634
|
+
visit '/slim/form_tag'
|
635
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
|
636
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
|
637
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
|
638
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
|
640
639
|
end
|
641
640
|
end
|
642
641
|
|
643
642
|
describe "for #select_tag method" do
|
644
643
|
it 'should display select tag in ruby' do
|
645
644
|
actual_html = select_tag(:favorite_color, :options => ['green', 'blue', 'black'], :include_blank => true)
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
645
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
646
|
+
assert_has_tag('select option:first-child', :content => '') { actual_html }
|
647
|
+
assert_has_tag('select option', :content => 'green', :value => 'green') { actual_html }
|
648
|
+
assert_has_tag('select option', :content => 'blue', :value => 'blue') { actual_html }
|
649
|
+
assert_has_tag('select option', :content => 'black', :value => 'black') { actual_html }
|
651
650
|
end
|
652
651
|
|
653
652
|
it 'should display select tag in ruby with extended attributes' do
|
654
653
|
actual_html = select_tag(:favorite_color, :disabled => true, :options => ['only', 'option'])
|
655
|
-
|
654
|
+
assert_has_tag(:select, :disabled => 'disabled') { actual_html }
|
656
655
|
end
|
657
656
|
|
658
657
|
it 'should take a range as a collection for options' do
|
659
658
|
actual_html = select_tag(:favorite_color, :options => (1..3))
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
659
|
+
assert_has_tag(:select) { actual_html }
|
660
|
+
assert_has_tag('select option', :content => '1', :value => '1') { actual_html }
|
661
|
+
assert_has_tag('select option', :content => '2', :value => '2') { actual_html }
|
662
|
+
assert_has_tag('select option', :content => '3', :value => '3') { actual_html }
|
664
663
|
end
|
665
664
|
|
666
665
|
it 'should include blank for grouped options' do
|
667
666
|
opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
|
668
667
|
actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => true )
|
669
|
-
|
668
|
+
assert_has_tag('select option:first-child', :value => "", :content => "") { actual_html }
|
670
669
|
end
|
671
670
|
|
672
671
|
it 'should include blank as caption' do
|
673
672
|
opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
|
674
673
|
actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => 'Choose your destiny' )
|
675
|
-
|
676
|
-
|
674
|
+
assert_has_tag('select option:first-child', :value => "", :content => "Choose your destiny") { actual_html }
|
675
|
+
assert_has_no_tag('select[include_blank]') { actual_html }
|
677
676
|
end
|
678
677
|
|
679
678
|
it 'should display select tag with grouped options for a nested array' do
|
@@ -682,13 +681,13 @@ describe "FormHelpers" do
|
|
682
681
|
["Enemies", ["Palpatine",['Darth Vader',3]]]
|
683
682
|
]
|
684
683
|
actual_html = select_tag( 'name', :grouped_options => opts )
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
684
|
+
assert_has_tag(:select, :name => "name") { actual_html }
|
685
|
+
assert_has_tag(:optgroup, :label => "Friends") { actual_html }
|
686
|
+
assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
|
687
|
+
assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
|
688
|
+
assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
|
689
|
+
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
|
690
|
+
assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
|
692
691
|
end
|
693
692
|
|
694
693
|
it 'should display select tag with grouped options for a nested array and accept disabled groups' do
|
@@ -697,10 +696,10 @@ describe "FormHelpers" do
|
|
697
696
|
["Enemies", ["Palpatine",['Darth Vader',3]], {:disabled => true}]
|
698
697
|
]
|
699
698
|
actual_html = select_tag( 'name', :grouped_options => opts )
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
699
|
+
assert_has_tag(:select, :name => "name") { actual_html }
|
700
|
+
assert_has_tag(:option, :disabled => 'disabled', :count => 0) { actual_html }
|
701
|
+
assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
|
702
|
+
assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
|
704
703
|
end
|
705
704
|
|
706
705
|
it 'should display select tag with grouped options for a nested array and accept disabled groups and/or with disabled options' do
|
@@ -709,12 +708,12 @@ describe "FormHelpers" do
|
|
709
708
|
["Enemies", [["Palpatine", "Palpatine", {:disabled => true}],['Darth Vader',3]], {:disabled => true}]
|
710
709
|
]
|
711
710
|
actual_html = select_tag( 'name', :grouped_options => opts )
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
711
|
+
assert_has_tag(:select, :name => "name") { actual_html }
|
712
|
+
assert_has_tag(:option, :disabled => 'disabled', :count => 2) { actual_html }
|
713
|
+
assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
|
714
|
+
assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
|
715
|
+
assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
|
716
|
+
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html }
|
718
717
|
end
|
719
718
|
|
720
719
|
it 'should display select tag with grouped options for a hash' do
|
@@ -723,13 +722,13 @@ describe "FormHelpers" do
|
|
723
722
|
"Enemies" => ["Palpatine",['Darth Vader',3]]
|
724
723
|
}
|
725
724
|
actual_html = select_tag( 'name', :grouped_options => opts )
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
725
|
+
assert_has_tag(:select, :name => "name") { actual_html }
|
726
|
+
assert_has_tag(:optgroup, :label => "Friends") { actual_html }
|
727
|
+
assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
|
728
|
+
assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
|
729
|
+
assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
|
730
|
+
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
|
731
|
+
assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
|
733
732
|
end
|
734
733
|
|
735
734
|
it 'should display select tag with grouped options for a hash and accept disabled groups and/or with disabled options' do
|
@@ -738,12 +737,12 @@ describe "FormHelpers" do
|
|
738
737
|
"Enemies" => [["Palpatine","Palpatine",{:disabled => true}],["Darth Vader",3], {:disabled => true}]
|
739
738
|
}
|
740
739
|
actual_html = select_tag( 'name', :grouped_options => opts )
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
740
|
+
assert_has_tag(:select, :name => "name") { actual_html }
|
741
|
+
assert_has_tag(:option, :disabled => 'disabled', :count => 2) { actual_html }
|
742
|
+
assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
|
743
|
+
assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
|
744
|
+
assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
|
745
|
+
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html }
|
747
746
|
end
|
748
747
|
|
749
748
|
it 'should display select tag with grouped options for a rails-style attribute hash' do
|
@@ -752,185 +751,171 @@ describe "FormHelpers" do
|
|
752
751
|
"Enemies" => [["Palpatine","Palpatine",{:scary=>'yes',:old=>'yes'}],["Darth Vader",3,{:disabled=>true}]]
|
753
752
|
}
|
754
753
|
actual_html = select_tag( 'name', :grouped_options => opts, :disabled_options => [2], :selected => ['Yoda'] )
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
754
|
+
assert_has_tag(:optgroup, :label => "Friends", :lame => 'yes') { actual_html }
|
755
|
+
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :scary => 'yes', :old => 'yes') { actual_html }
|
756
|
+
assert_has_tag(:option, :content => "Darth Vader", :disabled => 'disabled') { actual_html }
|
757
|
+
assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
|
758
|
+
assert_has_tag(:option, :content => "Yoda", :selected => 'selected') { actual_html }
|
760
759
|
end
|
761
760
|
|
762
761
|
it 'should display select tag in ruby with multiple attribute' do
|
763
762
|
actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option'])
|
764
|
-
|
763
|
+
assert_has_tag(:select, :multiple => 'multiple', :name => 'favorite_color[]') { actual_html }
|
765
764
|
end
|
766
765
|
|
767
766
|
it 'should display options with values and single selected' do
|
768
767
|
options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
769
768
|
actual_html = select_tag(:favorite_color, :options => options, :selected => 'green1')
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
end
|
776
|
-
|
777
|
-
it 'should display selected options first based on values not content' do
|
778
|
-
options = [['First', 'one'], ['one', 'two'], ['three', 'three']]
|
779
|
-
actual_html = select_tag(:number, :options => options, :selected => 'one')
|
780
|
-
assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
|
781
|
-
assert_html_has_tag(actual_html, 'select option', :content => 'First', :value => 'one', :selected => 'selected')
|
782
|
-
end
|
783
|
-
|
784
|
-
it 'should display selected options falling back to checking content' do
|
785
|
-
options = [['one', nil, :value => nil], ['two', nil, :value => nil], ['three', 'three']]
|
786
|
-
actual_html = select_tag(:number, :options => options, :selected => 'one')
|
787
|
-
assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
|
788
|
-
assert_html_has_tag(actual_html, 'select option', :content => 'one', :selected => 'selected')
|
769
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
770
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
771
|
+
assert_has_tag('select option', :content => 'Green', :value => 'green1', :selected => 'selected') { actual_html }
|
772
|
+
assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
|
773
|
+
assert_has_tag('select option', :content => 'Black', :value => 'black1') { actual_html }
|
789
774
|
end
|
790
775
|
|
791
776
|
it 'should display options with values and accept disabled options' do
|
792
777
|
options = [['Green', 'green1', {:disabled => true}], ['Blue', 'blue1'], ['Black', "black1"]]
|
793
778
|
actual_html = select_tag(:favorite_color, :options => options)
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
779
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
780
|
+
assert_has_tag('select option', :disabled => 'disabled', :count => 1) { actual_html }
|
781
|
+
assert_has_tag('select option', :content => 'Green', :value => 'green1', :disabled => 'disabled') { actual_html }
|
782
|
+
assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
|
783
|
+
assert_has_tag('select option', :content => 'Black', :value => 'black1') { actual_html }
|
799
784
|
end
|
800
785
|
|
801
786
|
it 'should display option with values and multiple selected' do
|
802
787
|
options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
803
|
-
actual_html = select_tag(:favorite_color, :options => options, :selected => ['green1', '
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
788
|
+
actual_html = select_tag(:favorite_color, :options => options, :selected => ['green1', 'Black'])
|
789
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
790
|
+
assert_has_tag('select option', :selected => 'selected', :count => 2) { actual_html }
|
791
|
+
assert_has_tag('select option', :content => 'Green', :value => 'green1', :selected => 'selected') { actual_html }
|
792
|
+
assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
|
793
|
+
assert_has_tag('select option', :content => 'Black', :value => 'black1', :selected => 'selected') { actual_html }
|
809
794
|
end
|
810
795
|
|
811
796
|
it 'should not misselect options with default value' do
|
812
797
|
options = ['Green', 'Blue']
|
813
798
|
actual_html = select_tag(:favorite_color, :options => options, :selected => ['Green', ''])
|
814
|
-
|
815
|
-
|
799
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
800
|
+
assert_has_tag('select option', :content => 'Green', :value => 'Green', :selected => 'selected') { actual_html }
|
816
801
|
end
|
817
802
|
|
818
803
|
it 'should display options selected only for exact match' do
|
819
804
|
options = [['One', '1'], ['1', '10'], ['Two', "-1"]]
|
820
805
|
actual_html = select_tag(:range, :options => options, :selected => '-1')
|
821
|
-
|
822
|
-
|
823
|
-
|
806
|
+
assert_has_tag(:select, :name => 'range') { actual_html }
|
807
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
808
|
+
assert_has_tag('select option', :content => 'Two', :value => '-1', :selected => 'selected') { actual_html }
|
824
809
|
end
|
825
810
|
|
826
811
|
it 'should display select tag in erb' do
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
812
|
+
visit '/erb/form_tag'
|
813
|
+
assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
|
814
|
+
assert_have_selector('select option', :content => 'green', :value => 'green')
|
815
|
+
assert_have_selector('select option', :content => 'orange', :value => 'orange')
|
816
|
+
assert_have_selector('select option', :content => 'purple', :value => 'purple')
|
817
|
+
assert_have_selector('form.advanced-form select', :name => 'fav_color')
|
818
|
+
assert_have_selector('select option', :content => 'green', :value => '1')
|
819
|
+
assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
|
820
|
+
assert_have_selector('select option', :content => 'purple', :value => '3')
|
821
|
+
assert_have_selector('select optgroup', :label => 'foo')
|
822
|
+
assert_have_selector('select optgroup', :label => 'bar')
|
823
|
+
assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
|
824
|
+
assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
|
825
|
+
assert_have_selector('select optgroup', :label => 'Friends')
|
826
|
+
assert_have_selector('select optgroup', :label => 'Enemies')
|
827
|
+
assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
|
828
|
+
assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
|
829
|
+
assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
|
830
|
+
assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
|
846
831
|
end
|
847
832
|
|
848
833
|
it 'should display select tag in haml' do
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
834
|
+
visit '/haml/form_tag'
|
835
|
+
assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
|
836
|
+
assert_have_selector('select option', :content => 'green', :value => 'green')
|
837
|
+
assert_have_selector('select option', :content => 'orange', :value => 'orange')
|
838
|
+
assert_have_selector('select option', :content => 'purple', :value => 'purple')
|
839
|
+
assert_have_selector('form.advanced-form select', :name => 'fav_color')
|
840
|
+
assert_have_selector('select option', :content => 'green', :value => '1')
|
841
|
+
assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
|
842
|
+
assert_have_selector('select option', :content => 'purple', :value => '3')
|
843
|
+
assert_have_selector('select optgroup', :label => 'foo')
|
844
|
+
assert_have_selector('select optgroup', :label => 'bar')
|
845
|
+
assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
|
846
|
+
assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
|
847
|
+
assert_have_selector('select optgroup', :label => 'Friends')
|
848
|
+
assert_have_selector('select optgroup', :label => 'Enemies')
|
849
|
+
assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
|
850
|
+
assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
|
851
|
+
assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
|
852
|
+
assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
|
868
853
|
end
|
869
854
|
|
870
855
|
it 'should display select tag in slim' do
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
856
|
+
visit '/slim/form_tag'
|
857
|
+
assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
|
858
|
+
assert_have_selector('select option', :content => 'green', :value => 'green')
|
859
|
+
assert_have_selector('select option', :content => 'orange', :value => 'orange')
|
860
|
+
assert_have_selector('select option', :content => 'purple', :value => 'purple')
|
861
|
+
assert_have_selector('form.advanced-form select', :name => 'fav_color')
|
862
|
+
assert_have_selector('select option', :content => 'green', :value => '1')
|
863
|
+
assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
|
864
|
+
assert_have_selector('select option', :content => 'purple', :value => '3')
|
865
|
+
assert_have_selector('select optgroup', :label => 'foo')
|
866
|
+
assert_have_selector('select optgroup', :label => 'bar')
|
867
|
+
assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
|
868
|
+
assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
|
869
|
+
assert_have_selector('select optgroup', :label => 'Friends')
|
870
|
+
assert_have_selector('select optgroup', :label => 'Enemies')
|
871
|
+
assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
|
872
|
+
assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
|
873
|
+
assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
|
874
|
+
assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
|
890
875
|
end
|
891
876
|
end
|
892
877
|
|
893
878
|
describe 'for #submit_tag method' do
|
894
879
|
it 'should display submit tag in ruby' do
|
895
880
|
actual_html = submit_tag("Update", :class => 'success')
|
896
|
-
|
881
|
+
assert_has_tag(:input, :type => 'submit', :class => "success", :value => 'Update') { actual_html }
|
897
882
|
end
|
898
883
|
|
899
884
|
it 'should display submit tag in erb' do
|
900
|
-
|
901
|
-
|
902
|
-
|
885
|
+
visit '/erb/form_tag'
|
886
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
887
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
903
888
|
end
|
904
889
|
|
905
890
|
it 'should display submit tag in haml' do
|
906
|
-
|
907
|
-
|
908
|
-
|
891
|
+
visit '/haml/form_tag'
|
892
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
893
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
909
894
|
end
|
910
895
|
|
911
896
|
it 'should display submit tag in slim' do
|
912
|
-
|
913
|
-
|
914
|
-
|
897
|
+
visit '/slim/form_tag'
|
898
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
899
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
915
900
|
end
|
916
901
|
|
917
902
|
describe 'for omitted args' do
|
918
903
|
it 'should display submit tag with default caption' do
|
919
904
|
actual_html = submit_tag()
|
920
|
-
|
905
|
+
assert_has_tag(:input, :type => 'submit', :value => 'Submit') { actual_html }
|
921
906
|
end
|
922
907
|
end
|
923
908
|
|
924
909
|
describe 'for omitted caption arg' do
|
925
910
|
it 'should display submit tag with default caption' do
|
926
911
|
actual_html = submit_tag(:class => 'success')
|
927
|
-
|
912
|
+
assert_has_tag(:input, :type => 'submit', :class => 'success', :value => 'Submit') { actual_html }
|
928
913
|
end
|
929
914
|
|
930
915
|
it 'should display submit tag without caption value when nil' do
|
931
916
|
actual_html = submit_tag(nil, :class => 'success')
|
932
|
-
|
933
|
-
|
917
|
+
assert_has_tag(:input, :type => 'submit', :class => 'success') { actual_html }
|
918
|
+
assert_has_no_tag(:input, :type => 'submit', :class => 'success', :value => 'Submit') { actual_html }
|
934
919
|
end
|
935
920
|
end
|
936
921
|
end
|
@@ -938,22 +923,22 @@ describe "FormHelpers" do
|
|
938
923
|
describe 'for #button_tag method' do
|
939
924
|
it 'should display submit tag in ruby' do
|
940
925
|
actual_html = button_tag("Cancel", :class => 'clear')
|
941
|
-
|
926
|
+
assert_has_tag(:input, :type => 'button', :class => "clear", :value => 'Cancel') { actual_html }
|
942
927
|
end
|
943
928
|
|
944
929
|
it 'should display submit tag in erb' do
|
945
|
-
|
946
|
-
|
930
|
+
visit '/erb/form_tag'
|
931
|
+
assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
|
947
932
|
end
|
948
933
|
|
949
934
|
it 'should display submit tag in haml' do
|
950
|
-
|
951
|
-
|
935
|
+
visit '/haml/form_tag'
|
936
|
+
assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
|
952
937
|
end
|
953
938
|
|
954
939
|
it 'should display submit tag in slim' do
|
955
|
-
|
956
|
-
|
940
|
+
visit '/slim/form_tag'
|
941
|
+
assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
|
957
942
|
end
|
958
943
|
end
|
959
944
|
|
@@ -964,406 +949,108 @@ describe "FormHelpers" do
|
|
964
949
|
|
965
950
|
it 'should display image submit tag in ruby with relative path' do
|
966
951
|
actual_html = image_submit_tag('buttons/ok.png', :class => 'success')
|
967
|
-
|
952
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
|
968
953
|
end
|
969
954
|
|
970
955
|
it 'should display image submit tag in ruby with absolute path' do
|
971
956
|
actual_html = image_submit_tag('/system/ok.png', :class => 'success')
|
972
|
-
|
957
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => "/system/ok.png") { actual_html }
|
973
958
|
end
|
974
959
|
|
975
960
|
it 'should display image submit tag in erb' do
|
976
|
-
|
977
|
-
|
961
|
+
visit '/erb/form_tag'
|
962
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
|
978
963
|
end
|
979
964
|
|
980
965
|
it 'should display image submit tag in haml' do
|
981
|
-
|
982
|
-
|
966
|
+
visit '/haml/form_tag'
|
967
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
|
983
968
|
end
|
984
969
|
|
985
970
|
it 'should display image submit tag in slim' do
|
986
|
-
|
987
|
-
|
971
|
+
visit '/slim/form_tag'
|
972
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
|
988
973
|
end
|
989
974
|
end
|
990
975
|
|
991
976
|
describe 'for #button_to method' do
|
992
977
|
it 'should have a form and set the method properly' do
|
993
978
|
actual_html = button_to('Delete', '/users/1', :method => :delete)
|
994
|
-
|
995
|
-
|
996
|
-
|
979
|
+
assert_has_tag('form', :action => '/users/1') { actual_html }
|
980
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
|
981
|
+
assert_has_tag('form input', :type => 'hidden', :name => "authenticity_token") { actual_html }
|
997
982
|
end
|
998
983
|
|
999
984
|
it 'should add a submit button by default if no content is specified' do
|
1000
985
|
actual_html = button_to('My Delete Button', '/users/1', :method => :delete)
|
1001
|
-
|
986
|
+
assert_has_tag('form input', :type => 'submit', :value => 'My Delete Button') { actual_html }
|
1002
987
|
end
|
1003
988
|
|
1004
989
|
it 'should set specific content inside the form if a block was sent' do
|
1005
990
|
actual_html = button_to('My Delete Button', '/users/1', :method => :delete) do
|
1006
991
|
content_tag :button, "My button's content", :type => :submit, :title => "My button"
|
1007
992
|
end
|
1008
|
-
|
993
|
+
assert_has_tag('form button', :type => 'submit', :content => "My button's content", :title => "My button") { actual_html }
|
1009
994
|
end
|
1010
995
|
|
1011
996
|
it 'should pass options on submit button when submit_options are given' do
|
1012
997
|
actual_html = button_to("Fancy button", '/users/1', :submit_options => { :class => :fancy })
|
1013
|
-
|
1014
|
-
|
998
|
+
assert_has_tag('form input', :type => 'submit', :value => 'Fancy button', :class => 'fancy') { actual_html }
|
999
|
+
assert_has_no_tag('form', :"submit_options-class" => 'fancy'){ actual_html }
|
1015
1000
|
end
|
1016
1001
|
|
1017
1002
|
it 'should display correct button_to in erb' do
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1003
|
+
visit '/erb/button_to'
|
1004
|
+
assert_have_selector('form', :action => '/foo')
|
1005
|
+
assert_have_selector('form button label', :for => 'username', :content => 'Username: ')
|
1006
|
+
assert_have_selector('form', :action => '/bar')
|
1007
|
+
assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
|
1023
1008
|
end
|
1024
1009
|
|
1025
1010
|
it 'should display correct button_to in haml' do
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1011
|
+
visit '/haml/button_to'
|
1012
|
+
assert_have_selector('form', :action => '/foo')
|
1013
|
+
assert_have_selector('form button label', :for => 'username', :content => 'Username: ')
|
1014
|
+
assert_have_selector('form', :action => '/bar')
|
1015
|
+
assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
|
1031
1016
|
end
|
1032
1017
|
|
1033
1018
|
it 'should display correct button_to in slim' do
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1019
|
+
visit '/slim/button_to'
|
1020
|
+
assert_have_selector('form', :action => '/foo')
|
1021
|
+
assert_have_selector('form button label', :for => 'username', :content => 'Username: ')
|
1022
|
+
assert_have_selector('form', :action => '/bar')
|
1023
|
+
assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
|
1039
1024
|
end
|
1040
1025
|
end
|
1041
1026
|
|
1042
1027
|
describe 'for #range_field_tag' do
|
1043
1028
|
it 'should create an input tag with min and max options' do
|
1044
1029
|
actual_html = range_field_tag('ranger', :min => 20, :max => 50)
|
1045
|
-
|
1030
|
+
assert_has_tag('input', :type => 'range', :name => 'ranger', :min => '20', :max => '50') { actual_html }
|
1046
1031
|
end
|
1047
1032
|
|
1048
1033
|
it 'should create an input tag with range' do
|
1049
1034
|
actual_html = range_field_tag('ranger', :range => 1..20)
|
1050
|
-
|
1035
|
+
assert_has_tag('input', :min => '1', :max => '20') { actual_html }
|
1051
1036
|
end
|
1052
1037
|
|
1053
1038
|
it 'should display correct range_field_tag in erb' do
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1039
|
+
visit '/erb/form_tag'
|
1040
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
|
1041
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
|
1057
1042
|
end
|
1058
1043
|
|
1059
1044
|
it 'should display correct range_field_tag in haml' do
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1045
|
+
visit '/haml/form_tag'
|
1046
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
|
1047
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
|
1063
1048
|
end
|
1064
1049
|
|
1065
1050
|
it 'should display correct range_field_tag in slim' do
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
end
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
describe 'for #datetime_field_tag' do
|
1073
|
-
before do
|
1074
|
-
@expected = {
|
1075
|
-
:name => 'datetime',
|
1076
|
-
:max => "2000-04-01T12:00:00.000+0000",
|
1077
|
-
:min => "1993-02-24T12:30:45.000+0000",
|
1078
|
-
:value => "2000-04-01T12:00:00.000+0000"
|
1079
|
-
}
|
1080
|
-
end
|
1081
|
-
|
1082
|
-
it 'should create an input tag with min and max and value options' do
|
1083
|
-
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1084
|
-
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1085
|
-
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1086
|
-
actual_html = datetime_field_tag('datetime', :max => max, :min => min, :value => value)
|
1087
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1088
|
-
end
|
1089
|
-
|
1090
|
-
it 'should create an input tag with datetime' do
|
1091
|
-
actual_html = datetime_field_tag('datetime')
|
1092
|
-
assert_html_has_tag(actual_html, 'input[type=datetime]')
|
1093
|
-
end
|
1094
|
-
|
1095
|
-
it 'should create an input tag when the format string passed as datetime option value' do
|
1096
|
-
actual_html = datetime_field_tag('datetime', :value => '1993-02-24T12:30:45+00:00')
|
1097
|
-
assert_html_has_tag(actual_html, 'input[type=datetime]', :value => "1993-02-24T12:30:45.000+0000")
|
1098
|
-
end
|
1099
|
-
|
1100
|
-
it 'should display correct datetime_field_tag in erb' do
|
1101
|
-
get "/erb/form_tag"
|
1102
|
-
assert_response_has_tag 'input', @expected
|
1103
|
-
end
|
1104
|
-
|
1105
|
-
it 'should display correct datetime_field_tag in haml' do
|
1106
|
-
get "/haml/form_tag"
|
1107
|
-
assert_response_has_tag 'input', @expected
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
it 'should display correct datetime_field_tag in slim' do
|
1111
|
-
get "/slim/form_tag"
|
1112
|
-
assert_response_has_tag 'input', @expected
|
1113
|
-
end
|
1114
|
-
end
|
1115
|
-
|
1116
|
-
describe 'for #datetime_local_field_tag' do
|
1117
|
-
before do
|
1118
|
-
@expected = {
|
1119
|
-
:name => 'datetime_local',
|
1120
|
-
:max => "2000-04-01T12:00:00",
|
1121
|
-
:min => "1993-02-24T12:30:45",
|
1122
|
-
:value => "2000-04-01T12:00:00"
|
1123
|
-
}
|
1124
|
-
end
|
1125
|
-
|
1126
|
-
it 'should create an input tag with min and max and value options' do
|
1127
|
-
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1128
|
-
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1129
|
-
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1130
|
-
actual_html = datetime_local_field_tag('datetime_local', :max => max, :min => min, :value => value)
|
1131
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1132
|
-
end
|
1133
|
-
|
1134
|
-
it 'should create an input tag with datetime-local' do
|
1135
|
-
actual_html = datetime_local_field_tag('datetime_local')
|
1136
|
-
assert_html_has_tag(actual_html, 'input[type="datetime-local"]')
|
1137
|
-
end
|
1138
|
-
|
1139
|
-
it 'should create an input tag when the format string passed as datetime-local option value' do
|
1140
|
-
actual_html = datetime_local_field_tag('datetime_local', :value => '1993-02-24T12:30:45')
|
1141
|
-
assert_html_has_tag(actual_html, 'input[type="datetime-local"]', :value => "1993-02-24T12:30:45")
|
1142
|
-
end
|
1143
|
-
|
1144
|
-
it 'should display correct datetime_local_field_tag in erb' do
|
1145
|
-
get "/erb/form_tag"
|
1146
|
-
assert_response_has_tag 'input', @expected
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
it 'should display correct datetime_local_field_tag in haml' do
|
1150
|
-
get "/haml/form_tag"
|
1151
|
-
assert_response_has_tag 'input', @expected
|
1152
|
-
end
|
1153
|
-
|
1154
|
-
it 'should display correct datetime_local_field_tag in slim' do
|
1155
|
-
get "/slim/form_tag"
|
1156
|
-
assert_response_has_tag 'input', @expected
|
1157
|
-
end
|
1158
|
-
end
|
1159
|
-
|
1160
|
-
describe 'for #date_field_tag' do
|
1161
|
-
before do
|
1162
|
-
@expected = {
|
1163
|
-
:name => 'date',
|
1164
|
-
:max => "2000-04-01",
|
1165
|
-
:min => "1993-02-24",
|
1166
|
-
:value => "2000-04-01"
|
1167
|
-
}
|
1168
|
-
end
|
1169
|
-
|
1170
|
-
it 'should create an input tag with min and max and value options' do
|
1171
|
-
max = DateTime.new(2000, 4, 1)
|
1172
|
-
min = DateTime.new(1993, 2, 24)
|
1173
|
-
value = DateTime.new(2000, 4, 1)
|
1174
|
-
actual_html = date_field_tag('date', :max => max, :min => min, :value => value)
|
1175
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1176
|
-
end
|
1177
|
-
|
1178
|
-
it 'should create an input tag with date' do
|
1179
|
-
actual_html = date_field_tag('date')
|
1180
|
-
assert_html_has_tag(actual_html, 'input[type="date"]')
|
1181
|
-
end
|
1182
|
-
|
1183
|
-
it 'should create an input tag when the format string passed as date option value' do
|
1184
|
-
actual_html = date_field_tag('date', :value => '1993-02-24')
|
1185
|
-
assert_html_has_tag(actual_html, 'input[type="date"]', :value => "1993-02-24")
|
1186
|
-
end
|
1187
|
-
|
1188
|
-
it 'should display correct date_field_tag in erb' do
|
1189
|
-
get "/erb/form_tag"
|
1190
|
-
assert_response_has_tag 'input', @expected
|
1191
|
-
end
|
1192
|
-
|
1193
|
-
it 'should display correct date_field_tag in haml' do
|
1194
|
-
get "/haml/form_tag"
|
1195
|
-
assert_response_has_tag 'input', @expected
|
1196
|
-
end
|
1197
|
-
|
1198
|
-
it 'should display correct date_field_tag in slim' do
|
1199
|
-
get "/slim/form_tag"
|
1200
|
-
assert_response_has_tag 'input', @expected
|
1201
|
-
end
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
describe 'for #month_field_tag' do
|
1205
|
-
before do
|
1206
|
-
@expected = {
|
1207
|
-
:name => 'month',
|
1208
|
-
:max => "2000-04",
|
1209
|
-
:min => "1993-02",
|
1210
|
-
:value => "2000-04"
|
1211
|
-
}
|
1212
|
-
end
|
1213
|
-
|
1214
|
-
it 'should create an input tag with min and max and value options' do
|
1215
|
-
max = DateTime.new(2000, 4, 1)
|
1216
|
-
min = DateTime.new(1993, 2, 24)
|
1217
|
-
value = DateTime.new(2000, 4, 1)
|
1218
|
-
actual_html = month_field_tag('month', :max => max, :min => min, :value => value)
|
1219
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1220
|
-
end
|
1221
|
-
|
1222
|
-
it 'should create an input tag with month' do
|
1223
|
-
actual_html = month_field_tag('month')
|
1224
|
-
assert_html_has_tag(actual_html, 'input[type="month"]')
|
1225
|
-
end
|
1226
|
-
|
1227
|
-
it 'should create an input tag when the format string passed as month option value' do
|
1228
|
-
actual_html = month_field_tag('month', :value => '1993-02-24')
|
1229
|
-
assert_html_has_tag(actual_html, 'input[type="month"]', :value => "1993-02")
|
1230
|
-
end
|
1231
|
-
|
1232
|
-
it 'should display correct month_field_tag in erb' do
|
1233
|
-
get "/erb/form_tag"
|
1234
|
-
assert_response_has_tag 'input', @expected
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
it 'should display correct month_field_tag in haml' do
|
1238
|
-
get "/haml/form_tag"
|
1239
|
-
assert_response_has_tag 'input', @expected
|
1240
|
-
end
|
1241
|
-
|
1242
|
-
it 'should display correct month_field_tag in slim' do
|
1243
|
-
get "/slim/form_tag"
|
1244
|
-
assert_response_has_tag 'input', @expected
|
1245
|
-
end
|
1246
|
-
end
|
1247
|
-
|
1248
|
-
describe 'for #week_field_tag' do
|
1249
|
-
before do
|
1250
|
-
@expected = {
|
1251
|
-
:name => 'week',
|
1252
|
-
:max => "2000-W13",
|
1253
|
-
:min => "1993-W08",
|
1254
|
-
:value => "2000-W13"
|
1255
|
-
}
|
1256
|
-
end
|
1257
|
-
|
1258
|
-
it 'should create an input tag with min and max and value options' do
|
1259
|
-
max = DateTime.new(2000, 4, 1)
|
1260
|
-
min = DateTime.new(1993, 2, 24)
|
1261
|
-
value = DateTime.new(2000, 4, 1)
|
1262
|
-
actual_html = week_field_tag('week', :max => max, :min => min, :value => value)
|
1263
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1264
|
-
end
|
1265
|
-
|
1266
|
-
it 'should create an input tag with week' do
|
1267
|
-
actual_html = week_field_tag('week')
|
1268
|
-
assert_html_has_tag(actual_html, 'input[type="week"]')
|
1269
|
-
end
|
1270
|
-
|
1271
|
-
it 'should create an input tag when the format string passed as week option value' do
|
1272
|
-
actual_html = week_field_tag('week', :value => '1993-02-24')
|
1273
|
-
assert_html_has_tag(actual_html, 'input[type="week"]', :value => "1993-W08")
|
1274
|
-
end
|
1275
|
-
|
1276
|
-
it 'should display correct week_field_tag in erb' do
|
1277
|
-
get "/erb/form_tag"
|
1278
|
-
assert_response_has_tag 'input', @expected
|
1279
|
-
end
|
1280
|
-
|
1281
|
-
it 'should display correct week_field_tag in haml' do
|
1282
|
-
get "/haml/form_tag"
|
1283
|
-
assert_response_has_tag 'input', @expected
|
1284
|
-
end
|
1285
|
-
|
1286
|
-
it 'should display correct week_field_tag in slim' do
|
1287
|
-
get "/slim/form_tag"
|
1288
|
-
assert_response_has_tag 'input', @expected
|
1289
|
-
end
|
1290
|
-
end
|
1291
|
-
|
1292
|
-
describe 'for #time_field_tag' do
|
1293
|
-
before do
|
1294
|
-
@expected = {
|
1295
|
-
:name => 'time',
|
1296
|
-
:max => "13:30:00.000",
|
1297
|
-
:min => "01:19:12.000",
|
1298
|
-
:value => "13:30:00.000"
|
1299
|
-
}
|
1300
|
-
end
|
1301
|
-
|
1302
|
-
it 'should create an input tag with min and max and value options' do
|
1303
|
-
max = Time.new(2008, 6, 21, 13, 30, 0)
|
1304
|
-
min = Time.new(1993, 2, 24, 1, 19, 12)
|
1305
|
-
value = Time.new(2008, 6, 21, 13, 30, 0)
|
1306
|
-
actual_html = time_field_tag('time', :max => max, :min => min, :value => value)
|
1307
|
-
assert_html_has_tag(actual_html, 'input', @expected)
|
1308
|
-
end
|
1309
|
-
|
1310
|
-
it 'should create an input tag with time' do
|
1311
|
-
actual_html = time_field_tag('time')
|
1312
|
-
assert_html_has_tag(actual_html, 'input[type="time"]')
|
1313
|
-
end
|
1314
|
-
|
1315
|
-
it 'should create an input tag when the format string passed as time option value' do
|
1316
|
-
actual_html = time_field_tag('time', :value => '1993-02-24 01:19:12')
|
1317
|
-
assert_html_has_tag(actual_html, 'input[type="time"]', :value => "01:19:12.000")
|
1318
|
-
end
|
1319
|
-
|
1320
|
-
it 'should display correct time_field_tag in erb' do
|
1321
|
-
get "/erb/form_tag"
|
1322
|
-
assert_response_has_tag 'input', @expected
|
1323
|
-
end
|
1324
|
-
|
1325
|
-
it 'should display correct time_field_tag in haml' do
|
1326
|
-
get "/haml/form_tag"
|
1327
|
-
assert_response_has_tag 'input', @expected
|
1328
|
-
end
|
1329
|
-
|
1330
|
-
it 'should display correct time_field_tag in slim' do
|
1331
|
-
get "/slim/form_tag"
|
1332
|
-
assert_response_has_tag 'input', @expected
|
1333
|
-
end
|
1334
|
-
end
|
1335
|
-
|
1336
|
-
describe 'for #color_field_tag' do
|
1337
|
-
before do
|
1338
|
-
@expected = {
|
1339
|
-
:name => 'color',
|
1340
|
-
:value => '#ff0000'
|
1341
|
-
}
|
1342
|
-
end
|
1343
|
-
|
1344
|
-
it 'should create an input tag with value option' do
|
1345
|
-
actual_html = color_field_tag('color', :value => "#ff0000")
|
1346
|
-
assert_html_has_tag(actual_html, 'input[type="color"]', @expected)
|
1347
|
-
end
|
1348
|
-
|
1349
|
-
it 'should create an input tag with short color code' do
|
1350
|
-
actual_html = color_field_tag('color', :value => "#f00")
|
1351
|
-
assert_html_has_tag(actual_html, 'input[type="color"]', @expected)
|
1352
|
-
end
|
1353
|
-
|
1354
|
-
it 'should display correct color_field_tag in erb' do
|
1355
|
-
get "/erb/form_tag"
|
1356
|
-
assert_response_has_tag 'input', @expected
|
1357
|
-
end
|
1358
|
-
|
1359
|
-
it 'should display correct color_field_tag in haml' do
|
1360
|
-
get "/haml/form_tag"
|
1361
|
-
assert_response_has_tag 'input', @expected
|
1362
|
-
end
|
1363
|
-
|
1364
|
-
it 'should display correct color_field_tag in slim' do
|
1365
|
-
get "/slim/form_tag"
|
1366
|
-
assert_response_has_tag 'input', @expected
|
1051
|
+
visit '/slim/form_tag'
|
1052
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
|
1053
|
+
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
|
1367
1054
|
end
|
1368
1055
|
end
|
1369
1056
|
end
|