padrino-helpers 0.12.9 → 0.13.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -13
  2. data/lib/padrino-helpers.rb +2 -2
  3. data/lib/padrino-helpers/asset_tag_helpers.rb +18 -26
  4. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +3 -56
  5. data/lib/padrino-helpers/form_builder/standard_form_builder.rb +1 -1
  6. data/lib/padrino-helpers/form_helpers.rb +11 -227
  7. data/lib/padrino-helpers/form_helpers/options.rb +5 -7
  8. data/lib/padrino-helpers/output_helpers.rb +1 -1
  9. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +1 -1
  10. data/lib/padrino-helpers/output_helpers/erb_handler.rb +1 -2
  11. data/lib/padrino-helpers/render_helpers.rb +2 -23
  12. data/lib/padrino-helpers/tag_helpers.rb +1 -14
  13. data/lib/padrino/rendering.rb +4 -56
  14. data/lib/padrino/rendering/erb_template.rb +0 -12
  15. data/lib/padrino/rendering/erubis_template.rb +1 -1
  16. data/padrino-helpers.gemspec +1 -1
  17. data/test/fixtures/markup_app/views/form_for.erb +0 -28
  18. data/test/fixtures/markup_app/views/form_for.haml +0 -22
  19. data/test/fixtures/markup_app/views/form_for.slim +0 -21
  20. data/test/fixtures/markup_app/views/form_tag.erb +0 -21
  21. data/test/fixtures/markup_app/views/form_tag.haml +0 -14
  22. data/test/fixtures/markup_app/views/form_tag.slim +0 -14
  23. data/test/helper.rb +17 -6
  24. data/test/test_asset_tag_helpers.rb +92 -110
  25. data/test/test_form_builder.rb +450 -691
  26. data/test/test_form_helpers.rb +457 -770
  27. data/test/test_format_helpers.rb +37 -17
  28. data/test/test_helpers.rb +0 -8
  29. data/test/test_output_helpers.rb +72 -72
  30. data/test/test_render_helpers.rb +100 -142
  31. data/test/test_rendering.rb +1 -58
  32. data/test/test_tag_helpers.rb +39 -41
  33. metadata +118 -34
  34. data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +0 -79
@@ -14,114 +14,89 @@ describe "AssetTagHelpers" do
14
14
 
15
15
  describe 'for #flash_tag method' do
16
16
  it 'should display flash with no given attributes' do
17
- assert_html_has_tag(flash_tag(:notice), 'div.notice', :content => "Demo notice")
17
+ assert_has_tag('div.notice', :content => "Demo notice") { flash_tag(:notice) }
18
18
  end
19
19
  it 'should display flash with given attributes' do
20
20
  actual_html = flash_tag(:notice, :class => 'notice', :id => 'notice-area')
21
- assert_html_has_tag(actual_html, 'div.notice#notice-area', :content => "Demo notice")
21
+ assert_has_tag('div.notice#notice-area', :content => "Demo notice") { actual_html }
22
22
  end
23
23
  it 'should display multiple flash tags with given attributes' do
24
24
  flash[:error] = 'wrong'
25
25
  flash[:success] = 'okey'
26
26
  actual_html = flash_tag(:success, :warning, :error, :id => 'area')
27
- assert_html_has_tag(actual_html, 'div.success#area', :content => flash[:success])
28
- assert_html_has_tag(actual_html, 'div.error#area', :content => flash[:error])
29
- assert_html_has_no_tag(actual_html, 'div.warning')
27
+ assert_has_tag('div.success#area', :content => flash[:success]) { actual_html }
28
+ assert_has_tag('div.error#area', :content => flash[:error]) { actual_html }
29
+ assert_has_no_tag('div.notice') { actual_html }
30
30
  end
31
31
  end
32
32
 
33
33
  describe 'for #link_to method' do
34
34
  it 'should display link element with no given attributes' do
35
- assert_html_has_tag(link_to('Sign up', '/register'), 'a', :content => "Sign up", :href => '/register')
35
+ assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
36
36
  end
37
37
 
38
38
  it 'should display link element with given attributes' do
39
39
  actual_html = link_to('Sign up', '/register', :class => 'first', :id => 'linky')
