padrino-helpers 0.12.8.1 → 0.12.9

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