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 "FormatHelpers" do
4
+ describe 'FormatHelpers' do
5
5
  include Padrino::Helpers::FormatHelpers
6
6
 
7
7
  def app
@@ -15,7 +15,7 @@ describe "FormatHelpers" do
15
15
  describe 'for #simple_format method' do
16
16
  it 'should format simple text into html format' do
17
17
  actual_text = simple_format("Here is some basic text...\n...with a line break.")
18
- assert_equal true, actual_text.html_safe?
18
+ assert actual_text.html_safe?
19
19
  assert_equal "<p>Here is some basic text...\n<br />...with a line break.</p>", actual_text
20
20
  end
21
21
 
@@ -25,13 +25,13 @@ describe "FormatHelpers" do
25
25
  end
26
26
 
27
27
  it 'should support defining a class for the paragraphs' do
28
- actual_text = simple_format("Look me! A class!", :class => 'description')
29
- assert_equal "<p class=\"description\">Look me! A class!</p>", actual_text
28
+ actual_text = simple_format('Look me! A class!', class: 'description')
29
+ assert_equal '<p class="description">Look me! A class!</p>', actual_text
30
30
  end
31
31
 
32
32
  it 'should escape html tags' do
33
- actual_text = simple_format("Will you escape <b>that</b>?")
34
- assert_equal "<p>Will you escape &lt;b&gt;that&lt;/b&gt;?</p>", actual_text
33
+ actual_text = simple_format('Will you escape <b>that</b>?')
34
+ assert_equal '<p>Will you escape &lt;b&gt;that&lt;/b&gt;?</p>', actual_text
35
35
  end
36
36
 
37
37
  it 'should support already sanitized text' do
@@ -41,36 +41,36 @@ describe "FormatHelpers" do
41
41
 
42
42
  describe 'wrapped in a custom tag' do
43
43
  it 'should format simple text into html format' do
44
- actual_text = simple_format("Here is some basic text...\n...with a line break.", :tag => :div)
44
+ actual_text = simple_format("Here is some basic text...\n...with a line break.", tag: :div)
45
45
  assert_equal "<div>Here is some basic text...\n<br />...with a line break.</div>", actual_text
46
46
  end
47
47
 
48
48
  it 'should format more text into html format' do
49
- actual_text = simple_format("We want to put a paragraph...\n\n...right there.", :tag => :div)
49
+ actual_text = simple_format("We want to put a paragraph...\n\n...right there.", tag: :div)
50
50
  assert_equal "<div>We want to put a paragraph...</div>\n\n<div>...right there.</div>", actual_text
51
51
  end
52
52
 
53
53
  it 'should support defining a class for the paragraphs' do
54
- actual_text = simple_format("Look me! A class!", :class => 'description', :tag => :div)
55
- assert_equal "<div class=\"description\">Look me! A class!</div>", actual_text
54
+ actual_text = simple_format('Look me! A class!', class: 'description', tag: :div)
55
+ assert_equal '<div class="description">Look me! A class!</div>', actual_text
56
56
  end
57
57
  end
58
58
  end
59
59
 
60
60
  describe 'for #word_wrap method' do
61
61
  it 'should return proper formatting for 8 max width' do
62
- actual_text = word_wrap('Once upon a time', :line_width => 8)
62
+ actual_text = word_wrap('Once upon a time', line_width: 8)
63
63
  assert_equal "Once\nupon a\ntime", actual_text
64
64
  end
65
65
  it 'should return proper formatting for 1 max width' do
66
- actual_text = word_wrap('Once upon a time', :line_width => 1)
66
+ actual_text = word_wrap('Once upon a time', line_width: 1)
67
67
  assert_equal "Once\nupon\na\ntime", actual_text
68
68
  end
69
69
  it 'should return proper formatting for default width' do
