tennpipes-helper 3.6.6

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/LICENSE.txt +20 -0
  3. data/README.rdoc +239 -0
  4. data/Rakefile +1 -0
  5. data/lib/tennpipes-helper.rb +62 -0
  6. data/lib/tennpipes-helper/asset_tag_helpers.rb +394 -0
  7. data/lib/tennpipes-helper/form_builder/abstract_form_builder.rb +279 -0
  8. data/lib/tennpipes-helper/form_builder/standard_form_builder.rb +40 -0
  9. data/lib/tennpipes-helper/form_helpers.rb +639 -0
  10. data/lib/tennpipes-helper/form_helpers/errors.rb +138 -0
  11. data/lib/tennpipes-helper/form_helpers/options.rb +98 -0
  12. data/lib/tennpipes-helper/form_helpers/security.rb +70 -0
  13. data/lib/tennpipes-helper/format_helpers.rb +372 -0
  14. data/lib/tennpipes-helper/locale/cs.yml +103 -0
  15. data/lib/tennpipes-helper/locale/da.yml +91 -0
  16. data/lib/tennpipes-helper/locale/de.yml +81 -0
  17. data/lib/tennpipes-helper/locale/en.yml +103 -0
  18. data/lib/tennpipes-helper/locale/es.yml +103 -0
  19. data/lib/tennpipes-helper/locale/fr.yml +79 -0
  20. data/lib/tennpipes-helper/locale/hu.yml +103 -0
  21. data/lib/tennpipes-helper/locale/it.yml +89 -0
  22. data/lib/tennpipes-helper/locale/ja.yml +103 -0
  23. data/lib/tennpipes-helper/locale/lv.yml +103 -0
  24. data/lib/tennpipes-helper/locale/nl.yml +82 -0
  25. data/lib/tennpipes-helper/locale/no.yml +91 -0
  26. data/lib/tennpipes-helper/locale/pl.yml +95 -0
  27. data/lib/tennpipes-helper/locale/pt_br.yml +103 -0
  28. data/lib/tennpipes-helper/locale/ro.yml +103 -0
  29. data/lib/tennpipes-helper/locale/ru.yml +103 -0
  30. data/lib/tennpipes-helper/locale/sv.yml +103 -0
  31. data/lib/tennpipes-helper/locale/tr.yml +103 -0
  32. data/lib/tennpipes-helper/locale/uk.yml +103 -0
  33. data/lib/tennpipes-helper/locale/zh_cn.yml +103 -0
  34. data/lib/tennpipes-helper/locale/zh_tw.yml +103 -0
  35. data/lib/tennpipes-helper/number_helpers.rb +283 -0
  36. data/lib/tennpipes-helper/output_helpers.rb +226 -0
  37. data/lib/tennpipes-helper/output_helpers/abstract_handler.rb +61 -0
  38. data/lib/tennpipes-helper/output_helpers/erb_handler.rb +27 -0
  39. data/lib/tennpipes-helper/output_helpers/haml_handler.rb +25 -0
  40. data/lib/tennpipes-helper/output_helpers/slim_handler.rb +18 -0
  41. data/lib/tennpipes-helper/render_helpers.rb +63 -0
  42. data/lib/tennpipes-helper/tag_helpers.rb +294 -0
  43. data/lib/tennpipes-helper/translation_helpers.rb +36 -0
  44. data/lib/tennpipes/rendering.rb +369 -0
  45. data/lib/tennpipes/rendering/erb_template.rb +40 -0
  46. data/lib/tennpipes/rendering/erubis_template.rb +66 -0
  47. data/lib/tennpipes/rendering/haml_template.rb +26 -0
  48. data/lib/tennpipes/rendering/slim_template.rb +20 -0
  49. data/test/fixtures/apps/render.rb +25 -0
  50. data/test/fixtures/apps/views/article/comment/show.slim +1 -0
  51. data/test/fixtures/apps/views/blog/post.erb +1 -0
  52. data/test/fixtures/apps/views/layouts/specific.erb +1 -0
  53. data/test/fixtures/apps/views/test/post.erb +1 -0
  54. data/test/fixtures/layouts/layout.erb +1 -0
  55. data/test/fixtures/markup_app/app.rb +87 -0
  56. data/test/fixtures/markup_app/views/button_to.erb +8 -0
  57. data/test/fixtures/markup_app/views/button_to.haml +5 -0
  58. data/test/fixtures/markup_app/views/button_to.slim +6 -0
  59. data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
  60. data/test/fixtures/markup_app/views/capture_concat.haml +12 -0
  61. data/test/fixtures/markup_app/views/capture_concat.slim +12 -0
  62. data/test/fixtures/markup_app/views/content_for.erb +23 -0
  63. data/test/fixtures/markup_app/views/content_for.haml +19 -0
  64. data/test/fixtures/markup_app/views/content_for.slim +19 -0
  65. data/test/fixtures/markup_app/views/content_tag.erb +13 -0
  66. data/test/fixtures/markup_app/views/content_tag.haml +11 -0
  67. data/test/fixtures/markup_app/views/content_tag.slim +11 -0
  68. data/test/fixtures/markup_app/views/current_engine.erb +5 -0
  69. data/test/fixtures/markup_app/views/current_engine.haml +5 -0
  70. data/test/fixtures/markup_app/views/current_engine.slim +5 -0
  71. data/test/fixtures/markup_app/views/fields_for.erb +20 -0
  72. data/test/fixtures/markup_app/views/fields_for.haml +15 -0
  73. data/test/fixtures/markup_app/views/fields_for.slim +15 -0
  74. data/test/fixtures/markup_app/views/form_for.erb +72 -0
  75. data/test/fixtures/markup_app/views/form_for.haml +59 -0
  76. data/test/fixtures/markup_app/views/form_for.slim +59 -0
  77. data/test/fixtures/markup_app/views/form_tag.erb +95 -0
  78. data/test/fixtures/markup_app/views/form_tag.haml +78 -0
  79. data/test/fixtures/markup_app/views/form_tag.slim +79 -0
  80. data/test/fixtures/markup_app/views/link_to.erb +5 -0
  81. data/test/fixtures/markup_app/views/link_to.haml +4 -0
  82. data/test/fixtures/markup_app/views/link_to.slim +4 -0
  83. data/test/fixtures/markup_app/views/mail_to.erb +3 -0
  84. data/test/fixtures/markup_app/views/mail_to.haml +3 -0
  85. data/test/fixtures/markup_app/views/mail_to.slim +3 -0
  86. data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
  87. data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
  88. data/test/fixtures/markup_app/views/meta_tag.slim +3 -0
  89. data/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
  90. data/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
  91. data/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
  92. data/test/fixtures/markup_app/views/simple_partial.erb +1 -0
  93. data/test/fixtures/markup_app/views/simple_partial.haml +1 -0
  94. data/test/fixtures/markup_app/views/simple_partial.slim +1 -0
  95. data/test/fixtures/render_app/app.rb +110 -0
  96. data/test/fixtures/render_app/views/_deep.erb +3 -0
  97. data/test/fixtures/render_app/views/_deep.haml +2 -0
  98. data/test/fixtures/render_app/views/_deep.slim +2 -0
  99. data/test/fixtures/render_app/views/_partial_block_erb.erb +10 -0
  100. data/test/fixtures/render_app/views/_partial_block_haml.haml +7 -0
  101. data/test/fixtures/render_app/views/_partial_block_slim.slim +7 -0
  102. data/test/fixtures/render_app/views/_unsafe.html.builder +2 -0
  103. data/test/fixtures/render_app/views/_unsafe_object.html.builder +2 -0
  104. data/test/fixtures/render_app/views/current_engine.haml +5 -0
  105. data/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
  106. data/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
  107. data/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
  108. data/test/fixtures/render_app/views/dive_inner_erb.erb +3 -0
  109. data/test/fixtures/render_app/views/dive_inner_haml.haml +2 -0
  110. data/test/fixtures/render_app/views/dive_inner_slim.slim +2 -0
  111. data/test/fixtures/render_app/views/dive_outer_erb.erb +3 -0
  112. data/test/fixtures/render_app/views/dive_outer_haml.haml +2 -0
  113. data/test/fixtures/render_app/views/dive_outer_slim.slim +2 -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 +88 -0
  133. data/test/test_asset_tag_helpers.rb +401 -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 +225 -0
  142. data/test/test_rendering.rb +706 -0
  143. data/test/test_rendering_extensions.rb +14 -0
  144. data/test/test_tag_helpers.rb +131 -0
  145. metadata +299 -0
