money 6.6.1 → 6.7.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 +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -2
- data/AUTHORS +16 -13
- data/CHANGELOG.md +12 -3
- data/Gemfile +1 -1
- data/README.md +31 -13
- data/Rakefile +1 -0
- data/config/currency_iso.json +23 -7
- data/config/currency_non_iso.json +34 -1
- data/lib/money.rb +13 -0
- data/lib/money/bank/base.rb +1 -1
- data/lib/money/currency.rb +4 -4
- data/lib/money/currency/heuristics.rb +3 -2
- data/lib/money/money.rb +2 -2
- data/lib/money/money/arithmetic.rb +44 -19
- data/lib/money/money/formatting.rb +35 -26
- data/lib/money/version.rb +1 -1
- data/money.gemspec +2 -1
- data/spec/bank/base_spec.rb +0 -2
- data/spec/bank/single_currency_spec.rb +0 -2
- data/spec/bank/variable_exchange_spec.rb +0 -1
- data/spec/currency/heuristics_spec.rb +79 -1
- data/spec/currency/loader_spec.rb +0 -1
- data/spec/currency_spec.rb +7 -9
- data/spec/money/arithmetic_spec.rb +99 -46
- data/spec/money/constructors_spec.rb +0 -2
- data/spec/money/formatting_spec.rb +42 -2
- data/spec/money_spec.rb +3 -5
- data/spec/rates_store/memory_spec.rb +2 -4
- data/spec/spec_helper.rb +2 -7
- metadata +26 -5
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
3
|
describe Money, "formatting" do
|
6
4
|
|
7
5
|
BAR = '{ "priority": 1, "iso_code": "BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }'
|
@@ -569,6 +567,33 @@ describe Money, "formatting" do
|
|
569
567
|
expect(Money.new(BigDecimal.new('100012.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1.000,13"
|
570
568
|
end
|
571
569
|
end
|
570
|
+
|
571
|
+
describe "with i18n = true" do
|
572
|
+
before do
|
573
|
+
Money.use_i18n = true
|
574
|
+
reset_i18n
|
575
|
+
I18n.locale = :de
|
576
|
+
I18n.backend.store_translations(
|
577
|
+
:de,
|
578
|
+
:number => { :currency => { :format => { :delimiter => ".", :separator => "," } } }
|
579
|
+
)
|
580
|
+
end
|
581
|
+
|
582
|
+
after do
|
583
|
+
reset_i18n
|
584
|
+
I18n.locale = :en
|
585
|
+
end
|
586
|
+
|
587
|
+
it 'does round fractional when set to true' do
|
588
|
+
expect(Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$0,12"
|
589
|
+
expect(Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$0,13"
|
590
|
+
expect(Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0,123"
|
591
|
+
expect(Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0,124"
|
592
|
+
expect(Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$1,00"
|
593
|
+
expect(Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$1,10"
|
594
|
+
expect(Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true)).to eq "Ar0,2"
|
595
|
+
end
|
596
|
+
end
|
572
597
|
end
|
573
598
|
|
574
599
|
context "when the monetary value is 0" do
|
@@ -670,5 +695,20 @@ describe Money, "formatting" do
|
|
670
695
|
end
|
671
696
|
end
|
672
697
|
|
698
|
+
describe ":drop_trailing_zeros option" do
|
699
|
+
specify "(:drop_trailing_zeros => true) works as documented" do
|
700
|
+
expect(Money.new(89000, "BTC").format(:drop_trailing_zeros => true, :symbol => false)).to eq "0.00089"
|
701
|
+
expect(Money.new(100089000, "BTC").format(:drop_trailing_zeros => true, :symbol => false)).to eq "1.00089"
|
702
|
+
expect(Money.new(100000000, "BTC").format(:drop_trailing_zeros => true, :symbol => false)).to eq "1"
|
703
|
+
expect(Money.new(110, "AUD").format(:drop_trailing_zeros => true, :symbol => false)).to eq "1.1"
|
704
|
+
end
|
705
|
+
|
706
|
+
specify "(:drop_trailing_zeros => false) works as documented" do
|
707
|
+
expect(Money.new(89000, "BTC").format(:drop_trailing_zeros => false, :symbol => false)).to eq "0.00089000"
|
708
|
+
expect(Money.new(100089000, "BTC").format(:drop_trailing_zeros => false, :symbol => false)).to eq "1.00089000"
|
709
|
+
expect(Money.new(100000000, "BTC").format(:drop_trailing_zeros => false, :symbol => false)).to eq "1.00000000"
|
710
|
+
expect(Money.new(110, "AUD").format(:drop_trailing_zeros => false, :symbol => false)).to eq "1.10"
|
711
|
+
end
|
712
|
+
end
|
673
713
|
end
|
674
714
|
end
|
data/spec/money_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
3
|
describe Money do
|
6
4
|
describe ".new" do
|
7
5
|
let(:initializing_value) { 1 }
|
@@ -374,7 +372,7 @@ YAML
|
|
374
372
|
expect(Money.new(1, "CLP").amount).to eq 1
|
375
373
|
end
|
376
374
|
|
377
|
-
it "does not
|
375
|
+
it "does not lose precision" do
|
378
376
|
expect(Money.new(100_37).amount).to eq 100.37
|
379
377
|
end
|
380
378
|
|
@@ -573,13 +571,13 @@ YAML
|
|
573
571
|
expect(Money.ca_dollar(005).allocate([1])).to eq [Money.ca_dollar(5)]
|
574
572
|
end
|
575
573
|
|
576
|
-
it "does not
|
574
|
+
it "does not lose pennies" do
|
577
575
|
moneys = Money.us_dollar(5).allocate([0.3, 0.7])
|
578
576
|
expect(moneys[0]).to eq Money.us_dollar(2)
|
579
577
|
expect(moneys[1]).to eq Money.us_dollar(3)
|
580
578
|
end
|
581
579
|
|
582
|
-
it "does not
|
580
|
+
it "does not lose pennies" do
|
583
581
|
moneys = Money.us_dollar(100).allocate([0.333, 0.333, 0.333])
|
584
582
|
expect(moneys[0].cents).to eq 34
|
585
583
|
expect(moneys[1].cents).to eq 33
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Money::RatesStore::Memory do
|
4
2
|
let(:subject) { described_class.new }
|
5
3
|
|
@@ -47,7 +45,7 @@ describe Money::RatesStore::Memory do
|
|
47
45
|
context 'mutex' do
|
48
46
|
it 'uses mutex' do
|
49
47
|
expect(subject.instance_variable_get('@mutex')).to receive(:synchronize)
|
50
|
-
subject.transaction{
|
48
|
+
subject.transaction{ 1 + 1 }
|
51
49
|
end
|
52
50
|
|
53
51
|
it 'wraps block in mutex transaction only once' do
|
@@ -64,7 +62,7 @@ describe Money::RatesStore::Memory do
|
|
64
62
|
|
65
63
|
it 'does not use mutex' do
|
66
64
|
expect(subject.instance_variable_get('@mutex')).not_to receive(:synchronize)
|
67
|
-
subject.transaction{
|
65
|
+
subject.transaction{ 1 + 1 }
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,8 @@ I18n.enforce_available_locales = false
|
|
9
9
|
|
10
10
|
RSpec.configure do |c|
|
11
11
|
c.order = :random
|
12
|
-
|
13
|
-
|
14
|
-
def silence_warnings
|
15
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
16
|
-
yield
|
17
|
-
ensure
|
18
|
-
$VERBOSE = old_verbose
|
12
|
+
c.filter_run :focus
|
13
|
+
c.run_all_when_everything_filtered = true
|
19
14
|
end
|
20
15
|
|
21
16
|
def reset_i18n
|
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.
|
4
|
+
version: 6.7.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:
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sixarm_ruby_unaccent
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.1.1
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.1.1
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: bundler
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,14 +84,14 @@ dependencies:
|
|
64
84
|
requirements:
|
65
85
|
- - "~>"
|
66
86
|
- !ruby/object:Gem::Version
|
67
|
-
version: 3.
|
87
|
+
version: 3.4.0
|
68
88
|
type: :development
|
69
89
|
prerelease: false
|
70
90
|
version_requirements: !ruby/object:Gem::Requirement
|
71
91
|
requirements:
|
72
92
|
- - "~>"
|
73
93
|
- !ruby/object:Gem::Version
|
74
|
-
version: 3.
|
94
|
+
version: 3.4.0
|
75
95
|
- !ruby/object:Gem::Dependency
|
76
96
|
name: yard
|
77
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +129,7 @@ extra_rdoc_files: []
|
|
109
129
|
files:
|
110
130
|
- ".coveralls.yml"
|
111
131
|
- ".gitignore"
|
132
|
+
- ".rspec"
|
112
133
|
- ".travis.yml"
|
113
134
|
- AUTHORS
|
114
135
|
- CHANGELOG.md
|
@@ -174,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
195
|
version: '0'
|
175
196
|
requirements: []
|
176
197
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.4.5
|
198
|
+
rubygems_version: 2.4.5.1
|
178
199
|
signing_key:
|
179
200
|
specification_version: 4
|
180
201
|
summary: A Ruby Library for dealing with money and currency conversion.
|