padrino-helpers-cj 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +21 -0
  4. data/.yardopts +1 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +239 -0
  7. data/Rakefile +5 -0
  8. data/lib/padrino-helpers.rb +62 -0
  9. data/lib/padrino-helpers/asset_tag_helpers.rb +390 -0
  10. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +283 -0
  11. data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +92 -0
  12. data/lib/padrino-helpers/form_builder/standard_form_builder.rb +40 -0
  13. data/lib/padrino-helpers/form_helpers.rb +633 -0
  14. data/lib/padrino-helpers/form_helpers/errors.rb +138 -0
  15. data/lib/padrino-helpers/form_helpers/options.rb +97 -0
  16. data/lib/padrino-helpers/form_helpers/security.rb +70 -0
  17. data/lib/padrino-helpers/format_helpers.rb +372 -0
  18. data/lib/padrino-helpers/locale/cs.yml +103 -0
  19. data/lib/padrino-helpers/locale/da.yml +91 -0
  20. data/lib/padrino-helpers/locale/de.yml +81 -0
  21. data/lib/padrino-helpers/locale/en.yml +103 -0
  22. data/lib/padrino-helpers/locale/es.yml +103 -0
  23. data/lib/padrino-helpers/locale/fr.yml +79 -0
  24. data/lib/padrino-helpers/locale/hu.yml +103 -0
  25. data/lib/padrino-helpers/locale/it.yml +89 -0
  26. data/lib/padrino-helpers/locale/ja.yml +103 -0
  27. data/lib/padrino-helpers/locale/lv.yml +103 -0
  28. data/lib/padrino-helpers/locale/nl.yml +82 -0
  29. data/lib/padrino-helpers/locale/no.yml +91 -0
  30. data/lib/padrino-helpers/locale/pl.yml +95 -0
  31. data/lib/padrino-helpers/locale/pt_br.yml +103 -0
  32. data/lib/padrino-helpers/locale/ro.yml +103 -0
  33. data/lib/padrino-helpers/locale/ru.yml +103 -0
  34. data/lib/padrino-helpers/locale/sv.yml +103 -0
  35. data/lib/padrino-helpers/locale/tr.yml +103 -0
  36. data/lib/padrino-helpers/locale/uk.yml +103 -0
  37. data/lib/padrino-helpers/locale/zh_cn.yml +103 -0
  38. data/lib/padrino-helpers/locale/zh_tw.yml +103 -0
  39. data/lib/padrino-helpers/number_helpers.rb +283 -0
  40. data/lib/padrino-helpers/output_helpers.rb +226 -0
  41. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +61 -0
  42. data/lib/padrino-helpers/output_helpers/erb_handler.rb +27 -0
  43. data/lib/padrino-helpers/output_helpers/haml_handler.rb +25 -0
  44. data/lib/padrino-helpers/output_helpers/slim_handler.rb +18 -0
  45. data/lib/padrino-helpers/render_helpers.rb +63 -0
  46. data/lib/padrino-helpers/tag_helpers.rb +294 -0
  47. data/lib/padrino-helpers/translation_helpers.rb +36 -0
  48. data/lib/padrino/rendering.rb +397 -0
  49. data/lib/padrino/rendering/erubis_template.rb +66 -0
  50. data/lib/padrino/rendering/haml_template.rb +26 -0
  51. data/lib/padrino/rendering/slim_template.rb +20 -0
  52. data/padrino-helpers.gemspec +29 -0
  53. data/test/fixtures/apps/.components +6 -0
  54. data/test/fixtures/apps/.gitignore +7 -0
  55. data/test/fixtures/apps/render.rb +25 -0
  56. data/test/fixtures/apps/views/article/comment/show.slim +1 -0
  57. data/test/fixtures/apps/views/blog/post.erb +1 -0
  58. data/test/fixtures/apps/views/layouts/specific.erb +1 -0
  59. data/test/fixtures/apps/views/test/post.erb +1 -0
  60. data/test/fixtures/layouts/layout.erb +1 -0
  61. data/test/fixtures/markup_app/app.rb +87 -0
  62. data/test/fixtures/markup_app/views/button_to.erb +8 -0
  63. data/test/fixtures/markup_app/views/button_to.haml +5 -0
  64. data/test/fixtures/markup_app/views/button_to.slim +6 -0
  65. data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
  66. data/test/fixtures/markup_app/views/capture_concat.haml +12 -0
  67. data/test/fixtures/markup_app/views/capture_concat.slim +12 -0
  68. data/test/fixtures/markup_app/views/content_for.erb +23 -0
  69. data/test/fixtures/markup_app/views/content_for.haml +19 -0
  70. data/test/fixtures/markup_app/views/content_for.slim +19 -0
  71. data/test/fixtures/markup_app/views/content_tag.erb +13 -0
  72. data/test/fixtures/markup_app/views/content_tag.haml +11 -0
  73. data/test/fixtures/markup_app/views/content_tag.slim +11 -0
  74. data/test/fixtures/markup_app/views/current_engine.erb +5 -0
  75. data/test/fixtures/markup_app/views/current_engine.haml +5 -0
  76. data/test/fixtures/markup_app/views/current_engine.slim +5 -0
  77. data/test/fixtures/markup_app/views/fields_for.erb +20 -0
  78. data/test/fixtures/markup_app/views/fields_for.haml +15 -0
  79. data/test/fixtures/markup_app/views/fields_for.slim +15 -0
  80. data/test/fixtures/markup_app/views/form_for.erb +72 -0
  81. data/test/fixtures/markup_app/views/form_for.haml +59 -0
  82. data/test/fixtures/markup_app/views/form_for.slim +59 -0
  83. data/test/fixtures/markup_app/views/form_tag.erb +95 -0
  84. data/test/fixtures/markup_app/views/form_tag.haml +78 -0
  85. data/test/fixtures/markup_app/views/form_tag.slim +79 -0
  86. data/test/fixtures/markup_app/views/link_to.erb +5 -0
  87. data/test/fixtures/markup_app/views/link_to.haml +4 -0
  88. data/test/fixtures/markup_app/views/link_to.slim +4 -0
  89. data/test/fixtures/markup_app/views/mail_to.erb +3 -0
  90. data/test/fixtures/markup_app/views/mail_to.haml +3 -0
  91. data/test/fixtures/markup_app/views/mail_to.slim +3 -0
  92. data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
  93. data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
  94. data/test/fixtures/markup_app/views/meta_tag.slim +3 -0
  95. data/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
  96. data/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
  97. data/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
  98. data/test/fixtures/markup_app/views/simple_partial.erb +1 -0
  99. data/test/fixtures/markup_app/views/simple_partial.haml +1 -0
  100. data/test/fixtures/markup_app/views/simple_partial.slim +1 -0
  101. data/test/fixtures/render_app/app.rb +94 -0
  102. data/test/fixtures/render_app/views/_deep.erb +3 -0
  103. data/test/fixtures/render_app/views/_deep.haml +2 -0
  104. data/test/fixtures/render_app/views/_deep.slim +2 -0
  105. data/test/fixtures/render_app/views/_partial_block_erb.erb +10 -0
  106. data/test/fixtures/render_app/views/_partial_block_haml.haml +7 -0
  107. data/test/fixtures/render_app/views/_partial_block_slim.slim +7 -0
  108. data/test/fixtures/render_app/views/_unsafe.html.builder +2 -0
  109. data/test/fixtures/render_app/views/_unsafe_object.html.builder +2 -0
  110. data/test/fixtures/render_app/views/current_engine.haml +5 -0
  111. data/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
  112. data/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
  113. data/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
  114. data/test/fixtures/render_app/views/double_capture_erb.erb +3 -0
  115. data/test/fixtures/render_app/views/double_capture_haml.haml +2 -0
  116. data/test/fixtures/render_app/views/double_capture_slim.slim +2 -0
  117. data/test/fixtures/render_app/views/erb/test.erb +1 -0
  118. data/test/fixtures/render_app/views/explicit_engine.haml +5 -0
  119. data/test/fixtures/render_app/views/haml/test.haml +1 -0
  120. data/test/fixtures/render_app/views/render_block_erb.erb +5 -0
  121. data/test/fixtures/render_app/views/render_block_haml.haml +4 -0
  122. data/test/fixtures/render_app/views/render_block_slim.slim +4 -0
  123. data/test/fixtures/render_app/views/ruby_block_capture_erb.erb +1 -0
  124. data/test/fixtures/render_app/views/ruby_block_capture_haml.haml +1 -0
  125. data/test/fixtures/render_app/views/ruby_block_capture_slim.slim +1 -0
  126. data/test/fixtures/render_app/views/template/_user.haml +7 -0
  127. data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
  128. data/test/fixtures/render_app/views/template/some_template.haml +2 -0
  129. data/test/fixtures/render_app/views/wrong_capture_erb.erb +3 -0
  130. data/test/fixtures/render_app/views/wrong_capture_haml.haml +2 -0
  131. data/test/fixtures/render_app/views/wrong_capture_slim.slim +2 -0
  132. data/test/helper.rb +131 -0
  133. data/test/test_asset_tag_helpers.rb +406 -0
  134. data/test/test_form_builder.rb +1216 -0
  135. data/test/test_form_helpers.rb +1056 -0
  136. data/test/test_format_helpers.rb +251 -0
  137. data/test/test_helpers.rb +10 -0
  138. data/test/test_locale.rb +20 -0
  139. data/test/test_number_helpers.rb +142 -0
  140. data/test/test_output_helpers.rb +157 -0
  141. data/test/test_render_helpers.rb +215 -0
  142. data/test/test_rendering.rb +694 -0
  143. data/test/test_rendering_extensions.rb +14 -0
  144. data/test/test_tag_helpers.rb +131 -0
  145. metadata +241 -0
@@ -0,0 +1,1056 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
+
4
+ describe "FormHelpers" do
5
+ include Padrino::Helpers::FormHelpers
6
+
7
+ def app
8
+ MarkupDemo
9
+ end
10
+
11
+ class UnprotectedApp
12
+ def protect_from_csrf; false; end
13
+ end
14
+
15
+ describe 'for #form_tag method' do
16
+ it 'should display correct forms in ruby' do
17
+ actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test', :method => "post") { "Demo" }
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
+ end
21
+
22
+ it 'should display correct text inputs within form_tag' do
23
+ actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test') { text_field_tag(:username) }
24
+ assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
25
+ end
26
+
27
+ it 'should display correct form with remote' do
28
+ actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :remote => true) { "Demo" }
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 }
31
+ end
32
+
33
+ it 'should display correct form with remote and method is put' do
34
+ actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :method => 'put', :remote => true) { "Demo" }
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 }
37
+ end
38
+
39
+ it 'should display correct form with method :put' do
40
+ actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :method => "put") { "Demo" }
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 }
43
+ end
44
+
45
+ it 'should display correct form with method :delete and charset' do
46
+ actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :class => 'delete-form', :method => "delete") { "Demo" }
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 }
49
+ end
50
+
51
+ it 'should display correct form with charset' do
52
+ actual_html = form_tag('/charset', :"accept-charset" => "UTF-8", :class => 'charset-form') { "Demo" }
53
+ assert_has_tag(:form, :class => "charset-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
54
+ end
55
+
56
+ it 'should display correct form with multipart encoding' do
57
+ actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
58
+ assert_has_tag(:form, :enctype => "multipart/form-data") { actual_html }
59
+ end
60
+
61
+ it 'should have an authenticity_token for method :post, :put or :delete' do
62
+ %w(post put delete).each do |method|
63
+ actual_html = form_tag('/modify', :method => method) { "Demo" }
64
+ assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
65
+ end
66
+ end
67
+
68
+ it 'should not have an authenticity_token if method: :get' do
69
+ actual_html = form_tag('/get', :method => :get) { "Demo" }
70
+ assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
71
+ end
72
+
73
+ it 'should have an authenticity_token by default' do
74
+ actual_html = form_tag('/superadmindelete') { "Demo" }
75
+ assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
76
+ end
77
+
78
+ it 'should create csrf meta tags with token and param - #csrf_meta_tags' do
79
+ actual_html = csrf_meta_tags
80
+ assert_has_tag(:meta, :name => 'csrf-param') { actual_html }
81
+ assert_has_tag(:meta, :name => 'csrf-token') { actual_html }
82
+ end
83
+
84
+ it 'should have an authenticity_token by default' do
85
+ actual_html = form_tag('/superadmindelete') { "Demo" }
86
+ assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
87
+ end
88
+
89
+ it 'should not have an authenticity_token if passing protect_from_csrf: false' do
90
+ actual_html = form_tag('/superadmindelete', :protect_from_csrf => false) { "Demo" }
91
+ assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
92
+ end
93
+
94
+ it 'should not have an authenticity_token if protect_from_csrf is false on app settings' do
95
+ self.expects(:settings).returns(UnprotectedApp.new)
96
+ actual_html = form_tag('/superadmindelete') { "Demo" }
97
+ assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
98
+ end
99
+
100
+ it 'should not include protect_from_csrf as an attribute of form element' do
101
+ actual_html = form_tag('/superadmindelete', :protect_from_csrf => true){ "Demo" }
102
+ assert_has_no_tag(:form, protect_from_csrf: "true"){ actual_html }
103
+ end
104
+
105
+ it 'should display correct forms in erb' do
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'
111
+ end
112
+
113
+ it 'should display correct forms in haml' do
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'
119
+ end
120
+
121
+ it 'should display correct forms in slim' do
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'
127
+ end
128
+ end
129
+
130
+ describe 'for #field_set_tag method' do
131
+ it 'should display correct field_sets in ruby' do
132
+ actual_html = field_set_tag("Basic", :class => 'basic') { "Demo" }
133
+ assert_has_tag(:fieldset, :class => 'basic') { actual_html }
134
+ assert_has_tag('fieldset legend', :content => "Basic") { actual_html }
135
+ end
136
+
137
+ it 'should display correct field_sets in erb' do
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"
143
+ end
144
+
145
+ it 'should display correct field_sets in haml' do
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"
151
+ end
152
+
153
+ it 'should display correct field_sets in slim' do
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"
159
+ end
160
+ end
161
+
162
+ describe 'for #error_messages_for method' do
163
+ it 'should display correct error messages list in ruby' do
164
+ user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
165
+ actual_html = error_messages_for(user)
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 }
171
+ end
172
+
173
+ it 'should display correct error messages list in erb' do
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"
185
+ end
186
+
187
+ it 'should display correct error messages list in haml' do
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"
199
+ end
200
+
201
+ it 'should display correct error messages list in slim' do
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"
213
+ end
214
+ end
215
+
216
+ describe 'for #error_message_on method' do
217
+ it 'should display correct error message on specified model name in ruby' do
218
+ @user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
219
+ actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
220
+ assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
221
+ end
222
+
223
+ it 'should display correct error message on specified object in ruby' do
224
+ @bob = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
225
+ actual_html = error_message_on(@bob, :a, :prepend => "foo", :append => "bar")
226
+ assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
227
+ end
228
+
229
+ it 'should display no message when error is not present' do
230
+ @user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
231
+ actual_html = error_message_on(:user, :fake, :prepend => "foo", :append => "bar")
232
+ assert actual_html.blank?
233
+ end
234
+
235
+ it 'should display no message when error is not present in an Array' do
236
+ @user = mock_model("User", :errors => { :a => [], :b => "2" }, :blank? => false)
237
+ actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
238
+ assert actual_html.blank?
239
+ end
240
+ end
241
+
242
+ describe 'for #label_tag method' do
243
+ it 'should display label tag in ruby' do
244
+ actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
245
+ assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname") { actual_html }
246
+ end
247
+
248
+ it 'should display label tag in ruby with required' do
249
+ actual_html = label_tag(:username, :caption => "Nickname", :required => true)
250
+ assert_has_tag(:label, :for => 'username', :content => 'Nickname') { actual_html }
251
+ assert_has_tag('label[for=username] span.required', :content => "*") { actual_html }
252
+ end
253
+
254
+ it 'should display label tag in ruby with a block' do
255
+ actual_html = label_tag(:admin, :class => 'long-label') { input_tag :checkbox }
256
+ assert_has_tag(:label, :for => 'admin', :class => 'long-label', :content => "Admin") { actual_html }
257
+ assert_has_tag('label input[type=checkbox]') { actual_html }
258
+ end
259
+
260
+ it 'should display label tag in erb for simple form' do
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'
266
+ end
267
+
268
+ it 'should display label tag in erb for advanced form' do
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'
276
+ end
277
+
278
+ it 'should display label tag in haml for simple form' do
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'
284
+ end
285
+
286
+ it 'should display label tag in haml for advanced form' do
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'
294
+ end
295
+
296
+ it 'should display label tag in slim for simple form' do
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'
302
+ end
303
+
304
+ it 'should display label tag in slim for advanced form' do
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'
312
+ end
313
+ end
314
+
315
+ describe 'for #hidden_field_tag method' do
316
+ it 'should display hidden field in ruby' do
317
+ actual_html = hidden_field_tag(:session_key, :id => 'session_id', :value => '56768')
318
+ assert_has_tag(:input, :type => 'hidden', :id => "session_id", :name => 'session_key', :value => '56768') { actual_html }
319
+ end
320
+
321
+ it 'should display hidden field in erb' do
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__"
325
+ end
326
+
327
+ it 'should display hidden field in haml' do
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__"
331
+ end
332
+
333
+ it 'should display hidden field in slim' do
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__"
337
+ end
338
+ end
339
+
340
+ describe 'for #text_field_tag method' do
341
+ it 'should display text field in ruby' do
342
+ actual_html = text_field_tag(:username, :class => 'long')
343
+ assert_has_tag(:input, :type => 'text', :class => "long", :name => 'username') { actual_html }
344
+ end
345
+
346
+ it 'should display text field in erb' do
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'
350
+ end
351
+
352
+ it 'should display text field in haml' do
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'
356
+ end
357
+
358
+ it 'should display text field in slim' do
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'
362
+ end
363
+ end
364
+
365
+ describe 'for #number_field_tag method' do
366
+ it 'should display number field in ruby' do
367
+ actual_html = number_field_tag(:age, :class => 'numeric')
368
+ assert_has_tag(:input, :type => 'number', :class => 'numeric', :name => 'age') { actual_html }
369
+ end
370
+
371
+ it 'should display number field in erb' do
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'
375
+ end
376
+
377
+ it 'should display number field in haml' do
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'
381
+ end
382
+
383
+ it 'should display number field in slim' do
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'
387
+ end
388
+ end
389
+
390
+ describe 'for #telephone_field_tag method' do
391
+ it 'should display number field in ruby' do
392
+ actual_html = telephone_field_tag(:telephone, :class => 'numeric')
393
+ assert_has_tag(:input, :type => 'tel', :class => 'numeric', :name => 'telephone') { actual_html }
394
+ end
395
+
396
+ it 'should display telephone field in erb' do
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'
400
+ end
401
+
402
+ it 'should display telephone field in haml' do
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'
406
+ end
407
+
408
+ it 'should display telephone field in slim' do
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'
412
+ end
413
+ end
414
+
415
+ describe 'for #search_field_tag method' do
416
+ it 'should display search field in ruby' do
417
+ actual_html = search_field_tag(:search, :class => 'string')
418
+ assert_has_tag(:input, :type => 'search', :class => 'string', :name => 'search') { actual_html }
419
+ end
420
+
421
+ it 'should display search field in erb' do
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'
425
+ end
426
+
427
+ it 'should display search field in haml' do
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'
431
+ end
432
+
433
+ it 'should display search field in slim' do
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'
437
+ end
438
+ end
439
+
440
+ describe 'for #email_field_tag method' do
441
+ it 'should display email field in ruby' do
442
+ actual_html = email_field_tag(:email, :class => 'string')
443
+ assert_has_tag(:input, :type => 'email', :class => 'string', :name => 'email') { actual_html }
444
+ end
445
+
446
+ it 'should display email field in erb' do
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'
450
+ end
451
+
452
+ it 'should display email field in haml' do
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'
456
+ end
457
+
458
+ it 'should display email field in slim' do
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'
462
+ end
463
+ end
464
+
465
+ describe 'for #url_field_tag method' do
466
+ it 'should display url field in ruby' do
467
+ actual_html = url_field_tag(:webpage, :class => 'string')
468
+ assert_has_tag(:input, :type => 'url', :class => 'string', :name => 'webpage') { actual_html }
469
+ end
470
+
471
+ it 'should display url field in erb' do
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'
475
+ end
476
+
477
+ it 'should display url field in haml' do
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'
481
+ end
482
+
483
+ it 'should display url field in slim' do
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'
487
+ end
488
+ end
489
+
490
+ describe 'for #text_area_tag method' do
491
+ it 'should display text area in ruby' do
492
+ actual_html = text_area_tag(:about, :class => 'long')
493
+ assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
494
+ end
495
+
496
+ it 'should display text area in ruby with specified content' do
497
+ actual_html = text_area_tag(:about, :value => "a test", :rows => 5, :cols => 6)
498
+ assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
499
+ end
500
+
501
+ it 'should insert newline to before of content' do
502
+ actual_html = text_area_tag(:about, :value => "\na test")
503
+ assert_has_tag(:textarea, :content => "\na test", :name => 'about') { actual_html }
504
+ assert_match(%r{<textarea[^>]*>\n\na test</textarea>}, actual_html)
505
+ end
506
+
507
+ it 'should display text area in erb' do
508
+ visit '/erb/form_tag'
509
+ assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
510
+ end
511
+
512
+ it 'should display text area in haml' do
513
+ visit '/haml/form_tag'
514
+ assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
515
+ end
516
+
517
+ it 'should display text area in slim' do
518
+ visit '/slim/form_tag'
519
+ assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
520
+ end
521
+ end
522
+
523
+ describe 'for #password_field_tag method' do
524
+ it 'should display password field in ruby' do
525
+ actual_html = password_field_tag(:password, :class => 'long')
526
+ assert_has_tag(:input, :type => 'password', :class => "long", :name => 'password') { actual_html }
527
+ end
528
+
529
+ it 'should display password field in erb' do
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'
533
+ end
534
+
535
+ it 'should display password field in haml' do
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'
539
+ end
540
+
541
+ it 'should display password field in slim' do
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'
545
+ end
546
+ end
547
+
548
+ describe 'for #file_field_tag method' do
549
+ it 'should display file field in ruby' do
550
+ actual_html = file_field_tag(:photo, :class => 'photo')
551
+ assert_has_tag(:input, :type => 'file', :class => "photo", :name => 'photo') { actual_html }
552
+ end
553
+
554
+ it 'should have an array name with multiple option' do
555
+ actual_html = file_field_tag(:photos, :multiple => true)
556
+ assert_has_tag(:input, :name => 'photos[]') { actual_html }
557
+ end
558
+
559
+ it 'should display file field in erb' do
560
+ visit '/erb/form_tag'
561
+ assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
562
+ end
563
+
564
+ it 'should display file field in haml' do
565
+ visit '/haml/form_tag'
566
+ assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
567
+ end
568
+
569
+ it 'should display file field in slim' do
570
+ visit '/slim/form_tag'
571
+ assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
572
+ end
573
+ end
574
+
575
+ describe "for #check_box_tag method" do
576
+ it 'should display check_box tag in ruby' do
577
+ actual_html = check_box_tag("clear_session")
578
+ assert_has_tag(:input, :type => 'checkbox', :value => '1', :name => 'clear_session') { actual_html }
579
+ assert_has_no_tag(:input, :type => 'hidden') { actual_html }
580
+ end
581
+
582
+ it 'should display check_box tag in ruby with extended attributes' do
583
+ actual_html = check_box_tag("clear_session", :disabled => true, :checked => true)
584
+ assert_has_tag(:input, :type => 'checkbox', :disabled => 'disabled', :checked => 'checked') { actual_html }
585
+ end
586
+
587
+ it 'should display check_box tag in erb' do
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'
591
+ end
592
+
593
+ it 'should display check_box tag in haml' do
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'
597
+ end
598
+
599
+ it 'should display check_box tag in slim' do
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'
603
+ end
604
+ end
605
+
606
+ describe "for #radio_button_tag method" do
607
+ it 'should display radio_button tag in ruby' do
608
+ actual_html = radio_button_tag("gender", :value => 'male')
609
+ assert_has_tag(:input, :type => 'radio', :value => 'male', :name => 'gender') { actual_html }
610
+ end
611
+
612
+ it 'should display radio_button tag in ruby with extended attributes' do
613
+ actual_html = radio_button_tag("gender", :disabled => true, :checked => true)
614
+ assert_has_tag(:input, :type => 'radio', :disabled => 'disabled', :checked => 'checked') { actual_html }
615
+ end
616
+
617
+ it 'should display radio_button tag in erb' do
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"
623
+ end
624
+
625
+ it 'should display radio_button tag in haml' do
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"
631
+ end
632
+
633
+ it 'should display radio_button tag in slim' do
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"
639
+ end
640
+ end
641
+
642
+ describe "for #select_tag method" do
643
+ it 'should display select tag in ruby' do
644
+ actual_html = select_tag(:favorite_color, :options => ['green', 'blue', 'black'], :include_blank => true)
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 }
650
+ end
651
+
652
+ it 'should display select tag in ruby with extended attributes' do
653
+ actual_html = select_tag(:favorite_color, :disabled => true, :options => ['only', 'option'])
654
+ assert_has_tag(:select, :disabled => 'disabled') { actual_html }
655
+ end
656
+
657
+ it 'should take a range as a collection for options' do
658
+ actual_html = select_tag(:favorite_color, :options => (1..3))
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 }
663
+ end
664
+
665
+ it 'should include blank for grouped options' do
666
+ opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
667
+ actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => true )
668
+ assert_has_tag('select option:first-child', :value => "", :content => "") { actual_html }
669
+ end
670
+
671
+ it 'should include blank as caption' do
672
+ opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
673
+ actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => 'Choose your destiny' )
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 }
676
+ end
677
+
678
+ it 'should display select tag with grouped options for a nested array' do
679
+ opts = [
680
+ ["Friends",["Yoda",["Obiwan",2]]],
681
+ ["Enemies", ["Palpatine",['Darth Vader',3]]]
682
+ ]
683
+ actual_html = select_tag( 'name', :grouped_options => opts )
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 }
691
+ end
692
+
693
+ it 'should display select tag with grouped options for a nested array and accept disabled groups' do
694
+ opts = [
695
+ ["Friends",["Yoda",["Obiwan",2]]],
696
+ ["Enemies", ["Palpatine",['Darth Vader',3]], {:disabled => true}]
697
+ ]
698
+ actual_html = select_tag( 'name', :grouped_options => opts )
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 }
703
+ end
704
+
705
+ it 'should display select tag with grouped options for a nested array and accept disabled groups and/or with disabled options' do
706
+ opts = [
707
+ ["Friends",["Yoda",["Obiwan",2, {:disabled => true}]]],
708
+ ["Enemies", [["Palpatine", "Palpatine", {:disabled => true}],['Darth Vader',3]], {:disabled => true}]
709
+ ]
710
+ actual_html = select_tag( 'name', :grouped_options => opts )
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 }
717
+ end
718
+
719
+ it 'should display select tag with grouped options for a hash' do
720
+ opts = {
721
+ "Friends" => ["Yoda",["Obiwan",2]],
722
+ "Enemies" => ["Palpatine",['Darth Vader',3]]
723
+ }
724
+ actual_html = select_tag( 'name', :grouped_options => opts )
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 }
732
+ end
733
+
734
+ it 'should display select tag with grouped options for a hash and accept disabled groups and/or with disabled options' do
735
+ opts = {
736
+ "Friends" => ["Yoda",["Obiwan",2,{:disabled => true}]],
737
+ "Enemies" => [["Palpatine","Palpatine",{:disabled => true}],["Darth Vader",3], {:disabled => true}]
738
+ }
739
+ actual_html = select_tag( 'name', :grouped_options => opts )
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 }
746
+ end
747
+
748
+ it 'should display select tag with grouped options for a rails-style attribute hash' do
749
+ opts = {
750
+ "Friends" => ["Yoda",["Obiwan",2,{:magister=>'no'}],{:lame=>'yes'}],
751
+ "Enemies" => [["Palpatine","Palpatine",{:scary=>'yes',:old=>'yes'}],["Darth Vader",3,{:disabled=>true}]]
752
+ }
753
+ actual_html = select_tag( 'name', :grouped_options => opts, :disabled_options => [2], :selected => ['Yoda'] )
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 }
759
+ end
760
+
761
+ it 'should display select tag in ruby with multiple attribute' do
762
+ actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option'])
763
+ assert_has_tag(:select, :multiple => 'multiple', :name => 'favorite_color[]') { actual_html }
764
+ end
765
+
766
+ it 'should display options with values and single selected' do
767
+ options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
768
+ actual_html = select_tag(:favorite_color, :options => options, :selected => 'green1')
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 }
774
+ end
775
+
776
+ it 'should display options with values and accept disabled options' do
777
+ options = [['Green', 'green1', {:disabled => true}], ['Blue', 'blue1'], ['Black', "black1"]]
778
+ actual_html = select_tag(:favorite_color, :options => options)
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 }
784
+ end
785
+
786
+ it 'should display option with values and multiple selected' do
787
+ options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
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 }
794
+ end
795
+
796
+ it 'should not misselect options with default value' do
797
+ options = ['Green', 'Blue']
798
+ actual_html = select_tag(:favorite_color, :options => options, :selected => ['Green', ''])
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 }
801
+ end
802
+
803
+ it 'should display options selected only for exact match' do
804
+ options = [['One', '1'], ['1', '10'], ['Two', "-1"]]
805
+ actual_html = select_tag(:range, :options => options, :selected => '-1')
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 }
809
+ end
810
+
811
+ it 'should display select tag in erb' do
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')
831
+ end
832
+
833
+ it 'should display select tag in haml' do
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')
853
+ end
854
+
855
+ it 'should display select tag in slim' do
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')
875
+ end
876
+ end
877
+
878
+ describe 'for #submit_tag method' do
879
+ it 'should display submit tag in ruby' do
880
+ actual_html = submit_tag("Update", :class => 'success')
881
+ assert_has_tag(:input, :type => 'submit', :class => "success", :value => 'Update') { actual_html }
882
+ end
883
+
884
+ it 'should display submit tag in erb' do
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"
888
+ end
889
+
890
+ it 'should display submit tag in haml' do
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"
894
+ end
895
+
896
+ it 'should display submit tag in slim' do
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"
900
+ end
901
+
902
+ describe 'for omitted args' do
903
+ it 'should display submit tag with default caption' do
904
+ actual_html = submit_tag()
905
+ assert_has_tag(:input, :type => 'submit', :value => 'Submit') { actual_html }
906
+ end
907
+ end
908
+
909
+ describe 'for omitted caption arg' do
910
+ it 'should display submit tag with default caption' do
911
+ actual_html = submit_tag(:class => 'success')
912
+ assert_has_tag(:input, :type => 'submit', :class => 'success', :value => 'Submit') { actual_html }
913
+ end
914
+
915
+ it 'should display submit tag without caption value when nil' do
916
+ actual_html = submit_tag(nil, :class => 'success')
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 }
919
+ end
920
+ end
921
+ end
922
+
923
+ describe 'for #button_tag method' do
924
+ it 'should display submit tag in ruby' do
925
+ actual_html = button_tag("Cancel", :class => 'clear')
926
+ assert_has_tag(:input, :type => 'button', :class => "clear", :value => 'Cancel') { actual_html }
927
+ end
928
+
929
+ it 'should display submit tag in erb' do
930
+ visit '/erb/form_tag'
931
+ assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
932
+ end
933
+
934
+ it 'should display submit tag in haml' do
935
+ visit '/haml/form_tag'
936
+ assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
937
+ end
938
+
939
+ it 'should display submit tag in slim' do
940
+ visit '/slim/form_tag'
941
+ assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
942
+ end
943
+ end
944
+
945
+ describe 'for #image_submit_tag method' do
946
+ before do
947
+ @stamp = stop_time_for_test.to_i
948
+ end
949
+
950
+ it 'should display image submit tag in ruby with relative path' do
951
+ actual_html = image_submit_tag('buttons/ok.png', :class => 'success')
952
+ assert_has_tag(:input, :type => 'image', :class => "success", :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
953
+ end
954
+
955
+ it 'should display image submit tag in ruby with absolute path' do
956
+ actual_html = image_submit_tag('/system/ok.png', :class => 'success')
957
+ assert_has_tag(:input, :type => 'image', :class => "success", :src => "/system/ok.png") { actual_html }
958
+ end
959
+
960
+ it 'should display image submit tag in erb' do
961
+ visit '/erb/form_tag'
962
+ assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
963
+ end
964
+
965
+ it 'should display image submit tag in haml' do
966
+ visit '/haml/form_tag'
967
+ assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
968
+ end
969
+
970
+ it 'should display image submit tag in slim' do
971
+ visit '/slim/form_tag'
972
+ assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
973
+ end
974
+ end
975
+
976
+ describe 'for #button_to method' do
977
+ it 'should have a form and set the method properly' do
978
+ actual_html = button_to('Delete', '/users/1', :method => :delete)
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 }
982
+ end
983
+
984
+ it 'should add a submit button by default if no content is specified' do
985
+ actual_html = button_to('My Delete Button', '/users/1', :method => :delete)
986
+ assert_has_tag('form input', :type => 'submit', :value => 'My Delete Button') { actual_html }
987
+ end
988
+
989
+ it 'should set specific content inside the form if a block was sent' do
990
+ actual_html = button_to('My Delete Button', '/users/1', :method => :delete) do
991
+ content_tag :button, "My button's content", :type => :submit, :title => "My button"
992
+ end
993
+ assert_has_tag('form button', :type => 'submit', :content => "My button's content", :title => "My button") { actual_html }
994
+ end
995
+
996
+ it 'should pass options on submit button when submit_options are given' do
997
+ actual_html = button_to("Fancy button", '/users/1', :submit_options => { :class => :fancy })
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 }
1000
+ end
1001
+
1002
+ it 'should display correct button_to in erb' do
1003
+ visit '/erb/button_to'
1004
+ assert_have_selector('form', :action => '/foo')
1005
+ assert_have_selector('form 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')
1008
+ end
1009
+
1010
+ it 'should display correct button_to in haml' do
1011
+ visit '/haml/button_to'
1012
+ assert_have_selector('form', :action => '/foo')
1013
+ assert_have_selector('form 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')
1016
+ end
1017
+
1018
+ it 'should display correct button_to in slim' do
1019
+ visit '/slim/button_to'
1020
+ assert_have_selector('form', :action => '/foo')
1021
+ assert_have_selector('form 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')
1024
+ end
1025
+ end
1026
+
1027
+ describe 'for #range_field_tag' do
1028
+ it 'should create an input tag with min and max options' do
1029
+ actual_html = range_field_tag('ranger', :min => 20, :max => 50)
1030
+ assert_has_tag('input', :type => 'range', :name => 'ranger', :min => '20', :max => '50') { actual_html }
1031
+ end
1032
+
1033
+ it 'should create an input tag with range' do
1034
+ actual_html = range_field_tag('ranger', :range => 1..20)
1035
+ assert_has_tag('input', :min => '1', :max => '20') { actual_html }
1036
+ end
1037
+
1038
+ it 'should display correct range_field_tag in erb' do
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
1042
+ end
1043
+
1044
+ it 'should display correct range_field_tag in haml' do
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
1048
+ end
1049
+
1050
+ it 'should display correct range_field_tag in slim' do
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
1054
+ end
1055
+ end
1056
+ end