@@ -0,0 +1,1216 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
+
4
+ describe "FormBuilder" do
5
+ include Tennpipes::Helpers::FormHelpers
6
+
7
+ def app
8
+ MarkupDemo
9
+ end
10
+
11
+ # Dummy form builder for testing
12
+ module Tennpipes::Helpers::FormBuilder
13
+ class FakeFormBuilder < AbstractFormBuilder
14
+ def foo_field; @template.content_tag(:span, "bar"); end
15
+ end
16
+ end
17
+
18
+ def setup
19
+ role_types = [mock_model('Role', :name => "Admin", :id => 1),
20
+ mock_model('Role', :name => 'Moderate', :id => 2), mock_model('Role', :name => 'Limited', :id => 3)]
21
+ @user = mock_model("User", :first_name => "Joe", :email => '', :session_id => 54)
22
+ @user.stubs(:errors => {:a => "must be present", :b => "must be valid", :email => "Must be valid", :first_name => []})
23
+ @user.stubs(:role_types => role_types, :role => "1", :roles => [1,3])
24
+ @user_none = mock_model("User")
25
+ end
26
+
27
+ def standard_builder(object=@user)
28
+ Tennpipes::Helpers::FormBuilder::StandardFormBuilder.new(self, object)
29
+ end
30
+
31
+ describe 'for #form_for method' do
32
+ it 'should display correct form html' do
33
+ actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { "Demo" }
34
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post', :content => "Demo") { actual_html }
35
+ assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
36
+ end
37
+
38
+ it 'should display correct form html with fake object' do
39
+ actual_html = form_for(:markup_user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
40
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post') { actual_html }
41
+ assert_has_tag('form input', :type => 'text', :name => 'markup_user[username]') { actual_html }
42
+ assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
43
+ end
44
+
45
+ it 'should display correct form html for namespaced object' do
46
+ actual_html = form_for(Outer::UserAccount.new, '/register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
47
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
48
+ assert_has_tag('form input', :type => 'text', :name => 'outer_user_account[username]') { actual_html }
49
+ end
50
+
51
+ it 'should display form specifying default builder setting' do
52
+ self.expects(:settings).returns(stub(:default_builder => 'FakeFormBuilder', :protect_from_csrf => false)).at_least_once
53
+ actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.foo_field }
54
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
55
+ assert_has_tag('span', :content => "bar") { actual_html }
56
+ end
57
+
58
+ it 'should display correct form html with remote option' do
59
+ actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true) { "Demo" }
60
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
61
+ end
62
+
63
+ it 'should display correct form html with namespace option' do
64
+ actual_html = form_for(@user, '/update', :namespace => 'foo') do |f|
65
+ f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
66
+ end
67
+
68
+ assert_has_no_tag(:form, :namespace => 'foo') { actual_html }
69
+ assert_has_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'foo_user_first_name') { actual_html }
70
+ assert_has_tag(:input, :type => 'text', :name => 'user[role_types_attributes][0][name]', :id => 'foo_user_role_types_attributes_0_name') { actual_html }
71
+ end
72
+
73
+ it 'should display correct form html with :as option' do
74
+ actual_html = form_for(@user, '/update', :as => :customer) do |f|
75
+ f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
76
+ end
77
+
78
+ assert_has_no_tag(:form, :as => 'customer') { actual_html }
79
+ assert_has_tag(:input, :type => 'text', :name => 'customer[first_name]', :id => 'customer_first_name') { actual_html }
80
+ assert_has_tag(:input, :type => 'text', :name => 'customer[role_types_attributes][0][name]', :id => 'customer_role_types_attributes_0_name') { actual_html }
81
+ end
82
+
83
+ it 'should display correct form html with remote option and method put' do
84
+ actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true, :method => 'put') { "Demo" }
85
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :method => 'post', "data-remote" => 'true') { actual_html }
86
+ assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
87
+ end
88
+
89
+ it 'should display correct form html with method :put' do
90
+ actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :method => 'put') { "Demo" }
91
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post') { actual_html }
92
+ assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
93
+ end
94
+
95
+ it 'should display correct form html with method :delete' do
96
+ actual_html = form_for(@user, '/destroy', :"accept-charset" => "UTF-8", :method => 'delete') { "Demo" }
97
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/destroy', :method => 'post') { actual_html }
98
+ assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
99
+ end
100
+
101
+ it 'should display correct form html with multipart' do
102
+ actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
103
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
104
+ end
105
+
106
+ it 'should support changing form builder type' do
107
+ form_html = proc { form_for(@user, '/register', :"accept-charset" => "UTF-8", :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
108
+ assert_raises(NoMethodError) { form_html.call }
109
+ end
110
+
111
+ it 'should support using default standard builder' do
112
+ actual_html = form_for(@user, '/register') { |f| f.text_field_block(:name) }
113
+ assert_has_tag('form p input[type=text]') { actual_html }
114
+ end
115
+
116
+ it 'should display fail for form with nil object' do
117
+ assert_raises(RuntimeError) { form_for(@not_real, '/register', :id => 'register', :method => 'post') { "Demo" } }
118
+ end
119
+
120
+ it 'should display correct form in haml' do
121
+ visit '/haml/form_for'
122
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
123
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
124
+ assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
125
+ assert_have_selector :input, :name => 'authenticity_token'
126
+ end
127
+
128
+ it 'should display correct form in erb' do
129
+ visit '/erb/form_for'
130
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
131
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
132
+ assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
133
+ assert_have_selector :input, :name => 'authenticity_token'
134
+ end
135
+
136
+ it 'should display correct form in slim' do
137
+ visit '/slim/form_for'
138
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
139
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
140
+ assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
141
+ assert_have_selector :input, :name => 'authenticity_token'
142
+ end
143
+
144
+ it 'should have a class of "invalid" for fields with errors' do
145
+ actual_html = form_for(@user, '/register') {|f| f.text_field(:email) }
146
+ assert_has_tag(:input, :type => 'text', :name => 'user[email]', :id => 'user_email', :class => 'invalid') {actual_html }
147
+ end
148
+
149
+ it 'should not have a class of "invalid" for fields with no errors' do
150
+ actual_html = form_for(@user, '/register') {|f| f.text_field(:first_name) }
151
+ assert_has_no_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name', :class => 'invalid') {actual_html }
152
+ end
153
+ end
154
+
155
+ describe 'for #fields_for method' do
156
+ it 'should display correct fields html' do
157
+ actual_html = fields_for(@user) { |f| f.text_field(:first_name) }
158
+ assert_has_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name') { actual_html }
159
+ end
160
+
161
+ it 'should display correct fields html with symbol object' do
162
+ actual_html = fields_for(:markup_user) { |f| f.text_field(:first_name) }
163
+ assert_has_tag(:input, :type => 'text', :name => 'markup_user[first_name]', :id => 'markup_user_first_name') { actual_html }
164
+ end
165
+
166
+ it 'should display fail for nil object' do
167
+ assert_raises(RuntimeError) { fields_for(@not_real) { |f| "Demo" } }
168
+ end
169
+
170
+ it 'should respect the builder of parent' do
171
+ assert_raises(NoMethodError) do
172
+ form_for(@user, '/register', builder: "AbstractFormBuilder") do |f|
173
+ f.fields_for(:role_types, @user.role_types) do |field|
174
+ field.submit_block "Submit"
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ it 'should display correct simple fields in haml' do
181
+ visit '/haml/fields_for'
182
+ assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
183
+ assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
184
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
185
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
186
+ end
187
+
188
+ it 'should display correct simple fields in erb' do
189
+ visit '/erb/fields_for'
190
+ assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
191
+ assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
192
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
193
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
194
+ end
195
+
196
+ it 'should display correct simple fields in slim' do
197
+ visit '/slim/fields_for'
198
+ assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
199
+ assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
200
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
201
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
202
+ end
203
+ end
204
+
205
+ # ===========================
206
+ # AbstractFormBuilder
207
+ # ===========================
208
+
209
+ describe 'for #error_messages method' do
210
+ it 'should display correct form html with no record' do
211
+ actual_html = standard_builder(@user_none).error_messages(:header_message => "Demo form cannot be saved")
212
+ assert actual_html.blank?
213
+ end
214
+
215
+ it 'should display correct form html with valid record' do
216
+ actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved", :style => "foo:bar", :class => "mine")
217
+ assert_has_tag('#field-errors h2', :content => "Demo form cannot be saved") { actual_html }
218
+ assert_has_tag('#field-errors ul li', :content => "B must be valid") { actual_html }
219
+ assert_has_tag('#field-errors ul li', :content => "A must be present") { actual_html }
220
+ assert_has_tag('#field-errors', :style => "foo:bar") { actual_html }
221
+ assert_has_tag('#field-errors', :class => "mine") { actual_html }
222
+ end
223
+
224
+ it 'should display correct form in haml' do
225
+ visit '/haml/form_for'
226
+ assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
227
+ assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
228
+ assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
229
+ assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
230
+ assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
231
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
232
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
233
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
234
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
235
+ end
236
+
237
+ it 'should display correct form in erb' do
238
+ visit '/erb/form_for'
239
+ assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
240
+ assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
241
+ assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
242
+ assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
243
+ assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
244
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
245
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
246
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
247
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
248
+ end
249
+
250
+ it 'should display correct form in slim' do
251
+ visit '/slim/form_for'
252
+ assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
253
+ assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
254
+ assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
255
+ assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
256
+ assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
257
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
258
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
259
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
260
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
261
+ end
262
+ end
263
+
264
+ describe 'for #error_message_on method' do
265
+ it 'should display correct form html with no record' do
266
+ actual_html = standard_builder(@user_none).error_message_on(:name)
267
+ assert actual_html.blank?
268
+ end
269
+
270
+ it 'should display error for specified invalid object' do
271
+ actual_html = standard_builder(@user).error_message_on(:a, :prepend => "foo", :append => "bar")
272
+ assert_has_tag('span.error', :content => "foo must be present bar") { actual_html }
273
+ end
274
+
275
+ it 'should display error for specified invalid object not matching class name' do
276
+ @bob = mock_model("User", :first_name => "Frank", :errors => { :foo => "must be bob" })
277
+ actual_html = standard_builder(@bob).error_message_on(:foo, :prepend => "foo", :append => "bar")
278
+ assert_has_tag('span.error', :content => "foo must be bob bar") { actual_html }
279
+ end
280
+ end
281
+
282
+ describe 'for #label method' do
283
+ it 'should display correct label html' do
284
+ actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name: ")
285
+ assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
286
+ assert_has_no_tag('label#user_first_name') { actual_html }
287
+ end
288
+
289
+ it 'should set specific content inside the label if a block was provided' do
290
+ actual_html = standard_builder.label(:admin, :class => 'large') { input_tag :checkbox }
291
+ assert_has_tag('label', :class => 'large', :for => 'user_admin', :content => "Admin: ") { actual_html }
292
+ assert_has_tag('label input[type=checkbox]') { actual_html }
293
+ end
294
+
295
+ it 'should display correct label in haml' do
296
+ visit '/haml/form_for'
297
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
298
+ assert_have_selector '#demo label', :content => "About Me: "
299
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
300
+ end
301
+
302
+ it 'should display correct label in erb' do
303
+ visit '/erb/form_for'
304
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
305
+ assert_have_selector '#demo label', :content => "About Me: "
306
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
307
+ end
308
+
309
+ it 'should display correct label in slim' do
310
+ visit '/slim/form_for'
311
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
312
+ assert_have_selector '#demo label', :content => "About Me: "
313
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
314
+ end
315
+ end
316
+
317
+ describe 'for #hidden_field method' do
318
+ it 'should display correct hidden field html' do
319
+ actual_html = standard_builder.hidden_field(:session_id, :class => 'hidden')
320
+ assert_has_tag('input.hidden[type=hidden]', :value => "54", :id => 'user_session_id', :name => 'user[session_id]') { actual_html }
321
+ end
322
+
323
+ it 'should display correct hidden field in haml' do
324
+ visit '/haml/form_for'
325
+ assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
326
+ assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
327
+ end
328
+
329
+ it 'should display correct hidden field in erb' do
330
+ visit '/erb/form_for'
331
+ assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
332
+ assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
333
+ end
334
+
335
+ it 'should display correct hidden field in slim' do
336
+ visit '/slim/form_for'
337
+ assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
338
+ assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
339
+ end
340
+ end
341
+
342
+ describe 'for #text_field method' do
343
+ it 'should display correct text field html' do
344
+ actual_html = standard_builder.text_field(:first_name, :class => 'large')
345
+ assert_has_tag('input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
346
+ end
347
+
348
+ it 'should display correct text field in haml' do
349
+ visit '/haml/form_for'
350
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
351
+ assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
352
+ end
353
+
354
+ it 'should display correct text field in erb' do
355
+ visit '/erb/form_for'
356
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
357
+ assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
358
+ end
359
+
360
+ it 'should display correct text field in slim' do
361
+ visit '/slim/form_for'
362
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
363
+ assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
364
+ end
365
+ end
366
+
367
+ describe 'for #number_field method' do
368
+ it 'should display correct number field html' do
369
+ actual_html = standard_builder.number_field(:age, :class => 'numeric')
370
+ assert_has_tag('input.numeric[type=number]', :id => 'user_age', :name => 'user[age]') { actual_html }
371
+ end
372
+
373
+ it 'should display correct number field in haml' do
374
+ visit '/haml/form_for'
375
+ assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
376
+ end
377
+
378
+ it 'should display correct number field in erb' do
379
+ visit '/erb/form_for'
380
+ assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
381
+ end
382
+
383
+ it 'should display correct number field in slim' do
384
+ visit '/slim/form_for'
385
+ assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
386
+ end
387
+ end
388
+
389
+ describe 'for #telephone_field method' do
390
+ it 'should display correct telephone field html' do
391
+ actual_html = standard_builder.telephone_field(:telephone, :class => 'numeric')
392
+ assert_has_tag('input.numeric[type=tel]', :id => 'user_telephone', :name => 'user[telephone]') { actual_html }
393
+ end
394
+
395
+ it 'should display correct telephone field in haml' do
396
+ visit '/haml/form_for'
397
+ assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
398
+ end
399
+
400
+ it 'should display correct telephone field in erb' do
401
+ visit '/erb/form_for'
402
+ assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
403
+ end
404
+
405
+ it 'should display correct telephone field in slim' do
406
+ visit '/slim/form_for'
407
+ assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
408
+ end
409
+ end
410
+
411
+ describe 'for #search_field method' do
412
+ it 'should display correct search field html' do
413
+ actual_html = standard_builder.search_field(:search, :class => 'string')
414
+ assert_has_tag('input.string[type=search]', :id => 'user_search', :name => 'user[search]') { actual_html }
415
+ end
416
+
417
+ it 'should display correct search field in haml' do
418
+ visit '/haml/form_for'
419
+ assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
420
+ end
421
+
422
+ it 'should display correct search field in erb' do
423
+ visit '/erb/form_for'
424
+ assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
425
+ end
426
+
427
+ it 'should display correct search field in slim' do
428
+ visit '/slim/form_for'
429
+ assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
430
+ end
431
+ end
432
+
433
+ describe 'for #email_field method' do
434
+ it 'should display correct email field html' do
435
+ actual_html = standard_builder.email_field(:email, :class => 'string')
436
+ assert_has_tag('input.string[type=email]', :id => 'user_email', :name => 'user[email]') { actual_html }
437
+ end
438
+
439
+ it 'should display correct email field in haml' do
440
+ visit '/haml/form_for'
441
+ assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
442
+ end
443
+
444
+ it 'should display correct email field in erb' do
445
+ visit '/erb/form_for'
446
+ assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
447
+ end
448
+
449
+ it 'should display correct email field in slim' do
450
+ visit '/slim/form_for'
451
+ assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
452
+ end
453
+ end
454
+
455
+ describe 'for #url_field method' do
456
+ it 'should display correct url field html' do
457
+ actual_html = standard_builder.url_field(:webpage, :class => 'string')
458
+ assert_has_tag('input.string[type=url]', :id => 'user_webpage', :name => 'user[webpage]') { actual_html }
459
+ end
460
+
461
+ it 'should display correct url field in haml' do
462
+ visit '/haml/form_for'
463
+ assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
464
+ end
465
+
466
+ it 'should display correct url field in erb' do
467
+ visit '/erb/form_for'
468
+ assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
469
+ end
470
+
471
+ it 'should display correct url field in slim' do
472
+ visit '/slim/form_for'
473
+ assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
474
+ end
475
+ end
476
+
477
+ describe 'for #check_box method' do
478
+ it 'should display correct checkbox html' do
479
+ actual_html = standard_builder.check_box(:confirm_destroy, :class => 'large')
480
+ assert_has_tag('input.large[type=checkbox]', :id => 'user_confirm_destroy', :name => 'user[confirm_destroy]') { actual_html }
481
+ assert_has_tag('input[type=hidden]', :name => 'user[confirm_destroy]', :value => '0') { actual_html }
482
+ end
483
+
484
+ it 'should display correct checkbox html when checked' do
485
+ actual_html = standard_builder.check_box(:confirm_destroy, :checked => true)
486
+ assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[confirm_destroy]') { actual_html }
487
+ end
488
+
489
+ it 'should display correct checkbox html as checked when object value matches' do
490
+ @user.stubs(:show_favorites => 'human')
491
+ actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
492
+ assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
493
+ end
494
+
495
+ it 'should display correct checkbox html as checked when object value is true' do
496
+ @user.stubs(:show_favorites => true)
497
+ actual_html = standard_builder.check_box(:show_favorites, :value => '1')
498
+ assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
499
+ end
500
+
501
+ it 'should display correct checkbox html as unchecked when object value does not match' do
502
+ @user.stubs(:show_favorites => 'alien')
503
+ actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
504
+ assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
505
+ end
506
+
507
+ it 'should display correct checkbox html as unchecked when object value is false' do
508
+ @user.stubs(:show_favorites => false)
509
+ actual_html = standard_builder.check_box(:show_favorites, :value => '1')
510
+ assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
511
+ end
512
+
513
+ it 'should display correct unchecked hidden field when specified' do
514
+ actual_html = standard_builder.check_box(:show_favorites, :value => 'female', :uncheck_value => 'false')
515
+ assert_has_tag('input[type=hidden]', :name => 'user[show_favorites]', :value => 'false') { actual_html }
516
+ end
517
+
518
+ it 'should display correct checkbox in haml' do
519
+ visit '/haml/form_for'
520
+ assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
521
+ end
522
+
523
+ it 'should display correct checkbox in erb' do
524
+ visit '/erb/form_for'
525
+ assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
526
+ end
527
+
528
+ it 'should display correct checkbox in slim' do
529
+ visit '/slim/form_for'
530
+ assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
531
+ end
532
+ end
533
+
534
+ describe 'for #check_box_group and #radio_button_group methods' do
535
+ it 'should display checkbox group html' do
536
+ checkboxes = standard_builder.check_box_group(:role, :collection => @user.role_types, :fields => [:name, :id], :selected => [2,3])
537
+ assert_has_tag('input[type=checkbox]', :value => '1') { checkboxes }
538
+ assert_has_no_tag('input[type=checkbox][checked]', :value => '1') { checkboxes }
539
+ assert_has_tag('input[type=checkbox]', :checked => 'checked', :value => '2') { checkboxes }
540
+ assert_has_tag('label[for=user_role_3] input[name="user[role][]"][value="3"][checked]') { checkboxes }
541
+ end
542
+
543
+ it 'should display checkbox group html and extract selected values from the object' do
544
+ checkboxes = standard_builder.check_box_group(:roles, :collection => @user.role_types, :fields => [:name, :id])
545
+ assert_has_tag('input[type=checkbox][name="user[roles][]"][value="1"][checked]') { checkboxes }
546
+ assert_has_tag('input[type=checkbox][name="user[roles][]"][value="3"][checked]') { checkboxes }
547
+ assert_has_no_tag('input[type=checkbox][name="user[roles][]"][value="2"][checked]') { checkboxes }
548
+ end
549
+
550
+ it 'should display radio group html' do
551
+ radios = standard_builder.radio_button_group(:role, :options => %W(red yellow blue), :selected => 'yellow')
552
+ assert_has_tag('input[type=radio]', :value => 'red') { radios }
553
+ assert_has_no_tag('input[type=radio][checked]', :value => 'red') { radios }
554
+ assert_has_tag('input[type=radio]', :checked => 'checked', :value => 'yellow') { radios }
555
+ assert_has_tag('label[for=user_role_blue] input[name="user[role]"][value=blue]') { radios }
556
+ end
557
+
558
+ it 'should display radio group html and extract selected value from the object' do
559
+ radios = standard_builder.radio_button_group(:role, :collection => @user.role_types)
560
+ assert_has_tag('input[type=radio][value="1"][checked]') { radios }
561
+ assert_has_no_tag('input[type=radio][value="2"][checked]') { radios }
562
+ end
563
+ end
564
+
565
+ describe 'for #radio_button method' do
566
+ it 'should display correct radio button html' do
567
+ actual_html = standard_builder.radio_button(:gender, :value => 'male', :class => 'large')
568
+ assert_has_tag('input.large[type=radio]', :id => 'user_gender_male', :name => 'user[gender]', :value => 'male') { actual_html }
569
+ end
570
+
571
+ it 'should display correct radio button html when checked' do
572
+ actual_html = standard_builder.radio_button(:gender, :checked => true)
573
+ assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
574
+ end
575
+
576
+ it 'should display correct radio button html as checked when object value matches' do
577
+ @user.stubs(:gender => 'male')
578
+ actual_html = standard_builder.radio_button(:gender, :value => 'male')
579
+ assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
580
+ end
581
+
582
+ it 'should display correct radio button html as unchecked when object value does not match' do
583
+ @user.stubs(:gender => 'male')
584
+ actual_html = standard_builder.radio_button(:gender, :value => 'female')
585
+ assert_has_no_tag('input[type=radio]', :checked => 'checked') { actual_html }
586
+ end
587
+
588
+ it 'should display correct radio button in haml' do
589
+ visit '/haml/form_for'
590
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
591
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
592
+ assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
593
+ end
594
+
595
+ it 'should display correct radio button in erb' do
596
+ visit '/erb/form_for'
597
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
598
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
599
+ assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
600
+ end
601
+
602
+ it 'should display correct radio button in slim' do
603
+ visit '/slim/form_for'
604
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
605
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
606
+ assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
607
+ end
608
+ end
609
+
610
+ describe 'for #text_area method' do
611
+ it 'should display correct text_area html' do
612
+ actual_html = standard_builder.text_area(:about, :class => 'large')
613
+ assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
614
+ end
615
+
616
+ it 'should display correct text_area html and content' do
617
+ actual_html = standard_builder.text_area(:about, :value => "Demo", :rows => '5', :cols => '6')
618
+ assert_has_tag('textarea', :id => 'user_about', :content => 'Demo', :rows => '5', :cols => '6') { actual_html }
619
+ end
620
+
621
+ it 'should display correct text_area in haml' do
622
+ visit '/haml/form_for'
623
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
624
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
625
+ end
626
+
627
+ it 'should display correct text_area in erb' do
628
+ visit '/erb/form_for'
629
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
630
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
631
+ end
632
+
633
+ it 'should display correct text_area in slim' do
634
+ visit '/slim/form_for'
635
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
636
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
637
+ end
638
+ end
639
+
640
+ describe 'for #password_field method' do
641
+ it 'should display correct password_field html' do
642
+ actual_html = standard_builder.password_field(:code, :class => 'large')
643
+ assert_has_tag('input.large[type=password]', :id => 'user_code', :name => 'user[code]') { actual_html }
644
+ end
645
+
646
+ it 'should display correct password_field in haml' do
647
+ visit '/haml/form_for'
648
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
649
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
650
+ end
651
+
652
+ it 'should display correct password_field in erb' do
653
+ visit '/erb/form_for'
654
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
655
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
656
+ end
657
+
658
+ it 'should display correct password_field in slim' do
659
+ visit '/slim/form_for'
660
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
661
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
662
+ end
663
+ end
664
+
665
+ describe 'for #file_field method' do
666
+ it 'should display correct file_field html' do
667
+ actual_html = standard_builder.file_field(:photo, :class => 'large')
668
+ assert_has_tag('input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
669
+ end
670
+
671
+ it 'should display correct file_field in haml' do
672
+ visit '/haml/form_for'
673
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
674
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
675
+ end
676
+
677
+ it 'should display correct file_field in erb' do
678
+ visit '/erb/form_for'
679
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
680
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
681
+ end
682
+
683
+ it 'should display correct file_field in slim' do
684
+ visit '/slim/form_for'
685
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
686
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
687
+ end
688
+
689
+ it 'should display correct form html with multipart, even if no multipart option is specified' do
690
+ actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8") { |f| f.file_field :photo }
691
+ assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
692
+ end
693
+
694
+ it 'should display correct form html without multipart, if multipart option is specified false' do
695
+ actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8", :multipart => false) { |f| f.file_field :photo }
696
+ assert_has_no_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
697
+ end
698
+
699
+ end
700
+
701
+ describe 'for #select method' do
702
+ it 'should display correct select html' do
703
+ actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :class => 'selecty')
704
+ assert_has_tag('select.selecty', :id => 'user_state', :name => 'user[state]') { actual_html }
705
+ assert_has_tag('select.selecty option', :count => 3) { actual_html }
706
+ assert_has_tag('select.selecty option', :value => 'California', :content => 'California') { actual_html }
707
+ assert_has_tag('select.selecty option', :value => 'Texas', :content => 'Texas') { actual_html }
708
+ assert_has_tag('select.selecty option', :value => 'Wyoming', :content => 'Wyoming') { actual_html }
709
+ end
710
+
711
+ it 'should display correct select html with selected item if it matches value' do
712
+ @user.stubs(:state => 'California')
713
+ actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'])
714
+ assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
715
+ assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
716
+ assert_has_tag('select option', :value => 'California', :selected => 'selected') { actual_html }
717
+ end
718
+
719
+ it 'should display correct select html with selected item if it matches full value' do
720
+ @user.stubs(:state => 'Cali')
721
+ actual_html = standard_builder.select(:state, :options => ['Cali', 'California', 'Texas', 'Wyoming'])
722
+ assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
723
+ assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
724
+ assert_has_tag('select option', :value => 'Cali', :selected => 'selected') { actual_html }
725
+ assert_has_tag('select option', :value => 'California') { actual_html }
726
+ end
727
+
728
+ it 'should display correct select html with multiple selected items' do
729
+ @user.stubs(:pickles => ['foo', 'bar'])
730
+ actual_html = standard_builder.select(
731
+ :pickles, :options => [ ['Foo', 'foo'], ['Bar', 'bar'], ['Baz', 'baz'], ['Bar Buz', 'bar buz'] ]
732
+ )
733
+ assert_has_tag('option', :value => 'foo', :content => 'Foo', :selected => 'selected') { actual_html }
734
+ assert_has_tag('option', :value => 'bar', :content => 'Bar', :selected => 'selected') { actual_html }
735
+ assert_has_tag('option', :value => 'baz', :content => 'Baz') { actual_html }
736
+ assert_has_tag('option', :value => 'bar buz', :content => 'Bar Buz') { actual_html }
737
+ end
738
+
739
+ it 'should display correct select html with include_blank' do
740
+ actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => true)
741
+ assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
742
+ assert_has_tag('select option', :count => 4) { actual_html }
743
+ assert_has_tag('select option:first-child', :content => '') { actual_html }
744
+ assert_has_tag('select option:first-child', :value => '') { actual_html }
745
+ actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => 'Select')
746
+ assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
747
+ assert_has_tag('select option', :count => 4) { actual_html }
748
+ assert_has_tag('select option:first-child', :content => 'Select') { actual_html }
749
+ assert_has_tag('select option:first-child', :value => '') { actual_html }
750
+ end
751
+
752
+ it 'should display correct select html with collection passed in' do
753
+ actual_html = standard_builder.select(:role, :collection => @user.role_types, :fields => [:name, :id])
754
+ assert_has_tag('select', :id => 'user_role', :name => 'user[role]') { actual_html }
755
+ assert_has_tag('select option', :count => 3) { actual_html }
756
+ assert_has_tag('select option', :value => '1', :content => 'Admin', :selected => 'selected') { actual_html }
757
+ assert_has_tag('select option', :value => '2', :content => 'Moderate') { actual_html }
758
+ assert_has_tag('select option', :value => '3', :content => 'Limited') { actual_html }
759
+ end
760
+
761
+ it 'should display correct select in haml' do
762
+ visit '/haml/form_for'
763
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
764
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
765
+ end
766
+
767
+ it 'should display correct select in erb' do
768
+ visit '/erb/form_for'
769
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
770
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
771
+ end
772
+
773
+ it 'should display correct select in slim' do
774
+ visit '/slim/form_for'
775
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
776
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
777
+ end
778
+ end
779
+
780
+ describe 'for #submit method' do
781
+ it 'should display correct submit button html with no options' do
782
+ actual_html = standard_builder.submit
783
+ assert_has_tag('input[type=submit]', :value => "Submit") { actual_html }
784
+ end
785
+
786
+
787
+ it 'should display correct submit button html with no caption' do
788
+ actual_html = standard_builder.submit(:class => 'btn')
789
+ assert_has_tag('input.btn[type=submit]', :value => "Submit") { actual_html }
790
+ end
791
+
792
+ it 'should display correct submit button html with nil caption' do
793
+ actual_html = standard_builder.submit(nil, :class => 'btn')
794
+ assert_has_tag('input.btn[type=submit]') { actual_html }
795
+ assert actual_html !~ %r{ value \* = }x
796
+ end
797
+
798
+ it 'should display correct submit button html' do
799
+ actual_html = standard_builder.submit("Commit", :class => 'large')
800
+ assert_has_tag('input.large[type=submit]', :value => "Commit") { actual_html }
801
+ end
802
+
803
+ it 'should display correct submit button in haml' do
804
+ visit '/haml/form_for'
805
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
806
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
807
+ end
808
+
809
+ it 'should display correct submit button in erb' do
810
+ visit '/erb/form_for'
811
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
812
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
813
+ end
814
+
815
+ it 'should display correct submit button in slim' do
816
+ visit '/slim/form_for'
817
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
818
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
819
+ end
820
+ end
821
+
822
+ describe 'for #image_submit method' do
823
+ before do
824
+ @stamp = stop_time_for_test.to_i
825
+ end
826
+
827
+ it 'should display correct image submit button html with no options' do
828
+ actual_html = standard_builder.image_submit('buttons/ok.png')
829
+ assert_has_tag('input[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
830
+ end
831
+
832
+ it 'should display correct image submit button html' do
833
+ actual_html = standard_builder.image_submit('/system/ok.png', :class => 'large')
834
+ assert_has_tag('input.large[type=image]', :src => "/system/ok.png") { actual_html }
835
+ end
836
+
837
+ it 'should display correct image submit button in haml' do
838
+ visit '/haml/form_for'
839
+ assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
840
+ assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
841
+ end
842
+
843
+ it 'should display correct image submit button in erb' do
844
+ visit '/erb/form_for'
845
+ assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
846
+ assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
847
+ end
848
+
849
+ it 'should display correct image submit button in slim' do
850
+ visit '/slim/form_for'
851
+ assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
852
+ assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
853
+ end
854
+ end
855
+
856
+ describe 'for #fields_for method' do
857
+ before do
858
+ @telephone = mock_model("Telephone", :number => "4568769876")
859
+ @user.stubs(:telephone).returns(@telephone)
860
+ @businesses = [ mock_model("Business", :name => "Silver", :new_record? => false, :id => 20) ]
861
+ @businesses << mock_model("Business", :name => "Gold", :new_record? => true)
862
+ @addresses = [ mock_model("Address", :name => "Foo", :new_record? => false, :id => 20, :businesses => @businesses) ]
863
+ @addresses << mock_model("Address", :name => "Bar", :new_record? => true, :businesses => @businesses)
864
+ @user.stubs(:addresses).returns(@addresses)
865
+ end
866
+
867
+ it 'should display nested children fields one-to-one within form' do
868
+ actual_html = standard_builder.fields_for :telephone do |child_form|
869
+ child_form.label(:number) +
870
+ child_form.text_field(:number) +
871
+ child_form.check_box('_destroy')
872
+ end
873
+ assert_has_tag('label', :for => 'user_telephone_attributes_number') { actual_html }
874
+ assert_has_tag('input', :type => 'text', :id => 'user_telephone_attributes_number', :name => 'user[telephone_attributes][number]', :value => "4568769876") { actual_html }
875
+ assert_has_tag('input', :type => 'hidden', :name => 'user[telephone_attributes][_destroy]', :value => '0') { actual_html }
876
+ assert_has_tag('input', :type => 'checkbox', :id => 'user_telephone_attributes__destroy', :name => 'user[telephone_attributes][_destroy]', :value => '1') { actual_html }
877
+ end
878
+
879
+ it 'should display nested children fields one-to-many within form' do
880
+ actual_html = standard_builder.fields_for(:addresses) do |child_form|
881
+ html = child_form.label(:name)
882
+ html << child_form.check_box('_destroy') unless child_form.object.new_record?
883
+ html << child_form.text_field(:name)
884
+ end
885
+ # Address 1 (Saved)
886
+ assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
887
+ assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
888
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]') { actual_html }
889
+ assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
890
+ # Address 2 (New)
891
+ assert_has_no_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_1_id') { actual_html }
892
+ assert_has_tag('label', :for => 'user_addresses_attributes_1_name', :content => 'Name') { actual_html }
893
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_name', :name => 'user[addresses_attributes][1][name]') { actual_html }
894
+ assert_has_no_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_1__destroy') { actual_html }
895
+ end
896
+
897
+ it 'should display fields for explicit instance object' do
898
+ address = mock_model("Address", :name => "Page", :new_record? => false, :id => 40)
899
+ actual_html = standard_builder.fields_for(:addresses, address) do |child_form|
900
+ html = child_form.label(:name)
901
+ html << child_form.text_field(:name)
902
+ html << child_form.check_box('_destroy')
903
+ end
904
+ assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '40') { actual_html }
905
+ assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
906
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Page") { actual_html }
907
+ assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]', :value => '1') { actual_html }
908
+ end
909
+
910
+ it 'should display fields for collection object' do
911
+ addresses = @addresses + [mock_model("Address", :name => "Walter", :new_record? => false, :id => 50)]
912
+ actual_html = standard_builder.fields_for(:addresses, addresses) do |child_form|
913
+ child_form.label(:name) +
914
+ child_form.text_field(:name) +
915
+ child_form.check_box('_destroy')
916
+ end
917
+ # Address 1
918
+ assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
919
+ assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
920
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Foo") { actual_html }
921
+ assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
922
+ # Address 3
923
+ assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_2_id', :value => '50') { actual_html }
924
+ assert_has_tag('label', :for => 'user_addresses_attributes_2_name', :content => 'Name') { actual_html }
925
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_2_name', :name => 'user[addresses_attributes][2][name]', :value => "Walter") { actual_html }
926
+ assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_2__destroy') { actual_html }
927
+ end
928
+
929
+ it 'should display fields for arbitrarily deep nested forms' do
930
+ actual_html = standard_builder.fields_for :addresses do |child_form|
931
+ child_form.fields_for(:businesses) do |second_child_form|
932
+ second_child_form.label(:name) +
933
+ second_child_form.text_field(:name) +
934
+ second_child_form.check_box('_destroy')
935
+ end
936
+ end
937
+ assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_0_name', :content => 'Name') { actual_html }
938
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_0_name', :name => 'user[addresses_attributes][1][businesses_attributes][0][name]') { actual_html }
939
+ end
940
+
941
+ it 'should display fields for nested forms with custom indices' do
942
+ actual_html = standard_builder.fields_for :addresses do |child_form|
943
+ html = ''.html_safe
944
+ child_form.object.businesses.each_with_index do |business, i|
945
+ html += child_form.fields_for(:businesses, business, :index => ('a'..'z').to_a[i]) do |second_child_form|
946
+ second_child_form.label(:name) +
947
+ second_child_form.text_field(:name) +
948
+ second_child_form.check_box('_destroy')
949
+ end
950
+ end
951
+ html
952
+ end
953
+
954
+ assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_a_name', :content => 'Name') { actual_html }
955
+ assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_a_name', :name => 'user[addresses_attributes][1][businesses_attributes][a][name]') { actual_html }
956
+ end
957
+
958
+ it 'should display nested children fields in erb' do
959
+ visit '/erb/fields_for'
960
+ # Telephone
961
+ assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
962
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
963
+ # Address 1 (Saved)
964
+ assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
965
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
966
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
967
+ assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
968
+ # Address 2 (New)
969
+ assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
970
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
971
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
972
+ assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
973
+ end
974
+
975
+ it 'should display nested children fields in haml' do
976
+ visit '/haml/fields_for'
977
+ # Telephone
978
+ assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
979
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
980
+ # Address 1 (Saved)
981
+ assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
982
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
983
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
984
+ assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
985
+ # Address 2 (New)
986
+ assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
987
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
988
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
989
+ assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
990
+ end
991
+
992
+ it 'should display nested children fields in slim' do
993
+ visit '/slim/fields_for'
994
+ # Telephone
995
+ assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
996
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
997
+ # Address 1 (Saved)
998
+ assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
999
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
1000
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
1001
+ assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
1002
+ # Address 2 (New)
1003
+ assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
1004
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
1005
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
1006
+ assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
1007
+ end
1008
+ end
1009
+
1010
+ # ===========================
1011
+ # StandardFormBuilder
1012
+ # ===========================
1013
+
1014
+ describe 'for #text_field_block method' do
1015
+ it 'should display correct text field block html' do
1016
+ actual_html = standard_builder.text_field_block(:first_name, :class => 'large', :caption => "FName")
1017
+ assert_has_tag('p label', :for => 'user_first_name', :content => "FName") { actual_html }
1018
+ assert_has_tag('p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
1019
+ end
1020
+
1021
+ it 'should display correct text field block in haml' do
1022
+ visit '/haml/form_for'
1023
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
1024
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
1025
+ end
1026
+
1027
+ it 'should display correct text field block in erb' do
1028
+ visit '/erb/form_for'
1029
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
1030
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
1031
+ end
1032
+
1033
+ it 'should display correct text field block in slim' do
1034
+ visit '/slim/form_for'
1035
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
1036
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
1037
+ end
1038
+ end
1039
+
1040
+ describe 'for #text_area_block method' do
1041
+ it 'should display correct text area block html' do
1042
+ actual_html = standard_builder.text_area_block(:about, :class => 'large', :caption => "About Me")
1043
+ assert_has_tag('p label', :for => 'user_about', :content => "About Me") { actual_html }
1044
+ assert_has_tag('p textarea', :id => 'user_about', :name => 'user[about]') { actual_html }
1045
+ end
1046
+
1047
+ it 'should display correct text area block in haml' do
1048
+ visit '/haml/form_for'
1049
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
1050
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
1051
+ end
1052
+
1053
+ it 'should display correct text area block in erb' do
1054
+ visit '/erb/form_for'
1055
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
1056
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
1057
+ end
1058
+
1059
+ it 'should display correct text area block in slim' do
1060
+ visit '/slim/form_for'
1061
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
1062
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
1063
+ end
1064
+ end
1065
+
1066
+ describe 'for #password_field_block method' do
1067
+ it 'should display correct password field block html' do
1068
+ actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code: ")
1069
+ assert_has_tag('p label', :for => 'user_keycode', :content => "Code: ") { actual_html }
1070
+ assert_has_tag('p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]') { actual_html }
1071
+ end
1072
+
1073
+ it 'should display correct password field block in haml' do
1074
+ visit '/haml/form_for'
1075
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
1076
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
1077
+ end
1078
+
1079
+ it 'should display correct password field block in erb' do
1080
+ visit '/erb/form_for'
1081
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
1082
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
1083
+ end
1084
+
1085
+ it 'should display correct password field block in slim' do
1086
+ visit '/slim/form_for'
1087
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
1088
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
1089
+ end
1090
+ end
1091
+
1092
+ describe 'for #file_field_block method' do
1093
+ it 'should display correct file field block html' do
1094
+ actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo: ")
1095
+ assert_has_tag('p label', :for => 'user_photo', :content => "Photo: ") { actual_html }
1096
+ assert_has_tag('p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
1097
+ end
1098
+
1099
+ it 'should display correct file field block in haml' do
1100
+ visit '/haml/form_for'
1101
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
1102
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
1103
+ end
1104
+
1105
+ it 'should display correct file field block in erb' do
1106
+ visit '/erb/form_for'
1107
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
1108
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
1109
+ end
1110
+
1111
+ it 'should display correct file field block in slim' do
1112
+ visit '/slim/form_for'
1113
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
1114
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
1115
+ end
1116
+ end
1117
+
1118
+ describe 'for #check_box_block method' do
1119
+ it 'should display correct check box block html' do
1120
+ actual_html = standard_builder.check_box_block(:remember_me, :class => 'large', :caption => "Remember session?")
1121
+ assert_has_tag('p label', :for => 'user_remember_me', :content => "Remember session?") { actual_html }
1122
+ assert_has_tag('p input.large[type=checkbox]', :id => 'user_remember_me', :name => 'user[remember_me]') { actual_html }
1123
+ end
1124
+
1125
+ it 'should display correct check box block in haml' do
1126
+ visit '/haml/form_for'
1127
+ assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
1128
+ assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
1129
+ end
1130
+
1131
+ it 'should display correct check box block in erb' do
1132
+ visit '/erb/form_for'
1133
+ assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
1134
+ assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
1135
+ end
1136
+
1137
+ it 'should display correct check box block in slim' do
1138
+ visit '/slim/form_for'
1139
+ assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
1140
+ assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
1141
+ end
1142
+ end
1143
+
1144
+ describe 'for #select_block method' do
1145
+ it 'should display correct select_block block html' do
1146
+ actual_html = standard_builder.select_block(:country, :options => ['USA', 'Canada'], :class => 'large', :caption => "Your country")
1147
+ assert_has_tag('p label', :for => 'user_country', :content => "Your country") { actual_html }
1148
+ assert_has_tag('p select', :id => 'user_country', :name => 'user[country]') { actual_html }
1149
+ assert_has_tag('p select option', :content => 'USA') { actual_html }
1150
+ assert_has_tag('p select option', :content => 'Canada') { actual_html }
1151
+ end
1152
+
1153
+ it 'should display correct select_block block in haml' do
1154
+ visit '/haml/form_for'
1155
+ assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
1156
+ assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
1157
+ assert_have_selector '#demo2 p select option', :content => 'California'
1158
+ assert_have_selector '#demo2 p select option', :content => 'Texas'
1159
+ end
1160
+
1161
+ it 'should display correct select_block block in erb' do
1162
+ visit '/erb/form_for'
1163
+ assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
1164
+ assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
1165
+ end
1166
+
1167
+ it 'should display correct select_block block in slim' do
1168
+ visit '/slim/form_for'
1169
+ assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
1170
+ assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
1171
+ end
1172
+ end
1173
+
1174
+ describe 'for #submit_block method' do
1175
+ it 'should display correct submit block html' do
1176
+ actual_html = standard_builder.submit_block("Update", :class => 'large')
1177
+ assert_has_tag('p input.large[type=submit]', :value => 'Update') { actual_html }
1178
+ end
1179
+
1180
+ it 'should display correct submit block in haml' do
1181
+ visit '/haml/form_for'
1182
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
1183
+ end
1184
+
1185
+ it 'should display correct submit block in erb' do
1186
+ visit '/erb/form_for'
1187
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
1188
+ end
1189
+
1190
+ it 'should display correct submit block in slim' do
1191
+ visit '/slim/form_for'
1192
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
1193
+ end
1194
+ end
1195
+
1196
+ describe 'for #image_submit_block method' do
1197
+ before do
1198
+ @stamp = stop_time_for_test.to_i
1199
+ end
1200
+
1201
+ it 'should display correct image submit block html' do
1202
+ actual_html = standard_builder.image_submit_block("buttons/ok.png", :class => 'large')
1203
+ assert_has_tag('p input.large[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
1204
+ end
1205
+
1206
+ it 'should display correct image submit block in haml' do
1207
+ visit '/haml/form_for'
1208
+ assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
1209
+ end
1210
+
1211
+ it 'should display correct image submit block in slim' do
1212
+ visit '/slim/form_for'
1213
+ assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
1214
+ end
1215
+ end
1216
+ end