40
- assert_html_has_tag(actual_html, 'a#linky.first', :content => "Sign up", :href => '/register')
41
- end
42
-
43
- it 'should display link element with anchor attribute' do
44
- actual_html = link_to("Anchor", "/anchor", :anchor => :foo)
45
- assert_html_has_tag(actual_html, 'a', :content => "Anchor", :href => '/anchor#foo')
40
+ assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
46
41
  end
47
42
 
48
43
  it 'should display link element with void url and options' do
49
44
  actual_link = link_to('Sign up', :class => "test")
50
- assert_html_has_tag(actual_link, 'a', :content => "Sign up", :href => '#', :class => 'test')
45
+ assert_has_tag('a', :content => "Sign up", :href => '#', :class => 'test') { actual_link }
51
46
  end
52
47
 
53
48
  it 'should display link element with remote option' do
54
49
  actual_link = link_to('Sign up', '/register', :remote => true)
55
- assert_html_has_tag(actual_link, 'a', :content => "Sign up", :href => '/register', 'data-remote' => 'true')
50
+ assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-remote' => 'true') { actual_link }
56
51
  end
57
52
 
58
53
  it 'should display link element with method option' do
59
54
  actual_link = link_to('Sign up', '/register', :method => :delete)
60
- assert_html_has_tag(actual_link, 'a', :content => "Sign up", :href => '/register', 'data-method' => 'delete', :rel => 'nofollow')
55
+ assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-method' => 'delete', :rel => 'nofollow') { actual_link }
61
56
  end
62
57
 
63
58
  it 'should display link element with confirm option' do
64
59
  actual_link = link_to('Sign up', '/register', :confirm => "Are you sure?")
65
- assert_html_has_tag(actual_link, 'a', :content => "Sign up", :href => '/register', 'data-confirm' => 'Are you sure?')
60
+ assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-confirm' => 'Are you sure?') { actual_link }
66
61
  end
67
62
 
68
63
  it 'should display link element with ruby block' do
69
64
  actual_link = link_to('/register', :class => 'first', :id => 'binky') { "Sign up" }
70
- assert_html_has_tag(actual_link, 'a#binky.first', :content => "Sign up", :href => '/register')
65
+ assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
71
66
  end
72
67
 
73
68
  it 'should escape the link text' do
74
69
  actual_link = link_to('/register', :class => 'first', :id => 'binky') { "<&>" }
75
- assert_html_has_tag(actual_link, 'a#binky.first', :href => '/register')
70
+ assert_has_tag('a#binky.first', :href => '/register') { actual_link }
76
71
  assert_match "&lt;&amp;&gt;", actual_link
77
72
  end
78
73
 
79
- it 'should escape the link href' do
80
- actual_link = link_to('Sign up', '/register new%20user')
81
- assert_html_has_tag(actual_link, 'a', :href => '/register%20new%20user')
82
- end
83
-
84
74
  it 'should not escape image_tag' do
85
75
  actual_link = link_to(image_tag("/my/fancy/image.png"), :class => 'first', :id => 'binky')
86
- assert_html_has_tag(actual_link, 'img', :src => "/my/fancy/image.png")
87
- end
88
-
89
- it 'should render alt text by default' do
90
- actual_tag = image_tag("/my/fancy/image.png")
91
- assert_html_has_tag(actual_tag, 'img', :src => "/my/fancy/image.png", :alt => "Image")
92
- end
93
-
94
- it 'should render humanized alt text' do
95
- actual_tag = image_tag("/my/fancy/image_white.png")
96
- assert_html_has_tag(actual_tag, 'img', :src => "/my/fancy/image_white.png", :alt => "Image white")
97
- end
98
-
99
- it 'should remove hash value from src path' do
100
- actual_tag = image_tag("/my/fancy/sprite-47bce5c74f589f4867dbd57e9ca9f808.png")
101
- assert_html_has_tag(actual_tag, 'img', :src => "/my/fancy/sprite-47bce5c74f589f4867dbd57e9ca9f808.png", :alt => "Sprite")
76
+ assert_has_tag('img', :src => "/my/fancy/image.png") { actual_link }
102
77
  end
103
78
 
104
79
  it 'should display link block element in haml' do