70
- actual_text = word_wrap((1..50).to_a.join(" "))
71
- assert_equal (1..30).to_a.join(" ") + "\n" + (31..50).to_a.join(" "), actual_text
72
- actual_text = word_wrap((1..50).to_a.join(" "), 80)
73
- assert_equal (1..30).to_a.join(" ") + "\n" + (31..50).to_a.join(" "), actual_text
70
+ actual_text = word_wrap((1..50).to_a.join(' '))
71
+ assert_equal "#{(1..30).to_a.join(' ')}\n#{(31..50).to_a.join(' ')}", actual_text
72
+ actual_text = word_wrap((1..50).to_a.join(' '), 80)
73
+ assert_equal "#{(1..30).to_a.join(' ')}\n#{(31..50).to_a.join(' ')}", actual_text
74
74
  end
75
75
  end
76
76
 
@@ -81,38 +81,41 @@ describe "FormatHelpers" do
81
81
  end
82
82
 
83
83
  it 'should highlight with highlighter' do
84
- actual_text = highlight('Lorem ipsum dolor sit amet', 'dolor', :highlighter => '<span class="custom">\1</span>')
84
+ actual_text = highlight('Lorem ipsum dolor sit amet', 'dolor', highlighter: '<span class="custom">\1</span>')
85
85
  assert_equal 'Lorem ipsum <span class="custom">dolor</span> sit amet', actual_text
86
86
  end
87
87
  end
88
88
 
89
89
  describe 'for #truncate method' do
90
90
  it 'should support default truncation' do
91
- actual_text = truncate("Once upon a time in a world far far away")
92
- assert_equal "Once upon a time in a world...", actual_text
91
+ actual_text = truncate('Once upon a time in a world far far away')
92
+ assert_equal 'Once upon a time in a world...', actual_text
93
93
  end
94
94
  it 'should support specifying length' do
95
- actual_text = truncate("Once upon a time in a world far far away", :length => 14)
96
- assert_equal "Once upon a...", actual_text
95
+ actual_text = truncate('Once upon a time in a world far far away', length: 14)
96
+ assert_equal 'Once upon a...', actual_text
97
97
  end
98
98
  it 'should support specifying omission text' do
99
- actual_text = truncate("And they found that many people were sleeping better.", :length => 25, :omission => "(clipped)")
100
- assert_equal "And they found t(clipped)", actual_text
99
+ actual_text = truncate('And they found that many people were sleeping better.', length: 25, omission: '(clipped)')
100
+ assert_equal 'And they found t(clipped)', actual_text
101
101
  end
102
102
  end
103
103
 
104
104
  describe 'for #truncate_words method' do
105
105
  it 'should support default truncation' do
106
- actual_text = truncate_words("Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about interesting people, but most of them were about the ways of fairies and giants.")
107
- assert_equal "Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about...", actual_text
106
+ actual_text = truncate_words(<<~TEXT.chomp)
107
+ Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about interesting people,
108
+ but most of them were about the ways of fairies and giants.
109
+ TEXT
110
+ assert_equal 'Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about...', actual_text
108
111
  end
109
112
  it 'should support specifying length' do
110
- actual_text = truncate_words("Once upon a time in a world far far away", :length => 8)
111
- assert_equal "Once upon a time in a world far...", actual_text
113
+ actual_text = truncate_words('Once upon a time in a world far far away', length: 8)
114
+ assert_equal 'Once upon a time in a world far...', actual_text
112
115
  end
113
116
  it 'should support specifying omission text' do
114
- actual_text = truncate_words("And they found that many people were sleeping better.", :length => 4, :omission => "(clipped)")
115
- assert_equal "And they found that(clipped)", actual_text
117
+ actual_text = truncate_words('And they found that many people were sleeping better.', length: 4, omission: '(clipped)')
118
+ assert_equal 'And they found that(clipped)', actual_text
116
119
  end
117
120
  end
118
121
 
