money 6.9.0 → 6.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f268faeee9a1901f8a4e482e8497370697eb436a
4
- data.tar.gz: 54f37ca793f33929f7c1dd10de33d58c813495fe
3
+ metadata.gz: 19c937d927f70901c2a2deda19899ec893b567b1
4
+ data.tar.gz: 213e8242c26aadfb1030453815547765ea030022
5
5
  SHA512:
6
- metadata.gz: b9d33bfe048a6ba6fe92391ac9223a92268f31bd6c1f0ef932f2d202fd3a45e7df013c5c96d5ac99b98aacde1ece7a905fda77949aa9e4ad7625698b16b5914f
7
- data.tar.gz: b3b255302aec3569a1b7e1b4dc5a7e1a77b1b4129c09eb65f295461eadc48cc342f09de81236a229a6d4139a5038069108fdc53660d09255c9d3fa1130d22a02
6
+ metadata.gz: 0bb443e04dccacd832fd53fad627eb4076b895a79da97adb29c32407689ddb53a95e3dc4e36ab8e9e5b5f764a13a3a579ea887a53ee748e2c60dea05ef882596
7
+ data.tar.gz: dce49cc4288a72a187ca03d709abd9659d9dab3965ade09fe5f86c69034a09a5106f4da57da2d3201233f256c1353a2661d95b70f2deb19cede3a6d4ac022ec4
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- --require spec_helper
1
+ --require spec_helper
2
+ --color
@@ -4,9 +4,9 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.10
7
- - 2.2.5
8
- - 2.3.1
9
- - 2.4.0
7
+ - 2.2.7
8
+ - 2.3.4
9
+ - 2.4.1
10
10
  - rbx-2
11
11
  - jruby-9.0.5.0
12
12
  - jruby-9.1.2.0
@@ -18,6 +18,8 @@ matrix:
18
18
  - rvm: jruby-head
19
19
  - rvm: rbx-2
20
20
  fast_finish: true
21
+ before_install:
22
+ - gem update bundler
21
23
  script: bundle exec rspec spec
22
24
  notifications:
23
25
  email:
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.10.0
4
+ - Added support for i18n version 0.9
5
+ - Disabled rounding when verifying allocation splits
6
+ - Added Chinese Yuan Offshore (CNH)
7
+ - Fixed html_entity for ARS
8
+ - Fixed KZT symbol
9
+ - Allowed comparing cross currency when both are zero
10
+ - Fixed memory rate store
11
+ - Corrected HUF subunit and thousands separator config
12
+
3
13
  ## 6.9.0
4
14
  - Extracted heuristics into money-heuristics gem
5
15
 
data/README.md CHANGED
@@ -119,15 +119,15 @@ below.
119
119
 
