padrino-helpers 0.16.0.pre4 → 0.16.0

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