@@ -125,107 +128,107 @@ describe "FormatHelpers" do
125
128
  assert_equal '&lt;h1&gt;&lt;&gt;&quot;&amp;demo&amp;&quot;&lt;&gt;&lt;/h1&gt;', h('<h1><>"&demo&"<></h1>')
126
129
  end
127
130
  it 'should return default text if text is empty' do
128
- assert_equal 'default', h!("", "default")
129
- assert_equal '&nbsp;', h!("")
131
+ assert_equal 'default', h!('', 'default')
132
+ assert_equal '&nbsp;', h!('')
130
133
  end
131
134
  it 'should return text escaped if not empty' do
132
135
  assert_equal '&lt;h1&gt;hello&lt;/h1&gt;', h!('<h1>hello</h1>')
133
136
  end
134
137
  it 'should mark escaped text as safe' do
135
- assert_equal false, '<h1>hello</h1>'.html_safe?
136
- assert_equal true, h('<h1>hello</h1>').html_safe?
137
- assert_equal true, h!("", "default").html_safe?
138
+ refute '<h1>hello</h1>'.html_safe?
139
+ assert h('<h1>hello</h1>').html_safe?
140
+ assert h!('', 'default').html_safe?
138
141
  end
139
142
  end
140
143
 
141
144
  describe 'for #time_ago_in_words method' do
142
- _DAY = 24*60*60
145
+ A_DAY = 24 * 60 * 60
143
146
 
144
147
  it 'should less than 5 seconds' do
145
148
  assert_equal 'less than 5 seconds', time_ago_in_words(Time.now, true)
146
149
  end
147
150
  it 'should less than 10 seconds' do
148
- assert_equal 'less than 10 seconds', time_ago_in_words(Time.now-5, true)
151
+ assert_equal 'less than 10 seconds', time_ago_in_words(Time.now - 5, true)
149
152
  end
150
153
  it 'should less than 20 seconds' do
151
- assert_equal 'less than 20 seconds', time_ago_in_words(Time.now-10, true)
154
+ assert_equal 'less than 20 seconds', time_ago_in_words(Time.now - 10, true)
152
155
  end
153
156
  it 'should less than a minute' do
154
- assert_equal 'less than a minute', time_ago_in_words(Time.now-40, true)
157
+ assert_equal 'less than a minute', time_ago_in_words(Time.now - 40, true)
155
158
  end
156
159
  it 'should 2 minutes' do
157
- assert_equal '2 minutes', time_ago_in_words(Time.now-120, true)
160
+ assert_equal '2 minutes', time_ago_in_words(Time.now - 120, true)
158
161
  end
159
162
  it 'should display today' do
160
163
  assert_equal 'less than a minute', time_ago_in_words(Time.now)
161
164
  end
162
165
  it 'should display yesterday' do
163
- assert_equal '1 day', time_ago_in_words(Time.now - _DAY)
166
+ assert_equal '1 day', time_ago_in_words(Time.now - A_DAY)
164
167
  end
165
168
  it 'should display tomorrow' do
166
- assert_equal '1 day', time_ago_in_words(Time.now + _DAY)
169
+ assert_equal '1 day', time_ago_in_words(Time.now + A_DAY)
167
170
  end
168
171
  it 'should return future number of days' do
169
- assert_equal '4 days', time_ago_in_words(Time.now + 4*_DAY)
172
+ assert_equal '4 days', time_ago_in_words(Time.now + 4 * A_DAY)
170
173
  end
171
174
  it 'should return past days ago' do
172
- assert_equal '4 days', time_ago_in_words(Time.now - 4*_DAY)
175
+ assert_equal '4 days', time_ago_in_words(Time.now - 4 * A_DAY)
173
176
  end
174
177
  it 'should return formatted archived date' do
175
- assert_equal '3 months', time_ago_in_words(Time.now - 100*_DAY)
178
+ assert_equal '3 months', time_ago_in_words(Time.now - 100 * A_DAY)
176
179
  end
177
180
  it 'should return formatted archived year date' do
178
- assert_equal 'over 1 year', time_ago_in_words(Time.now - 500*_DAY)
181
+ assert_equal 'over 1 year', time_ago_in_words(Time.now - 500 * A_DAY)
179
182
  end
180
183
  it 'should display now as a minute ago' do
181
184
  assert_equal '1 minute', time_ago_in_words(Time.now - 60)
182
185
  end
183
186
  it 'should display a few minutes ago' do
184
- assert_equal '4 minutes', time_ago_in_words(Time.now - 4*60)
187
+ assert_equal '4 minutes', time_ago_in_words(Time.now - 4 * 60)
185
188
  end
186
189
  it 'should display an hour ago' do
187
- assert_equal 'about 1 hour', time_ago_in_words(Time.now - 60*60 + 5)
190
+ assert_equal 'about 1 hour', time_ago_in_words(Time.now - 60 * 60 + 5)
188
191
  end
189
192
  it 'should display a few hours ago' do
190
- assert_equal 'about 3 hours', time_ago_in_words(Time.now - 3*60*60 + 5*60)
193
+ assert_equal 'about 3 hours', time_ago_in_words(Time.now - 3 * 60 * 60 + 5 * 60)
191
194
  end
192
195
  it 'should display a few days ago' do
193
- assert_equal '5 days', time_ago_in_words(Time.now - 5*_DAY - 5*60)
196
+ assert_equal '5 days', time_ago_in_words(Time.now - 5 * A_DAY - 5 * 60)
194
197
  end
195
198
  it 'should display a month ago' do
196
- assert_equal 'about 1 month', time_ago_in_words(Time.now - 32*_DAY + 5*60)
199
+ assert_equal 'about 1 month', time_ago_in_words(Time.now - 32 * A_DAY + 5 * 60)
197
200
  end
198
201
  it 'should display a few months ago' do
199
- assert_equal '6 months', time_ago_in_words(Time.now - 180*_DAY - 5*60)
202
+ assert_equal '6 months', time_ago_in_words(Time.now - 180 * A_DAY - 5 * 60)
200
203
  end
201
204
  it 'should display a year ago' do
202
- assert_equal 'about 1 year', time_ago_in_words(Time.now - 365*_DAY - 5*60)
205
+ assert_equal 'about 1 year', time_ago_in_words(Time.now - 365 * A_DAY - 5 * 60)
203
206
  end
204
207
  it 'should display a few years ago' do
205
- assert_equal 'over 7 years', time_ago_in_words(Time.now - 2800*_DAY - 5*60)
208
+ assert_equal 'over 7 years', time_ago_in_words(Time.now - 2800 * A_DAY - 5 * 60)
206
209
  end
207
210
  end
208
211
 
209
212
  describe 'for #js_escape_html method' do
210
213
  it 'should escape double quotes' do
211
- assert_equal "\\\"hello\\\"", js_escape_html('"hello"')
212
- assert_equal "\\\"hello\\\"", js_escape_html(SafeBuffer.new('"hello"'))
214
+ assert_equal '\"hello\"', js_escape_html('"hello"')
215
+ assert_equal '\"hello\"', js_escape_html(SafeBuffer.new('"hello"'))
213
216
  end
214
217
  it 'should escape single quotes' do
215
218
  assert_equal "\\'hello\\'", js_escape_html("'hello'")
216
219
  assert_equal "\\'hello\\'", js_escape_html(SafeBuffer.new("'hello'"))
217
220
  end
218
221
  it 'should escape html tags and breaks' do
219
- assert_equal "\\n\\n<p>hello<\\/p>\\n", js_escape_html("\n\r<p>hello</p>\r\n")
220
- assert_equal "\\n\\n<p>hello<\\/p>\\n", js_escape_html(SafeBuffer.new("\n\r<p>hello</p>\r\n"))
222
+ assert_equal '\\n\\n<p>hello<\\/p>\\n', js_escape_html("\n\r<p>hello</p>\r\n")
223
+ assert_equal '\\n\\n<p>hello<\\/p>\\n', js_escape_html(SafeBuffer.new("\n\r<p>hello</p>\r\n"))
221
224
  end
222
225
  it 'should escape data-confirm attribute' do
223
- assert_equal "<data-confirm=\\\"are you sure\\\">", js_escape_html("<data-confirm=\"are you sure\">")
224
- assert_equal "<data-confirm=\\\"are you sure\\\">", js_escape_html(SafeBuffer.new("<data-confirm=\"are you sure\">"))
226
+ assert_equal '<data-confirm=\"are you sure\">', js_escape_html('<data-confirm="are you sure">')
227
+ assert_equal '<data-confirm=\"are you sure\">', js_escape_html(SafeBuffer.new('<data-confirm="are you sure">'))
225
228
  end
226
229
  it 'should keep html_safe content html_safe' do
227
- assert_equal false, js_escape_html('"hello"').html_safe?
228
- assert_equal true, js_escape_html(SafeBuffer.new('"hello"')).html_safe?
230
+ refute js_escape_html('"hello"').html_safe?
231
+ assert js_escape_html(SafeBuffer.new('"hello"')).html_safe?
229
232
  end
230
233
  end
231
234
  end
data/test/test_helpers.rb CHANGED
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require_relative 'helper'
2
2
 
3
- describe "Padrino::Helpers" do
3
+ describe 'Padrino::Helpers' do
4
4
  it 'should allow including without registering' do
5
5
  class Foo
6
6
  include Padrino::Helpers
data/test/test_locale.rb CHANGED
@@ -1,20 +1,22 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require_relative 'helper'
2
2
 
3
- describe "Locale Helpers" do
4
- Dir[File.expand_path("../../lib/padrino-helpers/locale/*.yml", __FILE__)].each do |file|
3
+ describe 'Locale Helpers' do
4
+ Dir[File.expand_path('../lib/padrino-helpers/locale/*.yml', __dir__)].each do |file|
5
5
  base_original = YAML.load_file(file)
6
6
  name = File.basename(file, '.yml')
7
+
7
8
  it "should should have correct locale for #{name}" do
8
9
  base = base_original[name]['number']['format']
9
- assert !base['separator'].nil?
10
- assert !base['delimiter'].nil?
11
- assert !base['precision'].nil?
10
+ refute_nil base['separator']
11
+ refute_nil base['delimiter']
12
+ refute_nil base['precision']
13
+
12
14
  base = base_original[name]['number']['currency']['format']
13
- assert !base['format'].nil?
14
- assert !base['unit'].nil?
15
- assert !base['separator'].nil?
16
- assert !base['delimiter'].nil?
17
- assert !base['precision'].nil?
15
+ refute_nil base['format']
16
+ refute_nil base['unit']
17
+ refute_nil base['separator']
18
+ refute_nil base['delimiter']
19
+ refute_nil base['precision']
18
20
  end
19
21
  end
20
22
  end
@@ -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 "NumberHelpers" do
4
+ describe 'NumberHelpers' do
5
5
  include Padrino::Helpers::NumberHelpers
6
6
 
7
7
  def app
@@ -26,70 +26,70 @@ describe "NumberHelpers" do
26
26
 
27
27
  describe 'for number helpers functionality' do
28
28
  it 'should display number_to_currency' do