120
120
  ``` ruby
121
121
  curr = {
122
- :priority => 1,
123
- :iso_code => "USD",
124
- :iso_numeric => "840",
125
- :name => "United States Dollar",
126
- :symbol => "$",
127
- :subunit => "Cent",
128
- :subunit_to_unit => 100,
129
- :separator => ".",
130
- :delimiter => ","
122
+ :priority => 1,
123
+ :iso_code => "USD",
124
+ :iso_numeric => "840",
125
+ :name => "United States Dollar",
126
+ :symbol => "$",
127
+ :subunit => "Cent",
128
+ :subunit_to_unit => 100,
129
+ :decimal_mark => ".",
130
+ :thousands_separator => ","
131
131
  }
132
132
 
133
133
  Money::Currency.register(curr)
@@ -142,8 +142,8 @@ The pre-defined set of attributes includes:
142
142
  - `:symbol` the currency symbol (UTF-8 encoded)
143
143
  - `:subunit` the name of the fractional monetary unit
144
144
  - `:subunit_to_unit` the proportion between the unit and the subunit
145
- - `:separator` character between the whole and fraction amounts
146
- - `:delimiter` character between each thousands place
145
+ - `:decimal_mark` character between the whole and fraction amounts
146
+ - `:thousands_separator` character between each thousands place
147
147
 
148
148
  All attributes except `:iso_code` are optional. Some attributes, such as
149
149
  `:symbol`, are used by the Money class to print out a representation of the
@@ -100,7 +100,7 @@
100
100
  "subunit": "Centavo",
101
101
  "subunit_to_unit": 100,
102
102
  "symbol_first": true,
103
- "html_entity": "₱",
103
+ "html_entity": "$",
104
104
  "decimal_mark": ",",
105
105
  "thousands_separator": ".",
106
106
  "iso_numeric": "032",
@@ -931,12 +931,12 @@
931
931
  "name": "Hungarian Forint",
932
932
  "symbol": "Ft",
933
933
  "alternate_symbols": [],
934
- "subunit": "Fillér",
934
+ "subunit": "",
935
935
  "subunit_to_unit": 1,
936
936
  "symbol_first": false,
937
937
  "html_entity": "",
938
938
  "decimal_mark": ",",
939
- "thousands_separator": ".",
939
+ "thousands_separator": " ",
940
940
  "iso_numeric": "348",
941
941
  "smallest_denomination": 5
942
942
  },
@@ -1202,7 +1202,7 @@
1202
1202
  "priority": 100,
1203
1203
  "iso_code": "KZT",
1204
1204
  "name": "Kazakhstani Tenge",
1205
- "symbol": "",
1205
+ "symbol": "",
1206
1206
  "alternate_symbols": [],
1207
1207
  "subunit": "Tiyn",
1208
1208
  "subunit_to_unit": 100,
@@ -2561,7 +2561,7 @@
2561
2561
  },
2562
2562
  "xts": {
2563
2563
  "priority": 100,
2564
- "iso_code": "xts",
2564
+ "iso_code": "XTS",
2565
2565
  "name": "Codes specifically reserved for testing purposes",
2566
2566
  "symbol": "",
2567
2567
  "alternate_symbols": [],
@@ -93,5 +93,21 @@
93
93
  "thousands_separator": ",",
94
94
  "iso_numeric": "",
95
95
  "smallest_denomination": 1
96
+ },
97
+ "cnh": {
98
+ "priority": 100,
99
+ "iso_code": "CNH",
100
+ "name": "Chinese Renminbi Yuan Offshore",
101
+ "symbol": "¥",
102
+ "disambiguate_symbol": "CNH",
103
+ "alternate_symbols": ["CN¥", "元", "CN元"],
104
+ "subunit": "Fen",
105
+ "subunit_to_unit": 100,
106
+ "symbol_first": true,
107
+ "html_entity": "¥",
108
+ "decimal_mark": ".",
109
+ "thousands_separator": ",",
110
+ "iso_numeric": "",
111
+ "smallest_denomination": 1
96
112
  }
97
113
  }
@@ -584,7 +584,7 @@ class Money
584
584
  end
585
585
 
586
586
  def allocations_from_splits(splits)
587
- splits.inject(0) { |sum, n| sum + as_d(n) }
587
+ splits.inject(0) { |sum, n| sum + n }
588
588
  end
589
589
 
590
590
  def amounts_from_splits(allocations, splits)
@@ -57,6 +57,7 @@ class Money
57
57
  return unless other.respond_to?(:zero?) && other.zero?
58
58
  return other.is_a?(CoercedNumeric) ? 0 <=> fractional : fractional <=> 0
59
59
  end
60
+ return 0 if zero? && other.zero?
60
61
  other = other.exchange_to(currency)
61
62
  fractional <=> other.fractional
62
63
  rescue Money::Bank::UnknownRate
@@ -58,10 +58,9 @@ class Money
58
58
  end
59
59
 
60
60
  def marshal_dump
61
- [self.class, index, options]
61
+ [self.class, options, index]
62
62
  end
63
63
 
64
-
65
64
  # Wraps block execution in a thread-safe transaction
66
65
  def transaction(&block)
67
66
  if @in_transaction || options[:without_mutex]
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = "6.9.0"
2
+ VERSION = '6.10.0'
3
3
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.description = "A Ruby Library for dealing with money and currency conversion."
15
15
  s.license = "MIT"
16
16
 
17
- s.add_dependency 'i18n', ['>= 0.6.4', '< 0.9']
17
+ s.add_dependency 'i18n', [">= 0.6.4", '< 1.0']
18
18
 
19
19
  s.add_development_dependency "bundler", "~> 1.3"
20
20
  s.add_development_dependency "rake"
@@ -23,7 +23,6 @@ describe Money do
23
23
  end
24
24
 
25
25
  it "returns true if both amounts are zero, even if currency differs" do
26
- allow_any_instance_of(Money).to receive(:exchange_to) { Money.usd(0) }
27
26
  expect(Money.new(0, "USD")).to eq Money.new(0, "USD")
28
27
  expect(Money.new(0, "USD")).to eq Money.new(0, "EUR")
29
28
  expect(Money.new(0, "USD")).to eq Money.new(0, "AUD")
@@ -69,6 +68,12 @@ describe Money do
69
68
  expect(Money.new(1_00, "USD").eql?(Money.new(99_00, "EUR"))).to be false
70
69
  end
71
70
 
71
+ it "returns true when their amounts are zero and currencies differ" do
72
+ expect(Money.new(0, "USD").eql?(Money.new(0, "EUR"))).to be true
73
+ expect(Money.new(0, "USD").eql?(Money.new(0, "USD"))).to be true
74
+ expect(Money.new(0, "AUD").eql?(Money.new(0, "EUR"))).to be true
75
+ end
76
+
72
77
  it "returns false if used to compare with an object that doesn't inherit from Money" do
73
78
  expect(Money.new(1_00, "USD").eql?(Object.new)).to be false
74
79
  expect(Money.new(1_00, "USD").eql?(Class)).to be false
@@ -130,6 +135,32 @@ describe Money do
130
135
  expect(Money.new(1_00) <=> /foo/).to be_nil
131
136
  end
132
137
 
138
+ context 'when conversions disallowed' do
139
+ around do |example|
140
+ begin
141
+ old_default_bank = Money.default_bank
142
+ Money.disallow_currency_conversion!
143
+ example.run
144
+ ensure
145
+ Money.default_bank = old_default_bank
146
+ end
147
+ end
148
+
149
+ context 'when currencies differ' do
150
+ context 'when both values are 1_00' do
151
+ it 'raises currency error' do
152
+ expect { Money.usd(1_00) <=> Money.gbp(1_00) }.to raise_error Money::Bank::DifferentCurrencyError
153
+ end
154
+ end
155
+
156
+ context 'when both values are 0' do
157
+ it 'considers them equal' do
158
+ expect(Money.usd(0) <=> Money.gbp(0)).to eq(0)
159
+ end
160
+ end
161
+ end
162
+ end
163
+
133
164
  it 'compares with numeric 0' do
134
165
  expect(Money.usd(1) < 0).to eq false
135
166
  expect(Money.usd(1) > 0.0).to eq true
@@ -661,7 +692,7 @@ describe Money do
661
692
  end
662
693
  end
663
694
 
664
- %w(+ - / <=> divmod remainder).each do |op|
695
+ %w(+ - / divmod remainder).each do |op|
665
696
  describe "##{op}" do
666
697
  subject { ->(other = self.other) { instance.send(op, other) } }
667
698
  let(:instance) { Money.usd(1) }
@@ -598,6 +598,22 @@ YAML
598
598
  expect(moneys[2].cents).to eq 33
599
599
  end
600
600
 
601
+ it "does not round rationals" do
602
+ splits = 7.times.map { Rational(950, 6650) }
603
+ moneys = Money.us_dollar(6650).allocate(splits)
604
+ moneys.each do |money|
605
+ expect(money.cents).to eq 950
606
+ end
607
+ end
608
+
609
+ it "handles mixed split types" do
610
+ splits = [Rational(1, 4), 0.25, 0.25, BigDecimal.new('0.25')]
611
+ moneys = Money.us_dollar(100).allocate(splits)
612
+ moneys.each do |money|
613
+ expect(money.cents).to eq 25
614
+ end
615
+ end
616
+
601
617
  context "negative amount" do
602
618
  it "does not lose pennies" do
603
619
  moneys = Money.us_dollar(-100).allocate([0.333, 0.333, 0.333])
@@ -66,4 +66,15 @@ describe Money::RatesStore::Memory do
66
66
  end
67
67
  end
68
68
  end
69
+
70
+ describe '#marshal_dump' do
71
+ let(:subject) { Money::RatesStore::Memory.new(:optional => true) }
72
+
73
+ it 'can reload' do
74
+ bank = Money::Bank::VariableExchange.new(subject)
75
+ bank = Marshal.load(Marshal.dump(bank))
76
+ expect(bank.store.instance_variable_get(:@options)).to eq subject.instance_variable_get(:@options)
77
+ expect(bank.store.instance_variable_get(:@index)).to eq subject.instance_variable_get(:@index)
78
+ end
79
+ end
69
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.9.0
4
+ version: 6.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 0.6.4
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.9'
22
+ version: '1.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 0.6.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.9'
32
+ version: '1.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement