padrino-helpers 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/padrino-helpers.rb +16 -0
- data/lib/padrino-helpers/asset_tag_helpers.rb +97 -0
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +139 -0
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +37 -0
- data/lib/padrino-helpers/form_helpers.rb +194 -0
- data/lib/padrino-helpers/format_helpers.rb +74 -0
- data/lib/padrino-helpers/output_helpers.rb +98 -0
- data/lib/padrino-helpers/render_helpers.rb +63 -0
- data/lib/padrino-helpers/tag_helpers.rb +42 -0
- data/test/active_support_helpers.rb +7 -0
- data/test/fixtures/markup_app/app.rb +61 -0
- data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/test/fixtures/markup_app/views/capture_concat.haml +13 -0
- data/test/fixtures/markup_app/views/content_for.erb +11 -0
- data/test/fixtures/markup_app/views/content_for.haml +9 -0
- data/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/test/fixtures/markup_app/views/fields_for.erb +8 -0
- data/test/fixtures/markup_app/views/fields_for.haml +6 -0
- data/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/test/fixtures/markup_app/views/form_tag.erb +57 -0
- data/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/test/fixtures/render_app/app.rb +53 -0
- data/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/test/helper.rb +73 -0
- data/test/test_asset_tag_helpers.rb +127 -0
- data/test/test_form_builder.rb +611 -0
- data/test/test_form_helpers.rb +406 -0
- data/test/test_format_helpers.rb +96 -0
- data/test/test_output_helpers.rb +63 -0
- data/test/test_render_helpers.rb +78 -0
- data/test/test_tag_helpers.rb +73 -0
- metadata +174 -0
@@ -0,0 +1,406 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
3
|
+
|
4
|
+
class TestFormHelpers < Test::Unit::TestCase
|
5
|
+
include Padrino::Helpers::FormHelpers
|
6
|
+
|
7
|
+
def app
|
8
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'for #form_tag method' do
|
12
|
+
should "display correct forms in ruby" do
|
13
|
+
actual_html = form_tag('/register', :class => 'test', :method => "post") { "Demo" }
|
14
|
+
assert_has_tag(:form, :class => "test") { actual_html }
|
15
|
+
assert_has_tag('form input', :type => 'hidden', :name => '_method', :count => 0) { actual_html }
|
16
|
+
end
|
17
|
+
|
18
|
+
should "display correct text inputs within form_tag" do
|
19
|
+
actual_html = form_tag('/register', :class => 'test') { text_field_tag(:username) }
|
20
|
+
assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
|
21
|
+
end
|
22
|
+
|
23
|
+
should "display correct form with method :put" do
|
24
|
+
actual_html = form_tag('/update', :class => 'put-form', :method => "put") { "Demo" }
|
25
|
+
assert_has_tag(:form, :class => "put-form", :method => 'post') { actual_html }
|
26
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
|
27
|
+
end
|
28
|
+
|
29
|
+
should "display correct form with method :delete" do
|
30
|
+
actual_html = form_tag('/remove', :class => 'delete-form', :method => "delete") { "Demo" }
|
31
|
+
assert_has_tag(:form, :class => "delete-form", :method => 'post') { actual_html }
|
32
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
|
33
|
+
end
|
34
|
+
|
35
|
+
should "display correct form with multipart encoding" do
|
36
|
+
actual_html = form_tag('/remove', :multipart => true) { "Demo" }
|
37
|
+
assert_has_tag(:form, :enctype => "multipart/form-data") { actual_html }
|
38
|
+
end
|
39
|
+
|
40
|
+
should "display correct forms in erb" do
|
41
|
+
visit '/erb/form_tag'
|
42
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
43
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
44
|
+
end
|
45
|
+
|
46
|
+
should "display correct forms in haml" do
|
47
|
+
visit '/haml/form_tag'
|
48
|
+
assert_have_selector 'form.simple-form', :action => '/simple'
|
49
|
+
assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'for #field_set_tag method' do
|
54
|
+
should "display correct field_sets in ruby" do
|
55
|
+
actual_html = field_set_tag("Basic", :class => 'basic') { "Demo" }
|
56
|
+
assert_has_tag(:fieldset, :class => 'basic') { actual_html }
|
57
|
+
assert_has_tag('fieldset legend', :content => "Basic") { actual_html }
|
58
|
+
end
|
59
|
+
|
60
|
+
should "display correct field_sets in erb" do
|
61
|
+
visit '/erb/form_tag'
|
62
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
63
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
64
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
65
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
66
|
+
end
|
67
|
+
|
68
|
+
should "display correct field_sets in haml" do
|
69
|
+
visit '/haml/form_tag'
|
70
|
+
assert_have_selector 'form.simple-form fieldset', :count => 1
|
71
|
+
assert_have_no_selector 'form.simple-form fieldset legend'
|
72
|
+
assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
|
73
|
+
assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'for #error_messages_for method' do
|
78
|
+
should "display correct error messages list in ruby" do
|
79
|
+
user = stub(:class => "User", :errors => stub(:full_messages => ["1", "2"], :none? => false), :blank? => false)
|
80
|
+
actual_html = error_messages_for(user)
|
81
|
+
assert_has_tag('div.field-errors') { actual_html }
|
82
|
+
assert_has_tag('div.field-errors p', :content => "The user could not be saved") { actual_html }
|
83
|
+
assert_has_tag('div.field-errors ul.errors-list') { actual_html }
|
84
|
+
assert_has_tag('div.field-errors ul.errors-list li', :count => 2) { actual_html }
|
85
|
+
end
|
86
|
+
|
87
|
+
should "display correct error messages list in erb" do
|
88
|
+
visit '/erb/form_tag'
|
89
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
90
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
91
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There are problems with saving user!"
|
92
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list'
|
93
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :count => 3
|
94
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :content => "This is a second fake error"
|
95
|
+
end
|
96
|
+
|
97
|
+
should "display correct error messages list in haml" do
|
98
|
+
visit '/haml/form_tag'
|
99
|
+
assert_have_no_selector 'form.simple-form .field-errors'
|
100
|
+
assert_have_selector 'form.advanced-form .field-errors'
|
101
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There are problems with saving user!"
|
102
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list'
|
103
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :count => 3
|
104
|
+
assert_have_selector 'form.advanced-form .field-errors ul.errors-list li', :content => "This is a second fake error"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'for #label_tag method' do
|
109
|
+
should "display label tag in ruby" do
|
110
|
+
actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
|
111
|
+
assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname: ") { actual_html }
|
112
|
+
end
|
113
|
+
|
114
|
+
should "display label tag in erb for simple form" do
|
115
|
+
visit '/erb/form_tag'
|
116
|
+
assert_have_selector 'form.simple-form label', :count => 4
|
117
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
118
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
119
|
+
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
120
|
+
end
|
121
|
+
should "display label tag in erb for advanced form" do
|
122
|
+
visit '/erb/form_tag'
|
123
|
+
assert_have_selector 'form.advanced-form label', :count => 6
|
124
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
125
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
126
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
127
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
128
|
+
assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
|
129
|
+
end
|
130
|
+
|
131
|
+
should "display label tag in haml for simple form" do
|
132
|
+
visit '/haml/form_tag'
|
133
|
+
assert_have_selector 'form.simple-form label', :count => 4
|
134
|
+
assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
|
135
|
+
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
136
|
+
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
137
|
+
end
|
138
|
+
should "display label tag in haml for advanced form" do
|
139
|
+
visit '/haml/form_tag'
|
140
|
+
assert_have_selector 'form.advanced-form label', :count => 6
|
141
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
|
142
|
+
assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
|
143
|
+
assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
|
144
|
+
assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
|
145
|
+
assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'for #hidden_field_tag method' do
|
150
|
+
should "display hidden field in ruby" do
|
151
|
+
actual_html = hidden_field_tag(:session_key, :id => 'session_id', :value => '56768')
|
152
|
+
assert_has_tag(:input, :type => 'hidden', :id => "session_id", :name => 'session_key', :value => '56768') { actual_html }
|
153
|
+
end
|
154
|
+
|
155
|
+
should "display hidden field in erb" do
|
156
|
+
visit '/erb/form_tag'
|
157
|
+
assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
158
|
+
assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
159
|
+
end
|
160
|
+
|
161
|
+
should "display hidden field in haml" do
|
162
|
+
visit '/haml/form_tag'
|
163
|
+
assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
164
|
+
assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'for #text_field_tag method' do
|
169
|
+
should "display text field in ruby" do
|
170
|
+
actual_html = text_field_tag(:username, :class => 'long')
|
171
|
+
assert_has_tag(:input, :type => 'text', :class => "long", :name => 'username') { actual_html }
|
172
|
+
end
|
173
|
+
|
174
|
+
should "display text field in erb" do
|
175
|
+
visit '/erb/form_tag'
|
176
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
177
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
178
|
+
end
|
179
|
+
|
180
|
+
should "display text field in haml" do
|
181
|
+
visit '/haml/form_tag'
|
182
|
+
assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
|
183
|
+
assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'for #text_area_tag method' do
|
188
|
+
should "display text area in ruby" do
|
189
|
+
actual_html = text_area_tag(:about, :class => 'long')
|
190
|
+
assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
|
191
|
+
end
|
192
|
+
|
193
|
+
should "display text area in erb" do
|
194
|
+
visit '/erb/form_tag'
|
195
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
196
|
+
end
|
197
|
+
|
198
|
+
should "display text area in haml" do
|
199
|
+
visit '/haml/form_tag'
|
200
|
+
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'for #password_field_tag method' do
|
205
|
+
should "display password field in ruby" do
|
206
|
+
actual_html = password_field_tag(:password, :class => 'long')
|
207
|
+
assert_has_tag(:input, :type => 'password', :class => "long", :name => 'password') { actual_html }
|
208
|
+
end
|
209
|
+
|
210
|
+
should "display password field in erb" do
|
211
|
+
visit '/erb/form_tag'
|
212
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
213
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
214
|
+
end
|
215
|
+
|
216
|
+
should "display password field in haml" do
|
217
|
+
visit '/haml/form_tag'
|
218
|
+
assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
|
219
|
+
assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'for #file_field_tag method' do
|
224
|
+
should "display file field in ruby" do
|
225
|
+
actual_html = file_field_tag(:photo, :class => 'photo')
|
226
|
+
assert_has_tag(:input, :type => 'file', :class => "photo", :name => 'photo') { actual_html }
|
227
|
+
end
|
228
|
+
|
229
|
+
should "display file field in erb" do
|
230
|
+
visit '/erb/form_tag'
|
231
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
232
|
+
end
|
233
|
+
|
234
|
+
should "display file field in haml" do
|
235
|
+
visit '/haml/form_tag'
|
236
|
+
assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "for #check_box_tag method" do
|
241
|
+
should "display check_box tag in ruby" do
|
242
|
+
actual_html = check_box_tag("clear_session")
|
243
|
+
assert_has_tag(:input, :type => 'checkbox', :value => '1', :name => 'clear_session') { actual_html }
|
244
|
+
assert_has_no_tag(:input, :type => 'hidden') { actual_html }
|
245
|
+
end
|
246
|
+
|
247
|
+
should "display check_box tag in ruby with extended attributes" do
|
248
|
+
actual_html = check_box_tag("clear_session", :disabled => true, :checked => true)
|
249
|
+
assert_has_tag(:input, :type => 'checkbox', :disabled => 'disabled', :checked => 'checked') { actual_html }
|
250
|
+
end
|
251
|
+
|
252
|
+
should "display check_box tag in erb" do
|
253
|
+
visit '/erb/form_tag'
|
254
|
+
assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
|
255
|
+
assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
|
256
|
+
end
|
257
|
+
|
258
|
+
should "display check_box tag in haml" do
|
259
|
+
visit '/haml/form_tag'
|
260
|
+
assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
|
261
|
+
assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "for #radio_button_tag method" do
|
266
|
+
should "display radio_button tag in ruby" do
|
267
|
+
actual_html = radio_button_tag("gender", :value => 'male')
|
268
|
+
assert_has_tag(:input, :type => 'radio', :value => 'male', :name => 'gender') { actual_html }
|
269
|
+
end
|
270
|
+
|
271
|
+
should "display radio_button tag in ruby with extended attributes" do
|
272
|
+
actual_html = radio_button_tag("gender", :disabled => true, :checked => true)
|
273
|
+
assert_has_tag(:input, :type => 'radio', :disabled => 'disabled', :checked => 'checked') { actual_html }
|
274
|
+
end
|
275
|
+
|
276
|
+
should "display radio_button tag in erb" do
|
277
|
+
visit '/erb/form_tag'
|
278
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
|
279
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
|
280
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
|
281
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
|
282
|
+
end
|
283
|
+
|
284
|
+
should "display radio_button tag in haml" do
|
285
|
+
visit '/haml/form_tag'
|
286
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
|
287
|
+
assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
|
288
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
|
289
|
+
assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context "for #select_tag method" do
|
294
|
+
should "display select tag in ruby" do
|
295
|
+
actual_html = select_tag(:favorite_color, :options => ['green', 'blue', 'black'], :include_blank => true)
|
296
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
297
|
+
assert_has_tag('select option:first-child', :content => '') { actual_html }
|
298
|
+
assert_has_tag('select option', :content => 'green', :value => 'green') { actual_html }
|
299
|
+
assert_has_tag('select option', :content => 'blue', :value => 'blue') { actual_html }
|
300
|
+
assert_has_tag('select option', :content => 'black', :value => 'black') { actual_html }
|
301
|
+
end
|
302
|
+
|
303
|
+
should "display select tag in ruby with extended attributes" do
|
304
|
+
actual_html = select_tag(:favorite_color, :disabled => true, :options => ['only', 'option'])
|
305
|
+
assert_has_tag(:select, :disabled => 'disabled') { actual_html }
|
306
|
+
end
|
307
|
+
|
308
|
+
should "display select tag in ruby with multiple attribute" do
|
309
|
+
actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option'])
|
310
|
+
assert_has_tag(:select, :multiple => 'multiple', :name => 'favorite_color[]') { actual_html }
|
311
|
+
end
|
312
|
+
|
313
|
+
should "display options with values and selected" do
|
314
|
+
options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
315
|
+
actual_html = select_tag(:favorite_color, :options => options, :selected => 'green1')
|
316
|
+
assert_has_tag(:select, :name => 'favorite_color') { actual_html }
|
317
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
318
|
+
assert_has_tag('select option', :content => 'Green', :value => 'green1', :selected => 'selected') { actual_html }
|
319
|
+
assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
|
320
|
+
assert_has_tag('select option', :content => 'Black', :value => 'black1') { actual_html }
|
321
|
+
end
|
322
|
+
|
323
|
+
should "display select tag in erb" do
|
324
|
+
visit '/erb/form_tag'
|
325
|
+
assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
|
326
|
+
assert_have_selector('select option', :content => 'green', :value => 'green')
|
327
|
+
assert_have_selector('select option', :content => 'orange', :value => 'orange')
|
328
|
+
assert_have_selector('select option', :content => 'purple', :value => 'purple')
|
329
|
+
assert_have_selector 'form.advanced-form select', :name => 'fav_color'
|
330
|
+
assert_have_selector('select option', :content => 'green', :value => '1')
|
331
|
+
assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
|
332
|
+
assert_have_selector('select option', :content => 'purple', :value => '3')
|
333
|
+
end
|
334
|
+
|
335
|
+
should "display select tag in haml" do
|
336
|
+
visit '/haml/form_tag'
|
337
|
+
assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
|
338
|
+
assert_have_selector('select option', :content => 'green', :value => 'green')
|
339
|
+
assert_have_selector('select option', :content => 'orange', :value => 'orange')
|
340
|
+
assert_have_selector('select option', :content => 'purple', :value => 'purple')
|
341
|
+
assert_have_selector 'form.advanced-form select', :name => 'fav_color'
|
342
|
+
assert_have_selector('select option', :content => 'green', :value => '1')
|
343
|
+
assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
|
344
|
+
assert_have_selector('select option', :content => 'purple', :value => '3')
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'for #submit_tag method' do
|
349
|
+
should "display submit tag in ruby" do
|
350
|
+
actual_html = submit_tag("Update", :class => 'success')
|
351
|
+
assert_has_tag(:input, :type => 'submit', :class => "success", :value => 'Update') { actual_html }
|
352
|
+
end
|
353
|
+
|
354
|
+
should "display submit tag in erb" do
|
355
|
+
visit '/erb/form_tag'
|
356
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
357
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
358
|
+
end
|
359
|
+
|
360
|
+
should "display submit tag in haml" do
|
361
|
+
visit '/haml/form_tag'
|
362
|
+
assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
|
363
|
+
assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context 'for #button_tag method' do
|
368
|
+
should "display submit tag in ruby" do
|
369
|
+
actual_html = button_tag("Cancel", :class => 'clear')
|
370
|
+
assert_has_tag(:input, :type => 'button', :class => "clear", :value => 'Cancel') { actual_html }
|
371
|
+
end
|
372
|
+
|
373
|
+
should "display submit tag in erb" do
|
374
|
+
visit '/erb/form_tag'
|
375
|
+
assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
|
376
|
+
end
|
377
|
+
|
378
|
+
should "display submit tag in haml" do
|
379
|
+
visit '/haml/form_tag'
|
380
|
+
assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context 'for #image_submit_tag method' do
|
385
|
+
should "display image submit tag in ruby with relative path" do
|
386
|
+
actual_html = image_submit_tag('buttons/ok.png', :class => 'success')
|
387
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => '/images/buttons/ok.png') { actual_html }
|
388
|
+
end
|
389
|
+
|
390
|
+
should "display image submit tag in ruby with absolute path" do
|
391
|
+
actual_html = image_submit_tag('/system/ok.png', :class => 'success')
|
392
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => '/system/ok.png') { actual_html }
|
393
|
+
end
|
394
|
+
|
395
|
+
should "display image submit tag in erb" do
|
396
|
+
visit '/erb/form_tag'
|
397
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png"
|
398
|
+
end
|
399
|
+
|
400
|
+
should "display image submit tag in haml" do
|
401
|
+
visit '/haml/form_tag'
|
402
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png"
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
3
|
+
|
4
|
+
class TestFormatHelpers < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
include Padrino::Helpers::FormatHelpers
|
10
|
+
|
11
|
+
context 'for #h and #h! method' do
|
12
|
+
should "escape the simple html" do
|
13
|
+
assert_equal '<h1>hello</h1>', h('<h1>hello</h1>')
|
14
|
+
assert_equal '<h1>hello</h1>', escape_html('<h1>hello</h1>')
|
15
|
+
end
|
16
|
+
should "escape all brackets, quotes and ampersands" do
|
17
|
+
assert_equal '<h1><>"&demo&"<></h1>', h('<h1><>"&demo&"<></h1>')
|
18
|
+
end
|
19
|
+
should "return default text if text is empty" do
|
20
|
+
assert_equal 'default', h!("", "default")
|
21
|
+
assert_equal ' ', h!("")
|
22
|
+
end
|
23
|
+
should "return text escaped if not empty" do
|
24
|
+
assert_equal '<h1>hello</h1>', h!('<h1>hello</h1>')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'for #time_in_words method' do
|
29
|
+
should "display today" do
|
30
|
+
assert_equal 'today', time_in_words(Time.now)
|
31
|
+
end
|
32
|
+
should "display yesterday" do
|
33
|
+
assert_equal 'yesterday', time_in_words(1.day.ago)
|
34
|
+
end
|
35
|
+
should "display tomorrow" do
|
36
|
+
assert_equal 'tomorrow', time_in_words(1.day.from_now)
|
37
|
+
end
|
38
|
+
should "return future number of days" do
|
39
|
+
assert_equal 'in 4 days', time_in_words(4.days.from_now)
|
40
|
+
end
|
41
|
+
should "return past days ago" do
|
42
|
+
assert_equal '4 days ago', time_in_words(4.days.ago)
|
43
|
+
end
|
44
|
+
should "return formatted archived date" do
|
45
|
+
assert_equal 100.days.ago.strftime('%A, %B %e'), time_in_words(100.days.ago)
|
46
|
+
end
|
47
|
+
should "return formatted archived year date" do
|
48
|
+
assert_equal 500.days.ago.strftime('%A, %B %e, %Y'), time_in_words(500.days.ago)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'for #relative_time_ago method' do
|
53
|
+
should 'display now as a minute ago' do
|
54
|
+
assert_equal 'about a minute', relative_time_ago(1.minute.ago)
|
55
|
+
end
|
56
|
+
should "display a few minutes ago" do
|
57
|
+
assert_equal '4 minutes', relative_time_ago(4.minute.ago)
|
58
|
+
end
|
59
|
+
should "display an hour ago" do
|
60
|
+
assert_equal 'about 1 hour', relative_time_ago(1.hour.ago + 5.minutes.ago.sec)
|
61
|
+
end
|
62
|
+
should "display a few hours ago" do
|
63
|
+
assert_equal 'about 3 hours', relative_time_ago(3.hour.ago + 5.minutes.ago.sec)
|
64
|
+
end
|
65
|
+
should "display a day ago" do
|
66
|
+
assert_equal '1 day', relative_time_ago(1.day.ago)
|
67
|
+
end
|
68
|
+
should "display a few days ago" do
|
69
|
+
assert_equal '5 days', relative_time_ago(5.days.ago - 5.minutes.ago.sec)
|
70
|
+
end
|
71
|
+
should "display a month ago" do
|
72
|
+
assert_equal 'about 1 month', relative_time_ago(32.days.ago + 5.minutes.ago.sec)
|
73
|
+
end
|
74
|
+
should "display a few months ago" do
|
75
|
+
assert_equal '6 months', relative_time_ago(180.days.ago - 5.minutes.ago.sec)
|
76
|
+
end
|
77
|
+
should "display a year ago" do
|
78
|
+
assert_equal 'about 1 year', relative_time_ago(365.days.ago - 5.minutes.ago.sec)
|
79
|
+
end
|
80
|
+
should "display a few years ago" do
|
81
|
+
assert_equal 'over 7 years', relative_time_ago(2800.days.ago - 5.minutes.ago.sec)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'for #escape_javascript method' do
|
86
|
+
should "escape double quotes" do
|
87
|
+
assert_equal "\"hello\"", escape_javascript('"hello"')
|
88
|
+
end
|
89
|
+
should "escape single quotes" do
|
90
|
+
assert_equal "\"hello\"", escape_javascript("'hello'")
|
91
|
+
end
|
92
|
+
should "escape html tags and breaks" do
|
93
|
+
assert_equal "\"\\n<p>hello<\\/p>\\n\"", escape_javascript("\n\r<p>hello</p>\r\n")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|