29
- assert_equal "$1,234,567,890.50", number_to_currency(1234567890.50)
30
- assert_equal "$1,234,567,890.51", number_to_currency(1234567890.506)
31
- assert_equal "$1,234,567,892", number_to_currency(1234567891.60, {:precision => 0})
32
- assert_equal "$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1})
33
- assert_equal "&pound;1234567890,50", number_to_currency(1234567890.50, {:unit => "&pound;", :separator => ",", :delimiter => ""})
34
- assert_equal "$1,234,567,890.50", number_to_currency("1234567890.50")
35
- assert_equal "1,234,567,890.50 K&#269;", number_to_currency("1234567890.50", {:unit => "K&#269;", :format => "%n %u"})
36
- assert_equal "$x", number_to_currency("x")
29
+ assert_equal '$1,234,567,890.50', number_to_currency(1_234_567_890.50)
30
+ assert_equal '$1,234,567,890.51', number_to_currency(1_234_567_890.506)
31
+ assert_equal '$1,234,567,892', number_to_currency(1_234_567_891.60, { precision: 0 })
32
+ assert_equal '$1,234,567,890.5', number_to_currency(1_234_567_890.50, { precision: 1 })
33
+ assert_equal '&pound;1234567890,50', number_to_currency(1_234_567_890.50, { unit: '&pound;', separator: ',', delimiter: '' })
34
+ assert_equal '$1,234,567,890.50', number_to_currency('1234567890.50')
35
+ assert_equal '1,234,567,890.50 K&#269;', number_to_currency('1234567890.50', { unit: 'K&#269;', format: '%n %u' })
36
+ assert_equal '$x', number_to_currency('x')
37
37
 
38
38
  assert_nil number_to_currency(nil)
39
39
  end
40
40
 
41
41
  it 'should display number_to_percentage' do
42
- assert_equal "100.000%", number_to_percentage(100)
43
- assert_equal "100%", number_to_percentage(100, {:precision => 0})
44
- assert_equal "302.06%", number_to_percentage(302.0574, {:precision => 2})
45
- assert_equal "100.000%", number_to_percentage("100")
46
- assert_equal "1000.000%", number_to_percentage("1000")
47
- assert_equal "x%", number_to_percentage("x")
48
- assert_equal "1.000,000%", number_to_percentage(1000, :delimiter => '.', :separator => ',')
42
+ assert_equal '100.000%', number_to_percentage(100)
43
+ assert_equal '100%', number_to_percentage(100, { precision: 0 })
44
+ assert_equal '302.06%', number_to_percentage(302.0574, { precision: 2 })
45
+ assert_equal '100.000%', number_to_percentage('100')
46
+ assert_equal '1000.000%', number_to_percentage('1000')
47
+ assert_equal 'x%', number_to_percentage('x')
48
+ assert_equal '1.000,000%', number_to_percentage(1000, delimiter: '.', separator: ',')
49
49
 
50
50
  assert_nil number_to_percentage(nil)
51
51
  end
52
52
 
53
53
  it 'should display number_with_delimiter' do
54
- assert_equal "12,345,678", number_with_delimiter(12345678)
55
- assert_equal "0", number_with_delimiter(0)
56
- assert_equal "123", number_with_delimiter(123)
57
- assert_equal "123,456", number_with_delimiter(123456)
58
- assert_equal "123,456.78", number_with_delimiter(123456.78)
59
- assert_equal "123,456.789", number_with_delimiter(123456.789)
60
- assert_equal "123,456.78901", number_with_delimiter(123456.78901)
61
- assert_equal "123,456,789.78901", number_with_delimiter(123456789.78901)
62
- assert_equal "0.78901", number_with_delimiter(0.78901)
63
- assert_equal "123,456.78", number_with_delimiter("123456.78")
64
- assert_equal "x", number_with_delimiter("x")
54
+ assert_equal '12,345,678', number_with_delimiter(12_345_678)
55
+ assert_equal '0', number_with_delimiter(0)
56
+ assert_equal '123', number_with_delimiter(123)
57
+ assert_equal '123,456', number_with_delimiter(123_456)
58
+ assert_equal '123,456.78', number_with_delimiter(123_456.78)
59
+ assert_equal '123,456.789', number_with_delimiter(123_456.789)
60
+ assert_equal '123,456.78901', number_with_delimiter(123_456.78901)
61
+ assert_equal '123,456,789.78901', number_with_delimiter(123_456_789.78901)
62
+ assert_equal '0.78901', number_with_delimiter(0.78901)
63
+ assert_equal '123,456.78', number_with_delimiter('123456.78')
64
+ assert_equal 'x', number_with_delimiter('x')
65
65
 
