aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/number_helper_test.rb
diff options
context:
space:
mode:
authorPan GaoYong <pan.gaoyong@gmail.com>2016-04-02 19:33:33 +0800
committerPan GaoYong <pan.gaoyong@gmail.com>2016-04-02 20:13:22 +0800
commit4e977da541307dd650917b49e9410a3ca753a944 (patch)
tree9c6c076bcc8fc3cefdad57dce5f4e0fb037d94dd /activesupport/test/number_helper_test.rb
parent442207387e626d69154f942651c5fbd8d573f2c6 (diff)
downloadrails-4e977da541307dd650917b49e9410a3ca753a944.tar.gz
rails-4e977da541307dd650917b49e9410a3ca753a944.tar.bz2
rails-4e977da541307dd650917b49e9410a3ca753a944.zip
`number_to_phone` formats number with regexp
By default, this method formats US number. This commit extends its functionality to format number for other countries with a custom regular expression. number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/) # => 188-1234-5678 The output phone number is divided into three groups, so the regexp should also match three groups of numbers.
Diffstat (limited to 'activesupport/test/number_helper_test.rb')
-rw-r--r--activesupport/test/number_helper_test.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb
index 6696111476..074c872efc 100644
--- a/activesupport/test/number_helper_test.rb
+++ b/activesupport/test/number_helper_test.rb
@@ -57,6 +57,8 @@ module ActiveSupport
assert_equal("+18005551212", number_helper.number_to_phone(8005551212, :country_code => 1, :delimiter => ''))
assert_equal("22-555-1212", number_helper.number_to_phone(225551212))
assert_equal("+45-22-555-1212", number_helper.number_to_phone(225551212, :country_code => 45))
+ assert_equal("(755) 6123-4567", number_helper.number_to_phone(75561234567, pattern: /(\d{3,4})(\d{4})(\d{4})/, area_code: true))
+ assert_equal("133-1234-5678", number_helper.number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})/))
end
end