money 6.13.0 → 6.13.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +49 -2
- data/README.md +93 -3
- data/config/currency_backwards_compatible.json +31 -0
- data/config/currency_iso.json +18 -18
- data/lib/money/bank/variable_exchange.rb +14 -6
- data/lib/money/currency.rb +4 -4
- data/lib/money/currency/loader.rb +15 -13
- data/lib/money/locale_backend/currency.rb +11 -0
- data/lib/money/locale_backend/i18n.rb +2 -1
- data/lib/money/locale_backend/legacy.rb +2 -2
- data/lib/money/money.rb +100 -52
- data/lib/money/money/allocation.rb +8 -5
- data/lib/money/money/arithmetic.rb +20 -10
- data/lib/money/money/formatter.rb +3 -0
- data/lib/money/money/formatting_rules.rb +15 -5
- data/lib/money/money/locale_backend.rb +3 -1
- data/lib/money/rates_store/memory.rb +24 -23
- data/lib/money/version.rb +1 -1
- data/money.gemspec +4 -4
- metadata +11 -51
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -32
- data/AUTHORS +0 -131
- data/CONTRIBUTING.md +0 -17
- data/Gemfile +0 -16
- data/Rakefile +0 -17
- data/spec/bank/base_spec.rb +0 -79
- data/spec/bank/single_currency_spec.rb +0 -13
- data/spec/bank/variable_exchange_spec.rb +0 -265
- data/spec/currency/heuristics_spec.rb +0 -11
- data/spec/currency/loader_spec.rb +0 -19
- data/spec/currency_spec.rb +0 -400
- data/spec/locale_backend/i18n_spec.rb +0 -62
- data/spec/locale_backend/legacy_spec.rb +0 -74
- data/spec/money/allocation_spec.rb +0 -130
- data/spec/money/arithmetic_spec.rb +0 -756
- data/spec/money/constructors_spec.rb +0 -91
- data/spec/money/formatting_spec.rb +0 -855
- data/spec/money/locale_backend_spec.rb +0 -14
- data/spec/money_spec.rb +0 -880
- data/spec/rates_store/memory_spec.rb +0 -80
- data/spec/spec_helper.rb +0 -30
- data/spec/support/shared_examples/money_examples.rb +0 -14
@@ -1,80 +0,0 @@
|
|
1
|
-
describe Money::RatesStore::Memory do
|
2
|
-
let(:subject) { described_class.new }
|
3
|
-
|
4
|
-
describe '#add_rate and #get_rate' do
|
5
|
-
it 'stores rate in memory' do
|
6
|
-
expect(subject.add_rate('USD', 'CAD', 0.9)).to eql 0.9
|
7
|
-
expect(subject.get_rate('USD', 'CAD')).to eql 0.9
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'add_rate' do
|
12
|
-
it "uses a mutex by default" do
|
13
|
-
expect(subject.instance_variable_get(:@mutex)).to receive(:synchronize)
|
14
|
-
subject.add_rate('USD', 'EUR', 1.25)
|
15
|
-
end
|
16
|
-
|
17
|
-
context ':without_mutex' do
|
18
|
-
let(:subject) { Money::RatesStore::Memory.new(without_mutex: true) }
|
19
|
-
|
20
|
-
it "doesn't use mutex if requested not to" do
|
21
|
-
expect(subject.instance_variable_get(:@mutex)).not_to receive(:synchronize)
|
22
|
-
subject.add_rate('USD', 'EUR', 1.25)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#each_rate' do
|
28
|
-
before do
|
29
|
-
subject.add_rate('USD', 'CAD', 0.9)
|
30
|
-
subject.add_rate('CAD', 'USD', 1.1)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'iterates over rates' do
|
34
|
-
expect{|b| subject.each_rate(&b)}.to yield_successive_args(['USD', 'CAD', 0.9], ['CAD', 'USD', 1.1])
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'is an Enumeator' do
|
38
|
-
expect(subject.each_rate).to be_kind_of(Enumerator)
|
39
|
-
result = subject.each_rate.each_with_object({}){|(from, to, rate),m| m[[from,to].join] = rate}
|
40
|
-
expect(result).to match({'USDCAD' => 0.9, 'CADUSD' => 1.1})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#transaction' do
|
45
|
-
context 'mutex' do
|
46
|
-
it 'uses mutex' do
|
47
|
-
expect(subject.instance_variable_get('@mutex')).to receive(:synchronize)
|
48
|
-
subject.transaction{ 1 + 1 }
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'wraps block in mutex transaction only once' do
|
52
|
-
expect{
|
53
|
-
subject.transaction do
|
54
|
-
subject.add_rate('USD', 'CAD', 1)
|
55
|
-
end
|
56
|
-
}.not_to raise_error
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'no mutex' do
|
61
|
-
let(:subject) { Money::RatesStore::Memory.new(without_mutex: true) }
|
62
|
-
|
63
|
-
it 'does not use mutex' do
|
64
|
-
expect(subject.instance_variable_get('@mutex')).not_to receive(:synchronize)
|
65
|
-
subject.transaction{ 1 + 1 }
|
66
|
-
end
|
67
|
-
end
|
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
|
80
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "coveralls"
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
5
|
-
require "rspec"
|
6
|
-
require "money"
|
7
|
-
|
8
|
-
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
9
|
-
|
10
|
-
I18n.enforce_available_locales = false
|
11
|
-
|
12
|
-
RSpec.configure do |c|
|
13
|
-
c.order = :random
|
14
|
-
c.filter_run :focus
|
15
|
-
c.run_all_when_everything_filtered = true
|
16
|
-
end
|
17
|
-
|
18
|
-
def reset_i18n
|
19
|
-
I18n.backend = I18n::Backend::Simple.new
|
20
|
-
end
|
21
|
-
|
22
|
-
RSpec.shared_context "with infinite precision", :infinite_precision do
|
23
|
-
before do
|
24
|
-
Money.infinite_precision = true
|
25
|
-
end
|
26
|
-
|
27
|
-
after do
|
28
|
-
Money.infinite_precision = false
|
29
|
-
end
|
30
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
RSpec.shared_examples 'instance with custom bank' do |operation, value|
|
2
|
-
let(:custom_bank) { Money::Bank::VariableExchange.new }
|
3
|
-
let(:instance) { Money.new(1, :usd, custom_bank) }
|
4
|
-
|
5
|
-
subject { value ? instance.send(operation, value) : instance.send(operation) }
|
6
|
-
|
7
|
-
it "returns custom bank from new instance" do
|
8
|
-
new_money_instances = Array(subject).select { |el| el.is_a?(Money) }
|
9
|
-
|
10
|
-
new_money_instances.each do |money_instance|
|
11
|
-
expect(money_instance.bank).to eq(custom_bank)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|