66
66
  assert_nil number_with_delimiter(nil)
67
67
  end
68
68
 
69
69
  it 'should display number_with_delimiter with options' do
70
- assert_equal '12 345 678', number_with_delimiter(12345678, :delimiter => ' ')
71
- assert_equal '12,345,678-05', number_with_delimiter(12345678.05, :separator => '-')
72
- assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.')
73
- assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',')
70
+ assert_equal '12 345 678', number_with_delimiter(12_345_678, delimiter: ' ')
71
+ assert_equal '12,345,678-05', number_with_delimiter(12_345_678.05, separator: '-')
72
+ assert_equal '12.345.678,05', number_with_delimiter(12_345_678.05, separator: ',', delimiter: '.')
73
+ assert_equal '12.345.678,05', number_with_delimiter(12_345_678.05, delimiter: '.', separator: ',')
74
74
  end
75
75
 
76
76
  it 'should display number_with_precision' do
77
- assert_equal "111.235", number_with_precision(111.2346)
78
- assert_equal "111.23", number_with_precision(111.2346, :precision => 2)
79
- assert_equal "111.00", number_with_precision(111, :precision => 2)
80
- assert_equal "111.235", number_with_precision("111.2346")
81
- assert_equal "3268", number_with_precision((32.6751 * 100.00), :precision => 0)
82
- assert_equal "112", number_with_precision(111.60, :precision => 0)
83
- assert_equal "1234567892", number_with_precision(1234567891.60, :precision => 0)
77
+ assert_equal '111.235', number_with_precision(111.2346)
78
+ assert_equal '111.23', number_with_precision(111.2346, precision: 2)
79
+ assert_equal '111.00', number_with_precision(111, precision: 2)
80
+ assert_equal '111.235', number_with_precision('111.2346')
81
+ assert_equal '3268', number_with_precision(32.6751 * 100.00, precision: 0)
82
+ assert_equal '112', number_with_precision(111.60, precision: 0)
83
+ assert_equal '1234567892', number_with_precision(1_234_567_891.60, precision: 0)
84
84
 
85
85
  # Return non-numeric params unchanged.
86
- assert_equal "x", number_with_precision("x")
86
+ assert_equal 'x', number_with_precision('x')
87
87
  assert_nil number_with_precision(nil)
88
88
  end
89
89
 
90
90
  it 'should display number_with_precision with custom delimiter and separator' do
91
- assert_equal '31,83', number_with_precision(31.826, :precision => 2, :separator => ',')
92
- assert_equal '1.231,83', number_with_precision(1231.826, :precision => 2, :separator => ',', :delimiter => '.')
91
+ assert_equal '31,83', number_with_precision(31.826, precision: 2, separator: ',')
92
+ assert_equal '1.231,83', number_with_precision(1231.826, precision: 2, separator: ',', delimiter: '.')
93
93
  end
94
94
 
95
95
  it 'should display number_to_human_size' do
@@ -99,20 +99,20 @@ describe "NumberHelpers" do
99
99
  assert_equal '123 Bytes', number_to_human_size(123.0)
100
100
  assert_equal '123 Bytes', number_to_human_size(123)
101
101
  assert_equal '1.2 KB', number_to_human_size(1234)
102
- assert_equal '12.1 KB', number_to_human_size(12345)
103
- assert_equal '1.2 MB', number_to_human_size(1234567)
104
- assert_equal '1.1 GB', number_to_human_size(1234567890)
105
- assert_equal '1.1 TB', number_to_human_size(1234567890123)
102
+ assert_equal '12.1 KB', number_to_human_size(12_345)
103
+ assert_equal '1.2 MB', number_to_human_size(1_234_567)
104
+ assert_equal '1.1 GB', number_to_human_size(1_234_567_890)
105
+ assert_equal '1.1 TB', number_to_human_size(1_234_567_890_123)
106
106
  assert_equal '1025 TB', number_to_human_size(terabytes(1025))