105
- get "/haml/link_to"
106
- assert_response_has_tag :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
107
- assert_response_has_tag :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
80
+ visit '/haml/link_to'
81
+ assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
82
+ assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
108
83
  end
109
84
 
110
85
  it 'should display link block element in erb' do
111
- get "/erb/link_to"
112
- assert_response_has_tag :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
113
- assert_response_has_tag :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
86
+ visit '/erb/link_to'
87
+ assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
88
+ assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
114
89
  end
115
90
 
116
91
  it 'should display link block element in slim' do
117
- get "/slim/link_to"
118
- assert_response_has_tag :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
119
- assert_response_has_tag :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
92
+ visit '/slim/link_to'
93
+ assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
94
+ assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
120
95
  end
121
96
 
122
97
  it 'should not double-escape' do
123
98
  actual_link = link_to('test escape', '?a=1&b=2')
124
- assert_html_has_tag(actual_link, 'a', :href => '?a=1&b=2')
99
+ assert_has_tag('a', :href => '?a=1&b=2') { actual_link }
125
100
  assert_match %r{&amp;}, actual_link
126
101
  refute_match %r{&amp;amp;}, actual_link
127
102
  end
@@ -135,17 +110,17 @@ describe "AssetTagHelpers" do
135
110
  describe 'for #mail_to method' do
136
111
  it 'should display link element for mail to no caption' do
137
112
  actual_html = mail_to('test@demo.com')
138
- assert_html_has_tag(actual_html, :a, :href => "mailto:test@demo.com", :content => 'test@demo.com')
113
+ assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'test@demo.com') { actual_html }
139
114
  end
140
115
 
141
116
  it 'should display link element for mail to with caption' do
142
117
  actual_html = mail_to('test@demo.com', "My Email", :class => 'demo')
143
- assert_html_has_tag(actual_html, :a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo')
118
+ assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo') { actual_html }
144
119
  end
145
120
 
146
121
  it 'should display link element for mail to with caption and mail options' do
147
122
  actual_html = mail_to('test@demo.com', "My Email", :subject => 'demo test', :class => 'demo', :cc => 'foo@test.com')
148
- assert_html_has_tag(actual_html, :a, :class => 'demo')
123
+ assert_has_tag(:a, :class => 'demo') { actual_html }
149
124
  assert_match %r{mailto\:test\@demo.com\?}, actual_html
150
125
  assert_match %r{cc=foo\@test\.com}, actual_html
151
126
  assert_match %r{subject\=demo\%20test}, actual_html
@@ -158,92 +133,97 @@ describe "AssetTagHelpers" do
158
133
  end
159
134
 
160
135
  it 'should not double-escape ampersands in query' do
161
- actual_html = mail_to('to@demo.com', "Email", :bcc => 'bcc@test.com', :subject => 'Hi there')
162
- assert_html_has_tag(actual_html, :a, :href => 'mailto:to@demo.com?bcc=bcc@test.com&subject=Hi%20there', :content => 'Email')
136
+ actual_html = mail_to('to@demo.com', "Email", :subject => 'Hi there', :bcc => 'bcc@test.com')
137
+ assert_has_tag(:a, :href => 'mailto:to@demo.com?bcc=bcc@test.com&subject=Hi%20there', :content => 'Email') { actual_html }
163
138
  assert_match %r{&amp;}, actual_html
164
139
  refute_match %r{&amp;amp;}, actual_html
165
140
  end
166
141
 
167
142
  it 'should display mail link element in haml' do
168
- get "/haml/mail_to"
169
- assert_response_has_tag 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
170
- assert_response_has_tag 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
143
+ visit '/haml/mail_to'
144
+ assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
145
+ assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
171
146
  end
172
147
 
173
148
  it 'should display mail link element in erb' do
174
- get "/erb/mail_to"
175
- assert_response_has_tag 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
176
- assert_response_has_tag 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
149
+ visit '/erb/mail_to'
150
+ assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
151
+ assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
177
152
  end
178
153
 
179
154
  it 'should display mail link element in slim' do
180
- get "/slim/mail_to"
181
- assert_response_has_tag 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
182
- assert_response_has_tag 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
155
+ visit '/slim/mail_to'
156
+ assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
157
+ assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
183
158
  end
184
159
  end
185
160
 
186
161
  describe 'for #meta_tag method' do
187
162
  it 'should display meta tag with given content and name' do
188
163
  actual_html = meta_tag("weblog,news", :name => "keywords")
189
- assert_html_has_tag(actual_html, "meta", :name => "keywords", :content => "weblog,news")
164
+ assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
190
165
  end
191
166
 
192
167
  it 'should display meta tag with given content and http-equiv' do
193
168
  actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
194
- assert_html_has_tag(actual_html, "meta", :"http-equiv" => "Content-Type", :content => "text/html; charset=UTF-8")
169
+ assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
195
170
  end
196
171
 
197
172
  it 'should display meta tag element in haml' do
198
- get "/haml/meta_tag"
199
- assert_response_has_tag 'meta', :content => "weblog,news", :name => "keywords"
200
- assert_response_has_tag 'meta', :content => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
173
+ visit '/haml/meta_tag'
174
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
175
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
201
176
  end
202
177
 
203
178
  it 'should display meta tag element in erb' do
204
- get "/erb/meta_tag"
205
- assert_response_has_tag 'meta', :content => "weblog,news", :name => "keywords"
206
- assert_response_has_tag 'meta', :content => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
179
+ visit '/erb/meta_tag'
180
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
181
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
207
182
  end
208
183
 
209
184
  it 'should display meta tag element in slim' do
210
- get "/slim/meta_tag"
211
- assert_response_has_tag 'meta', :content => "weblog,news", :name => "keywords"
212
- assert_response_has_tag 'meta', :content => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
185
+ visit '/slim/meta_tag'
186
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
187
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
213
188
  end
214
189
  end
215
190
 
216
191
  describe 'for #image_tag method' do
217
192
  it 'should display image tag absolute link with no options' do
218
- assert_html_has_tag(image_tag('/absolute/pic.gif'), 'img', :src => "/absolute/pic.gif")
193
+ time = stop_time_for_test
194
+ assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
219
195
  end
220
196
 
221
197
  it 'should display image tag relative link with specified uri root' do
222
198
  time = stop_time_for_test
223
199
  self.class.stubs(:uri_root).returns("/blog")
224
- assert_html_has_tag(image_tag('relative/pic.gif'), 'img', :src => "/blog/images/relative/pic.gif?#{time.to_i}")
200
+ assert_has_tag('img', :src => "/blog/images/relative/pic.gif?#{time.to_i}") { image_tag('relative/pic.gif') }
225
201
  end
226
202
 
227
203
  it 'should display image tag relative link with options' do
228
204
  time = stop_time_for_test
229
- assert_html_has_tag(image_tag('relative/pic.gif', :class => 'photo'), 'img.photo', :src => "/images/relative/pic.gif?#{time.to_i}")
205
+ assert_has_tag('img.photo', :src => "/images/relative/pic.gif?#{time.to_i}") {
206
+ image_tag('relative/pic.gif', :class => 'photo') }
230
207
  end
231
208
 
232
209
  it 'should display image tag uri link with options' do
233
- assert_html_has_tag(image_tag('http://demo.org/pic.gif', :class => 'photo'), 'img.photo', :src => "http://demo.org/pic.gif")
210
+ time = stop_time_for_test
211
+ assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
234
212
  end
235
213
 
236
214
  it 'should display image tag relative link with incorrect spacing' do
237
215
  time = stop_time_for_test
238
- assert_html_has_tag(image_tag(' relative/ pic.gif ', :class => 'photo'), 'img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}")
216
+ assert_has_tag('img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}") {
217
+ image_tag(' relative/ pic.gif ', :class => 'photo')
218
+ }
239
219
  end
240
220
 
241
221
  it 'should not use a timestamp if stamp setting is false' do
242
- assert_html_has_tag(image_tag('/absolute/pic.gif'), 'img', :src => "/absolute/pic.gif")
222
+ assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
243
223
  end
244
224
 
245
225
  it 'should have xhtml convention tag' do
246
- assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" alt="Pic" />'
226
+ assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
247
227
  end
248
228
  end
249
229
 
@@ -252,7 +232,7 @@ describe "AssetTagHelpers" do
252
232
  time = stop_time_for_test
253
233
  actual_html = stylesheet_link_tag('style')
254
234
  expected_options = { :rel => "stylesheet", :type => "text/css" }
255
- assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}"))
235
+ assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { actual_html }
256
236
  assert actual_html.html_safe?
257
237
  end
258
238
 
@@ -260,14 +240,14 @@ describe "AssetTagHelpers" do
260
240
  time = stop_time_for_test
261
241
  expected_options = { :rel => "stylesheet", :type => "text/css" }
262
242
  actual_html = stylesheet_link_tag('example/demo/style')
263
- assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}"))
243
+ assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
264
244
  end
265
245
 
266
246
  it 'should display stylesheet link item with absolute path' do
267
247
  time = stop_time_for_test
268
248
  expected_options = { :rel => "stylesheet", :type => "text/css" }
269
249
  actual_html = stylesheet_link_tag('/css/style')
270
- assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/css/style.css"))
250
+ assert_has_tag('link', expected_options.merge(:href => "/css/style.css")) { actual_html }
271
251
  end
272
252
 
273
253
  it 'should display stylesheet link item with uri root' do
@@ -275,27 +255,27 @@ describe "AssetTagHelpers" do
275
255
  time = stop_time_for_test
276
256
  expected_options = { :rel => "stylesheet", :type => "text/css" }
277
257
  actual_html = stylesheet_link_tag('style')
278
- assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}"))
258
+ assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
279
259
  end
280
260
 
281
261
  it 'should display stylesheet link items' do
282
262
  time = stop_time_for_test
283
263
  actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
284
- assert_html_has_tag(actual_html, 'link', :rel => "stylesheet", :type => "text/css", :count => 3)
285
- assert_html_has_tag(actual_html, 'link', :href => "/stylesheets/style.css?#{time.to_i}")
286
- assert_html_has_tag(actual_html, 'link', :href => "/stylesheets/layout.css?#{time.to_i}")
287
- assert_html_has_tag(actual_html, 'link', :href => "http://google.com/style.css")
264
+ assert_has_tag('link', :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
265
+ assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
266
+ assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
267
+ assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
288
268
  assert_equal actual_html, stylesheet_link_tag(['style', 'layout.css', 'http://google.com/style.css'])
289
269
  end
290
270
 
291
271
  it 'should not use a timestamp if stamp setting is false' do
292
272
  self.class.expects(:asset_stamp).returns(false)
293
273
  expected_options = { :rel => "stylesheet", :type => "text/css" }
294
- assert_html_has_tag(stylesheet_link_tag('style'), 'link', expected_options.merge(:href => "/stylesheets/style.css"))
274
+ assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css")) { stylesheet_link_tag('style') }
295
275
  end
296
276
 
297
277
  it 'should display stylesheet link used custom options' do
298
- assert_html_has_tag(stylesheet_link_tag('style', :media => 'screen'), 'link', :rel => 'stylesheet', :media => 'screen')
278
+ assert_has_tag('link', :rel => 'stylesheet', :media => 'screen') { stylesheet_link_tag('style', :media => 'screen') }
299
279
  end
300
280
  end
301
281
 
@@ -303,7 +283,7 @@ describe "AssetTagHelpers" do
303
283
  it 'should display javascript item' do
304
284
  time = stop_time_for_test
305
285
  actual_html = javascript_include_tag('application')
306
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript")
286
+ assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
307
287
  assert actual_html.html_safe?
308
288
  end
309
289
 
@@ -312,58 +292,60 @@ describe "AssetTagHelpers" do
312
292
  self.class.stubs(:js_asset_folder).returns('js')
313
293
  assert_equal 'js', asset_folder_name(:js)
314
294
  actual_html = javascript_include_tag('application')
315
- assert_html_has_tag(actual_html, 'script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript")
295
+ assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
316
296
  end
317
297
 
318
298
  it 'should display javascript item for long relative path' do
319
299
  time = stop_time_for_test
320
300
  actual_html = javascript_include_tag('example/demo/application')
321
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript")
301
+ assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
322
302
  end
323
303
 
324
304
  it 'should display javascript item for path containing js' do
325
305
  time = stop_time_for_test
326
306
  actual_html = javascript_include_tag 'test/jquery.json'
327
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript")
307
+ assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
328
308
  end
329
309
 
330
310
  it 'should display javascript item for path containing period' do
331
311
  time = stop_time_for_test
332
312
  actual_html = javascript_include_tag 'test/jquery.min'
333
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript")
313
+ assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
334
314
  end
335
315
 
336
316
  it 'should display javascript item with absolute path' do
317
+ time = stop_time_for_test
337
318
  actual_html = javascript_include_tag('/js/application')
338
- assert_html_has_tag(actual_html, 'script', :src => "/js/application.js", :type => "text/javascript")
319
+ assert_has_tag('script', :src => "/js/application.js", :type => "text/javascript") { actual_html }
339
320
  end
340
321
 
341
322
  it 'should display javascript item with uri root' do
342
323
  self.class.stubs(:uri_root).returns("/blog")
343
324
  time = stop_time_for_test
344
325
  actual_html = javascript_include_tag('application')
345
- assert_html_has_tag(actual_html, 'script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript")
326
+ assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
346
327
  end
347
328
 
348
329
  it 'should not append extension to absolute paths' do
330
+ time = stop_time_for_test
349
331
  actual_html = javascript_include_tag('https://maps.googleapis.com/maps/api/js?key=value&sensor=false')
350
- assert_html_has_tag(actual_html, 'script', :src => "https://maps.googleapis.com/maps/api/js?key=value&sensor=false")
332
+ assert_has_tag('script', :src => "https://maps.googleapis.com/maps/api/js?key=value&sensor=false") { actual_html }
351
333
  end
352
334
 
353
335
  it 'should display javascript items' do
354
336
  time = stop_time_for_test
355
337
  actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
356
- assert_html_has_tag(actual_html, 'script', :type => "text/javascript", :count => 3)
357
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js?#{time.to_i}")
358
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/base.js?#{time.to_i}")
359
- assert_html_has_tag(actual_html, 'script', :src => "http://google.com/lib.js")
338
+ assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
339
+ assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
340
+ assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
341
+ assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
360
342
  assert_equal actual_html, javascript_include_tag(['application', 'base.js', 'http://google.com/lib.js'])
361
343
  end
362
344
 
363
345
  it 'should not use a timestamp if stamp setting is false' do
364
346
  self.class.expects(:asset_stamp).returns(false)
365
347
  actual_html = javascript_include_tag('application')
366
- assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js", :type => "text/javascript")
348
+ assert_has_tag('script', :src => "/javascripts/application.js", :type => "text/javascript") { actual_html }
367
349
  end
368
350
  end
369
351
 
@@ -371,33 +353,33 @@ describe "AssetTagHelpers" do
371
353
  it 'should display favicon' do
372
354
  time = stop_time_for_test
373
355
  actual_html = favicon_tag('icons/favicon.png')
374
- assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}")
356
+ assert_has_tag('link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}") { actual_html }
375
357
  end
376
358
 
377
359
  it 'should match type with file ext' do
378
360
  time = stop_time_for_test
379
361
  actual_html = favicon_tag('favicon.ico')
380
- assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}")
362
+ assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}") { actual_html }
381
363
  end
382
364
 
383
365
  it 'should allow option overrides' do
384
366
  time = stop_time_for_test
385
367
  actual_html = favicon_tag('favicon.png', :type => 'image/ico')
386
- assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}")
368
+ assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}") { actual_html }
387
369
  end
388
370
  end
389
371
 
390
372
  describe 'for #feed_tag method' do
391
373
  it 'should generate correctly link tag for rss' do
392
- assert_html_has_tag(feed_tag(:rss, "/blog/post.rss"), 'link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss')
374
+ assert_has_tag('link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss') { feed_tag :rss, "/blog/post.rss" }
393
375
  end
394
376
 
395
377
  it 'should generate correctly link tag for atom' do
396
- assert_html_has_tag(feed_tag(:atom, "/blog/post.atom"), 'link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom')
378
+ assert_has_tag('link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom') { feed_tag :atom, "/blog/post.atom" }
397
379
  end
398
380
 
399
381
  it 'should override options' do
400
- assert_html_has_tag(feed_tag(:rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title"), 'link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title')
382
+ assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" }
401
383
  end
402
384
  end
403
385