money_helper 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9409dd10ed69a492d053ef2f48f2df62b16b9eed8834f12c543dbc4865b1cfb
4
- data.tar.gz: 134b17f59322299c63b49e516af4c82ebd9e1359f759184a17b06aaa0f4f6fa7
3
+ metadata.gz: df602a2214fc58f6ccf9041f9cce6cc87ba22609f6d8314b6a497b5802de48ff
4
+ data.tar.gz: 46e3888d004f525559bf11b657e7cb504eb9c12f5dcaed61a56b18f1469a1e64
5
5
  SHA512:
6
- metadata.gz: c6a1d9d53b70a8e0e8aa50a2cfabcb48b56f38b09dbc8f4e8d2ee2746a7ae2786b33875d732a87d00d911f52acac8490ca59a5c66e9abe8384e6220dfede353c
7
- data.tar.gz: f36758af1bc845d8449ed052088b293a4659723cab6054112f960be5785f59932e480d26b783fc699ce206b4492d33669bc3861acec827fded3409f1c4171460
6
+ metadata.gz: 1b5f70766be6b1091e40266cb5c3cbcb34d0457e37511e60537935bc4408dada70693d0141e3c95840894f3a3d34658a99cd1354c413b58c97484047448dcecc
7
+ data.tar.gz: 7eb7051305203fed98bed96d14c2651c989fc498c58859802a85bdd26e7dda11792cef78ad9c0290530b3cd7bd69d4c94c2664cfc0bb4f487584c68e86016e25
@@ -0,0 +1,47 @@
1
+ version: 2.1
2
+
3
+ references:
4
+ set_env: &set_env
5
+ run:
6
+ name: Set up environment
7
+ command: |
8
+ echo "export BUNDLE_GEMFILE=$(pwd)/gemfiles/activesupport_$ACTIVESUPPORT_VERSION.gemfile" >> $BASH_ENV
9
+ bundle: &bundle
10
+ run:
11
+ name: Install dependencies
12
+ command: bundle install
13
+ test: &test
14
+ run:
15
+ name: Run test suite
16
+ command: bundle exec rake
17
+
18
+ jobs:
19
+ test:
20
+ docker:
21
+ - image: "cimg/ruby:<< parameters.ruby_version >>"
22
+ parameters:
23
+ ruby_version:
24
+ type: string
25
+ activesupport_version:
26
+ type: string
27
+ environment:
28
+ ACTIVESUPPORT_VERSION: << parameters.activesupport_version >>
29
+ steps:
30
+ - checkout
31
+ - <<: *set_env
32
+ - <<: *bundle
33
+ - <<: *test
34
+
35
+ workflows:
36
+ default:
37
+ jobs:
38
+ - test:
39
+ matrix:
40
+ parameters:
41
+ ruby_version: ["2.5", "2.6", "2.7"]
42
+ activesupport_version: ["40", "41", "42", "50", "51", "52", "edge"]
43
+ exclude:
44
+ - ruby_version: "2.5"
45
+ activesupport_version: "edge"
46
+ - ruby_version: "2.6"
47
+ activesupport_version: "edge"
data/.gitignore CHANGED
@@ -2,3 +2,5 @@ Gemfile.lock
2
2
  gemfiles/*.lock
3
3
  gemfiles/.bundle
4
4
  gemfiles/vendor
5
+ pkg
6
+ .DS_Store
data/.rubocop.yml CHANGED
@@ -15,4 +15,7 @@ Style/Documentation:
15
15
  Naming/MethodName:
16
16
  Enabled: false
17
17
 
18
+ Style/AsciiComments:
19
+ Enabled: false
20
+
18
21
  inherit_from: .rubocop_todo.yml
data/CHANGELOG.md CHANGED
@@ -1,39 +1,49 @@
1
- ### 1.0.2 (2019/4/19)
1
+ ### 2.0.1 (Next)
2
+
3
+ * Your contribution here.
4
+
5
+ ### 2.0.0 (2021-09-20)
6
+
7
+ #### Breaking Changes
8
+
9
+ * [#20](https://github.com/artsy/money_helper/pull/20): Update `money_to_text` and `money_range_to_text` to expect amounts in minor unit and simplify formatting; drop support for Ruby 2.3 and 2.4 - [@starsirius](https://github.com/starsirius)
10
+
11
+ ### 1.0.2 (2019-04-19)
2
12
 
3
13
  * [#16](https://github.com/artsy/money_helper/pull/16): Remove deprecation warnings - [@sweir27](https://github.com/sweir27).
4
14
  * [#15](https://github.com/artsy/money_helper/pull/15): Added Rubocop - [@dblock](https://github.com/dblock).
5
15
 
6
- ### 1.0.1 (2017/4/3)
16
+ ### 1.0.1 (2017-04-03)
7
17
 
8
18
  * Relaxed activesupport version dependency - [@dblock](https://github.com/dblock).
9
19
  * The `money_to_text` method now takes options - [@mzikherman](https://github.com/mzikherman).
10
20
  * Added `symbol_with_optional_iso_code` - [@mzikherman](https://github.com/mzikherman).
11
21
 
12
- ### 1.0.0 (2015/3/7)
22
+ ### 1.0.0 (2015-03-07)
13
23
 
14
24
  * Added compatibility with Money 6.5.1+, including new currency symbols - [@syakhmi](https://github.com/syakhmi).
15
25
 
16
- ### 0.0.5 (2014/4/12)
26
+ ### 0.0.5 (2014-04-12)
17
27
 
18
28
  * Added compatibility with Money 6.1+ - [@syakhmi](https://github.com/syakhmi).
19
29
  * Dropped support for pre 6.0 versions of Money - [@syakhmi](https://github.com/syakhmi).
20
30
 
21
- ### 0.0.4 (2014/1/8)
31
+ ### 0.0.4 (2014-01-08)
22
32
 
23
33
  * Added compatibility with Money 6.x - [@dblock](https://github.com/dblock).
24
34
  * Avoid failing on deprecated currencies (such as ITL) - [@joeyAghion](https://github.com/joeyAghion).
25
35
 
26
- ### 0.0.3 (2013/7/17)
36
+ ### 0.0.3 (2013-07-17)
27
37
 
28
38
  * Added support for currencies that don't have a symbol, eg. Uzbekistan Som (UZS) - [@dblock](https://github.com/dblock).
29
39
 
30
- ### 0.0.2 (2013/7/16)
40
+ ### 0.0.2 (2013-07-16)
31
41
 
32
42
  * Added unit tests - [@syakhmi](https://github.com/syakhmi).
33
43
  * Added support for Cambodian riel - [@syakhmi](https://github.com/syakhmi).
34
44
  * Added dependencies to gemspec - [@syakhmi](https://github.com/syakhmi).
35
45
  * Now defaults to USD when currency not specified - [@syakhmi](https://github.com/syakhmi).
36
46
 
37
- ### 0.0.1 (2013/7/12)
47
+ ### 0.0.1 (2013-07-12)
38
48
 
39
49
  * Initial public release - [@syakhmi](https://github.com/syakhmi).
data/README.md CHANGED
@@ -1,34 +1,31 @@
1
- MoneyHelper
1
+ MoneyHelper [![CircleCI][ci_badge]][circleci]
2
2
  ============
3
3
 
4
4
  A simple module to assist in formatting unambiguous prices and price ranges in international currencies in a Roman Script environment.
5
5
 
6
- [![Build Status](https://travis-ci.org/artsy/money_helper.svg?branch=master)](https://travis-ci.org/artsy/money_helper)
7
-
8
6
  Usage
9
7
  -----
10
8
 
11
9
  Examples:
12
10
 
13
11
  ``` ruby
14
- money_to_text(10000, 'AUD')
15
- ```
16
- produces "AUD $10,000"
12
+ money_to_text(10000, currency: 'AUD')
13
+ #=> 'AUD $100.00'
17
14
 
18
- ``` ruby
19
- money_to_text(10000, 'AUD', true)
20
- ```
21
- produces "10,000"
15
+ money_to_text(10000, currency: 'AUD', with_currency: false, with_symbol: false)
16
+ #=> '100.00'
22
17
 
23
- ``` ruby
24
- money_range_to_text(10000, 40000, 'AUD', ' ... ')
18
+ money_range_to_text(10000, 40000, currency: 'AUD')
19
+ #=> 'AUD $100.00 - 400.00'
20
+
21
+ money_range_to_text(10000, 40000, currency: 'AUD', delimiter: ' ... ')
22
+ #=> 'AUD $100.00 ... 400.00'
25
23
  ```
26
- produces: "AUD $10,000 ... 40,000"
27
24
 
28
25
  Defaults
29
26
  --------
30
27
 
31
- As of [#16](https://github.com/artsy/money_helper/pull/16) this library explicitly specifies the `Money.locale_backend = :currency` default.
28
+ As of [#16][#16] this library explicitly specifies the `Money.locale_backend = :currency` default.
32
29
 
33
30
  Contributing
34
31
  ------------
@@ -38,6 +35,15 @@ Fork the project. Make your feature addition or bug fix with tests. Send a pull
38
35
  Copyright and License
39
36
  ---------------------
40
37
 
41
- MIT License, see [LICENSE](LICENSE.md) for details.
38
+ MIT License, see [LICENSE][license] for details.
39
+
40
+ (c) 2013-2018 [Artsy][artsy], [Sahil Yakhmi][sahil_yakhmi], [Joey Aghion][joey_aghion] and [contributors][contributors].
42
41
 
43
- (c) 2013-2018 [Artsy](http://artsy.github.com), [Sahil Yakhmi](https://github.com/syakhmi), [Joey Aghion](https://github.com/joeyAghion) and [contributors](CHANGELOG.md).
42
+ [ci_badge]: https://circleci.com/gh/artsy/money_helper/tree/master.svg?style=shield
43
+ [circleci]: https://circleci.com/gh/artsy/money_helper/tree/master
44
+ [#16]: https://github.com/artsy/money_helper/pull/16
45
+ [license]: LICENSE.md
46
+ [artsy]: https://github.com/artsy
47
+ [sahil_yakhmi]: https://github.com/syakhmi
48
+ [joey_aghion]: https://github.com/joeyAghion
49
+ [contributors]: CHANGELOG.md
data/RELEASING.md CHANGED
@@ -11,9 +11,9 @@ bundle install
11
11
  rake
12
12
  ```
13
13
 
14
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/artsy/money_helper) for all supported platforms.
14
+ Check that the last build succeeded on [CI][ci] for all supported platforms.
15
15
 
16
- Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
16
+ Change "Next" in [CHANGELOG.md][changelog] to the current date.
17
17
 
18
18
  ```
19
19
  ### 0.2.2 (2015/7/10)
@@ -42,7 +42,7 @@ Pushed money_helper 0.2.2 to rubygems.org.
42
42
 
43
43
  ### Prepare for the Next Version
44
44
 
45
- Add the next release to [CHANGELOG.md](CHANGELOG.md).
45
+ Add the next release to [CHANGELOG.md][changelog].
46
46
 
47
47
  ```
48
48
  ### 0.2.3 (Next)
@@ -50,7 +50,7 @@ Add the next release to [CHANGELOG.md](CHANGELOG.md).
50
50
  * Your contribution here.
51
51
  ```
52
52
 
53
- Increment the third version number in [lib/version.rb](lib/version.rb).
53
+ Increment the third version number in [lib/version.rb][version].
54
54
 
55
55
  Commit your changes.
56
56
 
@@ -59,3 +59,7 @@ git add CHANGELOG.md lib/version.rb
59
59
  git commit -m "Preparing for next development iteration, 0.2.3."
60
60
  git push origin master
61
61
  ```
62
+
63
+ [ci]: https://circleci.com/gh/artsy/money_helper/tree/master
64
+ [changelog]: CHANGELOG.md
65
+ [version]: lib/version.rb
data/lib/money_helper.rb CHANGED
@@ -18,25 +18,28 @@ module MoneyHelper
18
18
  #
19
19
  # = Example
20
20
  #
21
- # $10,000; HKD $10,000 for (10000, "USD") and (10000, "HKD"), respectively
21
+ # MoneyHelper.money_to_text(30_175_93, currency: 'USD') #=> 'USD $30,175.93'
22
+ # MoneyHelper.money_to_text(30_175_93, currency: 'EUR') #=> 'EUR €30.175,93'
23
+ # MoneyHelper.money_to_text(30_175_93) #=> 'USD $30,175.93'
22
24
  #
23
25
  # = Arguments
24
26
  #
25
- # amount: (Float)
26
- # currency: (String)
27
- # number_only: (Boolean) optional flag to exclude currency indicators (retains number formatting
28
- # specific to currency)
29
- def self.money_to_text(amount, currency, number_only = false, options = {})
30
- return nil unless amount.present?
27
+ # amount_minor: (Integer) amount in minor unit
28
+ # currency: (String) optional ISO currency code, defaulting to USD
29
+ # with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
30
+ # with_symbol: (Boolean) optional flag to include currency symbol, defaulting to true
31
+ def self.money_to_text(amount_minor, currency: 'USD', with_currency: true, with_symbol: true)
32
+ return '' if amount_minor.blank?
31
33
 
32
- currency = 'USD' if currency.blank?
33
- valid_currency = code_valid?(currency) ? currency : 'USD'
34
- symbol = symbol_for_code(currency)
35
- include_symbol = !number_only && symbol.present? && OK_SYMBOLS.include?(symbol)
36
- subunit_factor = Money::Currency.new(valid_currency).subunit_to_unit
37
- money_options = { no_cents: true, format: '%u %n', symbol: include_symbol }.merge(options)
38
- (number_only || SYMBOL_ONLY.include?(currency) ? '' : currency + ' ') +
39
- Money.new(amount * subunit_factor.ceil, valid_currency).format(money_options).delete(' ')
34
+ money_options = {
35
+ format: '%u%n',
36
+ symbol: with_symbol
37
+ }
38
+
39
+ formatted_amount = Money.new(amount_minor, currency).format(money_options)
40
+ formatted_currency = with_currency ? currency.upcase : ''
41
+
42
+ "#{formatted_currency} #{formatted_amount}".strip
40
43
  end
41
44
 
42
45
  def self.symbol_with_optional_iso_code(currency = 'USD')
@@ -55,28 +58,30 @@ module MoneyHelper
55
58
  #
56
59
  # = Example
57
60
  #
58
- # $10,000 - 20,000 for (10000, 20000, "USD")
59
- # HKD $10,000 - 20,000 for (10000, 20000, "HKD")
60
- # $10,000 ... 20,000 for (10000, 20000, "USD", " ... ")
61
- # HKD $10,000 ... 20,000 for (10000, 20000, "HKD", " ... ")
61
+ # MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD') #=> 'USD $30,175.93 - 40,983.27'
62
+ # MoneyHelper.money_range_to_text(30_175_93, 40_983_27) #=> 'USD $30,175.93 - 40,983.27'
63
+ # MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR') #=> 'EUR €30.175,93 - 40.983,27'
64
+ # MoneyHelper.money_range_to_text(30_175_93, 40_983_27, delimiter: ' ... ') #=> 'USD $30,175.93 ... 40,983.27'
62
65
  #
63
66
  # = Arguments
64
67
  #
65
- # low: (Float)
66
- # high: (Float)
67
- # currency: (String)
68
+ # low: (Integer) amount in minor unit
69
+ # high: (Integer) amount in minor unit
70
+ # currency: (String) optional ISO currency code, defaulting to USD
68
71
  # delimiter: (String) optional
69
- def self.money_range_to_text(low, high, currency, delimiter = ' - ')
72
+ def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ')
70
73
  if low.blank? && high.blank?
71
- nil
74
+ ''
72
75
  elsif low.blank?
73
- 'Under ' + money_to_text(high, currency)
76
+ 'Under ' + money_to_text(high, currency: currency)
74
77
  elsif high.blank?
75
- money_to_text(low, currency) + ' and up'
78
+ money_to_text(low, currency: currency) + ' and up'
76
79
  elsif low == high
77
- money_to_text(low, currency)
80
+ money_to_text(low, currency: currency)
78
81
  else
79
- [money_to_text(low, currency), money_to_text(high, currency, true)].compact.join(delimiter)
82
+ formatted_low = money_to_text(low, currency: currency)
83
+ formatted_high = money_to_text(high, currency: currency, with_currency: false, with_symbol: false)
84
+ [formatted_low, formatted_high].compact.join(delimiter)
80
85
  end
81
86
  end
82
87
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MoneyHelper
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/money_helper.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.require_paths = ['lib']
16
16
  s.homepage = 'https://github.com/artsy/money_helper'
17
17
  s.add_dependency('activesupport')
18
- s.add_dependency('money', '~> 6.5')
18
+ s.add_dependency('money', '6.16.0')
19
19
  s.add_development_dependency('appraisal')
20
20
  s.add_development_dependency('rspec', '~> 3')
21
21
  s.licenses = ['MIT']
@@ -2,152 +2,168 @@ require 'spec_helper'
2
2
 
3
3
  describe MoneyHelper do
4
4
  describe 'money_to_text' do
5
- it 'includes only symbol for well-recognizable currencies' do
6
- expect(MoneyHelper.money_to_text(30_000, 'EUR')).to eql('30.000')
7
- expect(MoneyHelper.money_to_text(30_000, 'GBP')).to eql('£30,000')
8
- expect(MoneyHelper.money_to_text(30_000, 'MYR')).to eql('RM30,000')
9
- expect(MoneyHelper.money_to_text(30_000, 'TRY')).to eql('TRY 30.000')
10
- expect(MoneyHelper.money_to_text(30_000, 'USD')).to eql('$30,000')
11
- end
12
- it 'includes ISO code and symbol for ambiguous currencies' do
13
- expect(MoneyHelper.money_to_text(30_000, 'AUD')).to eql('AUD $30,000')
14
- expect(MoneyHelper.money_to_text(30_000, 'ARS')).to eql('ARS $30.000')
15
- expect(MoneyHelper.money_to_text(30_000, 'BBD')).to eql('BBD $30,000')
16
- expect(MoneyHelper.money_to_text(30_000, 'BMD')).to eql('BMD $30,000')
17
- expect(MoneyHelper.money_to_text(30_000, 'BND')).to eql('BND $30,000')
18
- expect(MoneyHelper.money_to_text(30_000, 'BSD')).to eql('BSD $30,000')
19
- expect(MoneyHelper.money_to_text(30_000, 'BZD')).to eql('BZD $30,000')
20
- expect(MoneyHelper.money_to_text(30_000, 'CAD')).to eql('CAD $30,000')
21
- expect(MoneyHelper.money_to_text(30_000, 'CLP')).to eql('CLP $30.000')
22
- expect(MoneyHelper.money_to_text(30_000, 'COP')).to eql('COP $30.000')
23
- expect(MoneyHelper.money_to_text(30_000, 'CUC')).to eql('CUC $30,000')
24
- expect(MoneyHelper.money_to_text(30_000, 'CUP')).to eql('CUP $30,000')
25
- expect(MoneyHelper.money_to_text(30_000, 'DOP')).to eql('DOP $30,000')
26
- expect(MoneyHelper.money_to_text(30_000, 'FJD')).to eql('FJD $30,000')
27
- expect(MoneyHelper.money_to_text(30_000, 'GYD')).to eql('GYD $30,000')
28
- expect(MoneyHelper.money_to_text(30_000, 'HKD')).to eql('HKD $30,000')
29
- expect(MoneyHelper.money_to_text(30_000, 'JMD')).to eql('JMD $30,000')
30
- expect(MoneyHelper.money_to_text(30_000, 'KYD')).to eql('KYD $30,000')
31
- expect(MoneyHelper.money_to_text(30_000, 'LRD')).to eql('LRD $30,000')
32
- expect(MoneyHelper.money_to_text(30_000, 'MXN')).to eql('MXN $30,000')
33
- expect(MoneyHelper.money_to_text(30_000, 'NAD')).to eql('NAD $30,000')
34
- expect(MoneyHelper.money_to_text(30_000, 'NZD')).to eql('NZD $30,000')
35
- expect(MoneyHelper.money_to_text(30_000, 'SBD')).to eql('SBD $30,000')
36
- expect(MoneyHelper.money_to_text(30_000, 'SGD')).to eql('SGD $30,000')
37
- expect(MoneyHelper.money_to_text(30_000, 'SRD')).to eql('SRD $30,000')
38
- expect(MoneyHelper.money_to_text(30_000, 'TWD')).to eql('TWD $30,000')
39
- expect(MoneyHelper.money_to_text(30_000, 'TTD')).to eql('TTD $30,000')
40
- expect(MoneyHelper.money_to_text(30_000, 'UYU')).to eql('UYU $30.000')
41
- expect(MoneyHelper.money_to_text(30_000, 'XCD')).to eql('XCD $30,000')
42
- expect(MoneyHelper.money_to_text(30_000, 'ZWL')).to eql('ZWL $30,000')
43
-
44
- expect(MoneyHelper.money_to_text(30_000, 'FKP')).to eql('FKP £30,000')
45
- expect(MoneyHelper.money_to_text(30_000, 'GIP')).to eql('GIP £30,000')
46
- expect(MoneyHelper.money_to_text(30_000, 'SDG')).to eql('SDG £30,000')
47
- expect(MoneyHelper.money_to_text(30_000, 'SHP')).to eql('SHP £30,000')
48
-
49
- expect(MoneyHelper.money_to_text(30_000, 'CNY')).to eql('CNY ¥30,000')
50
- expect(MoneyHelper.money_to_text(30_000, 'JPY')).to eql('JPY ¥30,000')
51
-
52
- expect(MoneyHelper.money_to_text(30_000, 'ALL')).to eql('ALL L30,000')
53
- expect(MoneyHelper.money_to_text(30_000, 'HNL')).to eql('HNL L30,000')
54
- expect(MoneyHelper.money_to_text(30_000, 'LSL')).to eql('LSL L30,000')
55
- expect(MoneyHelper.money_to_text(30_000, 'MDL')).to eql('MDL L30,000')
56
- expect(MoneyHelper.money_to_text(30_000, 'RON')).to eql('RON 30.000')
57
- expect(MoneyHelper.money_to_text(30_000, 'SZL')).to eql('SZL E30,000')
58
-
59
- expect(MoneyHelper.money_to_text(30_000, 'ANG')).to eql('ANG ƒ30.000')
60
- expect(MoneyHelper.money_to_text(30_000, 'AWG')).to eql('AWG ƒ30,000')
61
-
62
- expect(MoneyHelper.money_to_text(30_000, 'BWP')).to eql('BWP P30,000')
63
- expect(MoneyHelper.money_to_text(30_000, 'MOP')).to eql('MOP P30,000')
64
-
65
- expect(MoneyHelper.money_to_text(30_000, 'CRC')).to eql('CRC ₡30.000')
66
- expect(MoneyHelper.money_to_text(30_000, 'SVC')).to eql('SVC 30,000')
67
-
68
- expect(MoneyHelper.money_to_text(30_000, 'MUR')).to eql('MUR ₨30,000')
69
- expect(MoneyHelper.money_to_text(30_000, 'NPR')).to eql('NPR ₨30,000')
70
- expect(MoneyHelper.money_to_text(30_000, 'PKR')).to eql('PKR ₨30,000')
71
- expect(MoneyHelper.money_to_text(30_000, 'SCR')).to eql('SCR 30,000')
72
- end
73
- it 'includes ISO code and symbol for difficult to recognize symbols' do
74
- expect(MoneyHelper.money_to_text(30_000, 'AMD')).to eql('AMD դր.30,000')
75
- expect(MoneyHelper.money_to_text(30_000, 'BDT')).to eql('BDT 30,000')
76
- expect(MoneyHelper.money_to_text(30_000, 'BRL')).to eql('BRL R$30.000')
77
- expect(MoneyHelper.money_to_text(30_000, 'GMD')).to eql('GMD D30,000')
78
- expect(MoneyHelper.money_to_text(30_000, 'GEL')).to eql('GEL ლ30,000')
79
- expect(MoneyHelper.money_to_text(30_000, 'GHS')).to eql('GHS ₵30,000')
80
- expect(MoneyHelper.money_to_text(30_000, 'GTQ')).to eql('GTQ Q30,000')
81
- expect(MoneyHelper.money_to_text(30_000, 'HTG')).to eql('HTG G30,000')
82
- expect(MoneyHelper.money_to_text(30_000, 'IDR')).to eql('IDR Rp30.000')
83
- expect(MoneyHelper.money_to_text(30_000, 'ILS')).to eql('ILS 30,000')
84
- expect(MoneyHelper.money_to_text(30_000, 'INR')).to eql('INR 30,000')
85
- expect(MoneyHelper.money_to_text(30_000, 'KHR')).to eql('KHR 30,000')
86
- expect(MoneyHelper.money_to_text(30_000, 'KPW')).to eql('KPW 30,000')
87
- expect(MoneyHelper.money_to_text(30_000, 'LAK')).to eql('LAK 30,000')
88
- expect(MoneyHelper.money_to_text(30_000, 'MNT')).to eql('MNT ₮30,000')
89
- expect(MoneyHelper.money_to_text(30_000, 'NIO')).to eql('NIO C$30,000')
90
- expect(MoneyHelper.money_to_text(30_000, 'NGN')).to eql('NGN ₦30,000')
91
- expect(MoneyHelper.money_to_text(30_000, 'PGK')).to eql('PGK K30,000')
92
- expect(MoneyHelper.money_to_text(30_000, 'PHP')).to eql('PHP 30,000')
93
- expect(MoneyHelper.money_to_text(30_000, 'PYG')).to eql('PYG ₲30,000')
94
- expect(MoneyHelper.money_to_text(30_000, 'RUB')).to eql('RUB 30.000')
95
- expect(MoneyHelper.money_to_text(30_000, 'THB')).to eql('THB ฿30,000')
96
- expect(MoneyHelper.money_to_text(30_000, 'TOP')).to eql('TOP T$30,000')
97
- expect(MoneyHelper.money_to_text(30_000, 'TMT')).to eql('TMT T30,000')
98
- expect(MoneyHelper.money_to_text(30_000, 'UAH')).to eql('UAH ₴30,000')
99
- expect(MoneyHelper.money_to_text(30_000, 'VND')).to eql('VND ₫30.000')
100
- expect(MoneyHelper.money_to_text(30_000, 'WST')).to eql('WST T30,000')
101
- expect(MoneyHelper.money_to_text(30_000, 'ZAR')).to eql('ZAR R30,000')
102
- end
103
- it "includes only ISO code for currencies that don't have a symbol" do
104
- expect(MoneyHelper.money_to_text(30_000, 'UZS')).to eql('UZS 30,000')
105
- end
106
- it 'includes only ISO code for RTL symbols' do
107
- expect(MoneyHelper.money_to_text(30_000, 'AFN')).to eql('AFN 30,000')
108
- expect(MoneyHelper.money_to_text(30_000, 'DZD')).to eql('DZD 30,000')
109
- expect(MoneyHelper.money_to_text(30_000, 'BHD')).to eql('BHD 30,000')
110
- expect(MoneyHelper.money_to_text(30_000, 'EGP')).to eql('EGP 30,000')
111
- expect(MoneyHelper.money_to_text(30_000, 'IRR')).to eql('IRR 30,000')
112
- expect(MoneyHelper.money_to_text(30_000, 'IQD')).to eql('IQD 30,000')
113
- expect(MoneyHelper.money_to_text(30_000, 'JOD')).to eql('JOD 30,000')
114
- expect(MoneyHelper.money_to_text(30_000, 'KWD')).to eql('KWD 30,000')
115
- expect(MoneyHelper.money_to_text(30_000, 'LBP')).to eql('LBP 30,000')
116
- expect(MoneyHelper.money_to_text(30_000, 'LYD')).to eql('LYD 30,000')
117
- expect(MoneyHelper.money_to_text(30_000, 'MAD')).to eql('MAD 30,000')
118
- expect(MoneyHelper.money_to_text(30_000, 'OMR')).to eql('OMR 30,000')
119
- expect(MoneyHelper.money_to_text(30_000, 'JOD')).to eql('JOD 30,000')
120
- expect(MoneyHelper.money_to_text(30_000, 'QAR')).to eql('QAR 30,000')
121
- expect(MoneyHelper.money_to_text(30_000, 'SAR')).to eql('SAR 30,000')
122
- expect(MoneyHelper.money_to_text(30_000, 'SYP')).to eql('SYP 30,000')
123
- expect(MoneyHelper.money_to_text(30_000, 'TND')).to eql('TND 30,000')
124
- expect(MoneyHelper.money_to_text(30_000, 'AED')).to eql('AED 30,000')
125
- expect(MoneyHelper.money_to_text(30_000, 'YER')).to eql('YER 30,000')
126
- end
127
- it 'defaults to USD when an empty string or nil is passed as the currency' do
128
- expect(MoneyHelper.money_to_text(30_000, '')).to eql('$30,000')
129
- expect(MoneyHelper.money_to_text(30_000, nil)).to eql('$30,000')
130
- end
131
- it 'returns only the formatted numeral when number_only = true' do
132
- expect(MoneyHelper.money_to_text(30_000, 'EUR', true)).to eql('30.000')
133
- expect(MoneyHelper.money_to_text(30_000, 'AUD', true)).to eql('30,000')
134
- expect(MoneyHelper.money_to_text(30_000, 'AMD', true)).to eql('30,000')
135
- expect(MoneyHelper.money_to_text(30_000, 'AFN', true)).to eql('30,000')
136
- end
137
- it 'returns nil if amount passed in is whitespace, empty string, or nil' do
138
- expect(MoneyHelper.money_to_text(' ', 'USD')).to be_nil
139
- expect(MoneyHelper.money_to_text('', 'USD')).to be_nil
140
- expect(MoneyHelper.money_to_text(nil, 'USD')).to be_nil
141
- end
142
- it "falls back to ISO code when currency can't be found" do
143
- expect(MoneyHelper.money_to_text(10_000, 'ITL')).to eql('ITL 10,000')
144
- expect(MoneyHelper.money_to_text(10_000, 'ITL', true)).to eql('10,000')
145
- end
146
- it 'allows options to be passed through and cents displayed' do
147
- expect(MoneyHelper.money_to_text(10_000.1, 'USD', nil, no_cents: false)).to eq '$10,000.10'
148
- expect(MoneyHelper.money_to_text(10_000.1, 'USD')).to eq '$10,000'
5
+ it 'includes ISO code and symbol' do
6
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD')).to eql('AUD $30,175.93')
7
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ARS')).to eql('ARS $30.175,93')
8
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BBD')).to eql('BBD $30,175.93')
9
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BMD')).to eql('BMD $30,175.93')
10
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BND')).to eql('BND $30,175.93')
11
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BSD')).to eql('BSD $30,175.93')
12
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BZD')).to eql('BZD $30,175.93')
13
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CAD')).to eql('CAD $30,175.93')
14
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CLP')).to eql('CLP $3.017.593')
15
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'COP')).to eql('COP $30.175,93')
16
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUC')).to eql('CUC $30,175.93')
17
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUP')).to eql('CUP $30,175.93')
18
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'DOP')).to eql('DOP $30,175.93')
19
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'FJD')).to eql('FJD $30,175.93')
20
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GYD')).to eql('GYD $30,175.93')
21
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'HKD')).to eql('HKD $30,175.93')
22
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'JMD')).to eql('JMD $30,175.93')
23
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'KYD')).to eql('KYD $30,175.93')
24
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'LRD')).to eql('LRD $30,175.93')
25
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MXN')).to eql('MXN $30,175.93')
26
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'NAD')).to eql('NAD $30,175.93')
27
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'NZD')).to eql('NZD $30,175.93')
28
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SBD')).to eql('SBD $30,175.93')
29
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SGD')).to eql('SGD $30,175.93')
30
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SRD')).to eql('SRD $30,175.93')
31
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TWD')).to eql('TWD $30,175.93')
32
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TTD')).to eql('TTD $30,175.93')
33
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'UYU')).to eql('UYU $U30.175,93')
34
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
35
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'XCD')).to eql('XCD $30,175.93')
36
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZWL')).to eql('ZWL $30,175.93')
37
+
38
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR 30.175,93')
39
+
40
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'FKP')).to eql('FKP £30,175.93')
41
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GBP')).to eql('GBP £30,175.93')
42
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GIP')).to eql('GIP £30,175.93')
43
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SDG')).to eql('SDG £30,175.93')
44
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SHP')).to eql('SHP £30,175.93')
45
+
46
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CNY')).to eql('CNY ¥30,175.93')
47
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
48
+
49
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ALL')).to eql('ALL L30,175.93')
50
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'HNL')).to eql('HNL L30,175.93')
51
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'LSL')).to eql('LSL L30,175.93')
52
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MDL')).to eql('MDL L30,175.93')
53
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MYR')).to eql('MYR RM30,175.93')
54
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'RON')).to eql('RON Lei30.175,93')
55
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SZL')).to eql('SZL E30,175.93')
56
+
57
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ANG')).to eql('ANG ƒ30.175,93')
58
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AWG')).to eql('AWG ƒ30,175.93')
59
+
60
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BWP')).to eql('BWP P30,175.93')
61
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MOP')).to eql('MOP P30,175.93')
62
+
63
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'CRC')).to eql('CRC ₡30.175,93')
64
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SVC')).to eql('SVC ₡30,175.93')
65
+
66
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MUR')).to eql('MUR 30,175.93')
67
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'NPR')).to eql('NPR Rs.30,175.93')
68
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'PKR')).to eql('PKR ₨30,175.93')
69
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SCR')).to eql('SCR ₨30,175.93')
70
+
71
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD')).to eql('AMD դր.30,175.93')
72
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BDT')).to eql('BDT ৳30,175.93')
73
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BRL')).to eql('BRL R$30.175,93')
74
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GEL')).to eql('GEL 30,175.93')
75
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GHS')).to eql('GHS 30,175.93')
76
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GMD')).to eql('GMD D30,175.93')
77
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'GTQ')).to eql('GTQ Q30,175.93')
78
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'HTG')).to eql('HTG G30,175.93')
79
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'IDR')).to eql('IDR Rp30.175,93')
80
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ILS')).to eql('ILS ₪30,175.93')
81
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'INR')).to eql('INR ₹30,175.93')
82
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'KHR')).to eql('KHR ៛30,175.93')
83
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'KPW')).to eql('KPW 30,175.93')
84
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'LAK')).to eql('LAK 30,175.93')
85
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MNT')).to eql('MNT 30,175.93')
86
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'NGN')).to eql('NGN 30,175.93')
87
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'NIO')).to eql('NIO C$30,175.93')
88
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'PGK')).to eql('PGK K30,175.93')
89
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'PHP')).to eql('PHP 30,175.93')
90
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'PYG')).to eql('PYG ₲3,017,593')
91
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'RUB')).to eql('RUB ₽30.175,93')
92
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'THB')).to eql('THB ฿30,175.93')
93
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TMT')).to eql('TMT T30,175.93')
94
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TOP')).to eql('TOP T$30,175.93')
95
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TRY')).to eql('TRY 30.175,93')
96
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'UAH')).to eql('UAH 30,175.93')
97
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'VND')).to eql('VND ₫3.017.593')
98
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'WST')).to eql('WST T30,175.93')
99
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZAR')).to eql('ZAR R30,175.93')
100
+ end
101
+
102
+ it "respects currency's thousands separator and decimal mark" do
103
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
104
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR 30.175,93')
105
+ end
106
+
107
+ it "converts from currency's minor unit to major unit" do
108
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
109
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
110
+ end
111
+
112
+ it 'displays LTR for RTL symbols' do
113
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN')).to eql('AFN ؋30,175.93')
114
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'DZD')).to eql('DZD د.ج30,175.93')
115
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'BHD')).to eql('BHD د.ب3,017.593')
116
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EGP')).to eql('EGP ج.م30,175.93')
117
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'IRR')).to eql('IRR 30,175.93')
118
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'IQD')).to eql('IQD ع.د3,017.593')
119
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'JOD')).to eql('JOD د.ا3,017.593')
120
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'LYD')).to eql('LYD ل.د3,017.593')
121
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'MAD')).to eql('MAD د.م.30,175.93')
122
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'QAR')).to eql('QAR ر.ق30,175.93')
123
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'SYP')).to eql('SYP £S30,175.93')
124
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'TND')).to eql('TND د.ت3,017.593')
125
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AED')).to eql('AED د.إ30,175.93')
126
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'YER')).to eql('YER ﷼30,175.93')
127
+ end
128
+
129
+ it 'defaults to USD' do
130
+ expect(MoneyHelper.money_to_text(30_175_93)).to eql('USD $30,175.93')
131
+ end
132
+
133
+ it 'omits ISO code when with_currency is false' do
134
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false)).to eql('30.175,93')
135
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false)).to eql('$30,175.93')
136
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false)).to eql('դր.30,175.93')
137
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false)).to eql('؋30,175.93')
138
+ end
139
+
140
+ it 'omits symbol when with_symbol is false' do
141
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_symbol: false)).to eql('EUR 30.175,93')
142
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_symbol: false)).to eql('AUD 30,175.93')
143
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_symbol: false)).to eql('AMD 30,175.93')
144
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_symbol: false)).to eql('AFN 30,175.93')
145
+ end
146
+
147
+ it 'omits ISO code and symbol when both with_currency and with_symbol are false' do
148
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, with_symbol: false)).to eql('30.175,93')
149
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false, with_symbol: false)).to eql('30,175.93')
150
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false, with_symbol: false)).to eql('30,175.93')
151
+ expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false, with_symbol: false)).to eql('30,175.93')
152
+ end
153
+
154
+ it 'returns an empty string if amount passed in is whitespace, empty string, or nil' do
155
+ expect(MoneyHelper.money_to_text(' ')).to eql('')
156
+ expect(MoneyHelper.money_to_text('')).to eql('')
157
+ expect(MoneyHelper.money_to_text(nil)).to eql('')
158
+ end
159
+
160
+ it "raises an exception when currency can't be found" do
161
+ expect do
162
+ MoneyHelper.money_to_text(30_175_93, currency: 'AAA')
163
+ end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'aaa'")
149
164
  end
150
165
  end
166
+
151
167
  describe 'symbol_with_optional_iso_code' do
152
168
  it 'just includes the symbol for USD GBP EUR and MYR' do
153
169
  expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
@@ -155,51 +171,64 @@ describe MoneyHelper do
155
171
  expect(MoneyHelper.symbol_with_optional_iso_code('MYR')).to eql('RM')
156
172
  expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
157
173
  end
174
+
158
175
  it 'includes the iso code as well for other currencies' do
159
176
  expect(MoneyHelper.symbol_with_optional_iso_code('AUD')).to eql('AUD $')
160
177
  expect(MoneyHelper.symbol_with_optional_iso_code('UZS')).to eql('UZS')
161
178
  expect(MoneyHelper.symbol_with_optional_iso_code('JPY')).to eql('JPY ¥')
162
179
  end
163
180
  end
181
+
164
182
  describe 'money_range_to_text' do
165
183
  it 'includes no indicator for currency for the upper amount in range' do
166
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'USD')).to eql('$30,000 - 40,000')
167
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AUD')).to eql('AUD $30,000 - 40,000')
168
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AMD')).to eql('AMD դր.30,000 - 40,000')
169
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AFN')).to eql('AFN 30,000 - 40,000')
184
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD')).to eql('USD $30,175.93 - 40,983.27')
185
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD')).to eql('AUD $30,175.93 - 40,983.27')
186
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD')).to eql('AMD դր.30,175.93 - 40,983.27')
187
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AFN')).to eql('AFN ؋30,175.93 - 40,983.27')
170
188
  end
189
+
171
190
  it 'uses the special range amount delimeter when supplied' do
172
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'USD', '-')).to eql('$30,000-40,000')
173
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AUD', '-')).to eql('AUD $30,000-40,000')
174
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AMD', '-')).to eql('AMD դր.30,000-40,000')
175
- expect(MoneyHelper.money_range_to_text(30_000, 40_000, 'AFN', '-')).to eql('AFN 30,000-40,000')
191
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD', delimiter: '-')).to eql('USD $30,175.93-40,983.27')
192
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD', delimiter: '-')).to eql('AUD $30,175.93-40,983.27')
193
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD', delimiter: '-')).to eql('AMD դր.30,175.93-40,983.27')
194
+ expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AFN', delimiter: '-')).to eql('AFN ؋30,175.93-40,983.27')
176
195
  end
196
+
177
197
  it "prefixes the text 'Under ' when low amount not given" do
178
- expect(MoneyHelper.money_range_to_text(nil, 40_000, 'USD')).to eql('Under $40,000')
198
+ expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD')).to eql('Under USD $40,983.27')
179
199
  end
200
+
180
201
  it "appends the text ' and up' when high amount not given" do
181
- expect(MoneyHelper.money_range_to_text(30_000, nil, 'USD')).to eql('$30,000 and up')
202
+ expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD')).to eql('USD $30,175.93 and up')
182
203
  end
204
+
183
205
  it 'treats as a single price when low amount and high amount are identical' do
184
- expect(MoneyHelper.money_range_to_text(30_000, 30_000, 'USD')).to eql('$30,000')
206
+ expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD')).to eql('USD $30,175.93')
185
207
  end
186
- it 'returns nil when both amounts are nil' do
187
- expect(MoneyHelper.money_range_to_text(nil, nil, 'USD')).to be_nil
208
+
209
+ it 'returns empty string when both amounts are nil' do
210
+ expect(MoneyHelper.money_range_to_text(nil, nil, currency: 'USD')).to eql('')
188
211
  end
189
- it "falls back to ISO code when currency can't be found" do
190
- expect(MoneyHelper.money_range_to_text(10_000, 20_000, 'ITL')).to eql('ITL 10,000 - 20,000')
212
+
213
+ it "raises an exception when currency can't be found" do
214
+ expect do
215
+ MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
216
+ end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'itl'")
191
217
  end
192
218
  end
219
+
193
220
  describe 'symbol_with_optional_iso_code' do
194
221
  it 'returns the symbol only if currency is in SYMBOL_ONLY list' do
195
222
  expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
196
223
  expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
197
224
  end
225
+
198
226
  it 'returns iso code and symbol if symbol is in OK_SYMBOLS' do
199
227
  expect(MoneyHelper.symbol_with_optional_iso_code('INR')).to eql('INR ₹')
200
228
  expect(MoneyHelper.symbol_with_optional_iso_code('KHR')).to eql('KHR ៛')
201
229
  expect(MoneyHelper.symbol_with_optional_iso_code('KPW')).to eql('KPW ₩')
202
230
  end
231
+
203
232
  it 'returns only the iso code if symbol is not in OK_SYMBOLS' do
204
233
  expect(MoneyHelper.symbol_with_optional_iso_code('CHF')).to eql('CHF')
205
234
  expect(MoneyHelper.symbol_with_optional_iso_code('YER')).to eql('YER')
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sahil Yakhmi
8
8
  - Joey Aghion
9
9
  - Matt Zikherman
10
10
  - Sarah Weir
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-04-19 00:00:00.000000000 Z
14
+ date: 2021-09-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -31,16 +31,16 @@ dependencies:
31
31
  name: money
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "~>"
34
+ - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: '6.5'
36
+ version: 6.16.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
41
+ - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: '6.5'
43
+ version: 6.16.0
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: appraisal
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -76,10 +76,10 @@ executables: []
76
76
  extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
+ - ".circleci/config.yml"
79
80
  - ".gitignore"
80
81
  - ".rubocop.yml"
81
82
  - ".rubocop_todo.yml"
82
- - ".travis.yml"
83
83
  - Appraisals
84
84
  - CHANGELOG.md
85
85
  - Gemfile
@@ -104,7 +104,7 @@ homepage: https://github.com/artsy/money_helper
104
104
  licenses:
105
105
  - MIT
106
106
  metadata: {}
107
- post_install_message:
107
+ post_install_message:
108
108
  rdoc_options: []
109
109
  require_paths:
110
110
  - lib
@@ -119,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: 1.3.6
121
121
  requirements: []
122
- rubygems_version: 3.0.3
123
- signing_key:
122
+ rubygems_version: 3.1.4
123
+ signing_key:
124
124
  specification_version: 4
125
125
  summary: MoneyHelper international price formatting utility.
126
126
  test_files:
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- language: ruby
2
-
3
- cache: bundler
4
-
5
- sudo: false
6
-
7
- rvm:
8
- - 2.3.4
9
- - 2.4.1
10
- - 2.5
11
- - ruby-head
12
-
13
- matrix:
14
- allow_failures:
15
- - rvm: ruby-head
16
- include:
17
- - rvm: 2.5
18
- gemfile: gemfiles/activesupport_40.gemfile
19
- - rvm: 2.5
20
- gemfile: gemfiles/activesupport_41.gemfile
21
- - rvm: 2.5
22
- gemfile: gemfiles/activesupport_42.gemfile
23
- - rvm: 2.5
24
- gemfile: gemfiles/activesupport_50.gemfile
25
- - rvm: 2.5
26
- gemfile: gemfiles/activesupport_51.gemfile
27
- - rvm: 2.5
28
- gemfile: gemfiles/activesupport_52.gemfile
29
- - rvm: 2.5
30
- gemfile: gemfiles/activesupport_edge.gemfile