107
107
  assert_equal '444 KB', number_to_human_size(kilobytes(444))
108
108
  assert_equal '1023 MB', number_to_human_size(megabytes(1023))
109
109
  assert_equal '3 TB', number_to_human_size(terabytes(3))
110
- assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2)
111
- assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4)
112
- assert_equal '123 Bytes', number_to_human_size("123")
113
- assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0123), :precision => 2)
114
- assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0100), :precision => 4)
115
- assert_equal '10 KB', number_to_human_size(kilobytes(10.000), :precision => 4)
110
+ assert_equal '1.18 MB', number_to_human_size(1_234_567, precision: 2)
111
+ assert_equal '3 Bytes', number_to_human_size(3.14159265, precision: 4)
112
+ assert_equal '123 Bytes', number_to_human_size('123')
113
+ assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0123), precision: 2)
114
+ assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0100), precision: 4)
115
+ assert_equal '10 KB', number_to_human_size(kilobytes(10.000), precision: 4)
116
116
  assert_equal '1 Byte', number_to_human_size(1.1)
117
117
  assert_equal '10 Bytes', number_to_human_size(10)
118
118
 
@@ -120,21 +120,21 @@ describe "NumberHelpers" do
120
120
  end
121
121
 
122
122
  it 'should display number_to_human_size with options' do
123
- assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2)
124
- assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4)
125
- assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0123), :precision => 2)
126
- assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0100), :precision => 4)
127
- assert_equal '10 KB', number_to_human_size(kilobytes(10.000), :precision => 4)
128
- assert_equal '1 TB', number_to_human_size(1234567890123, :precision => 0)
129
- assert_equal '500 MB', number_to_human_size(524288000, :precision => 0)
130
- assert_equal '40 KB', number_to_human_size(41010, :precision => 0)
131
- assert_equal '40 KB', number_to_human_size(41100, :precision => 0)
123
+ assert_equal '1.18 MB', number_to_human_size(1_234_567, precision: 2)
124
+ assert_equal '3 Bytes', number_to_human_size(3.14159265, precision: 4)
125
+ assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0123), precision: 2)
126
+ assert_equal '1.01 KB', number_to_human_size(kilobytes(1.0100), precision: 4)
127
+ assert_equal '10 KB', number_to_human_size(kilobytes(10.000), precision: 4)
128
+ assert_equal '1 TB', number_to_human_size(1_234_567_890_123, precision: 0)
129
+ assert_equal '500 MB', number_to_human_size(524_288_000, precision: 0)
130
+ assert_equal '40 KB', number_to_human_size(41_010, precision: 0)
131
+ assert_equal '40 KB', number_to_human_size(41_100, precision: 0)
132
132
  end
133
133
 
134
134
  it 'should display number_to_human_size with custom delimiter and separator' do
135
- assert_equal '1,01 KB', number_to_human_size(kilobytes(1.0123), :precision => 2, :separator => ',')
136
- assert_equal '1,01 KB', number_to_human_size(kilobytes(1.0100), :precision => 4, :separator => ',')
137
- assert_equal '1.000,1 TB', number_to_human_size(terabytes(1000.1), :delimiter => '.', :separator => ',')
135
+ assert_equal '1,01 KB', number_to_human_size(kilobytes(1.0123), precision: 2, separator: ',')
136
+ assert_equal '1,01 KB', number_to_human_size(kilobytes(1.0100), precision: 4, separator: ',')
137
+ assert_equal '1.000,1 TB', number_to_human_size(terabytes(1000.1), delimiter: '.', separator: ',')
138
138
  end
139
139
  end
140
140
  end