money 6.13.2 → 6.13.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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