danconia 0.2.7 → 0.2.8

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
  SHA256:
3
- metadata.gz: baded88d58c693935472d8cc00e274384505ffd9859bca99c1accf4780f7cdf3
4
- data.tar.gz: 50150e40b421805ff2f383250bb77f741932f66b4f324c9bb935388628521c77
3
+ metadata.gz: fc840f5913a010c41495c7fd843304d67565217acf7eb7c248be9bf4c17624f8
4
+ data.tar.gz: d8906df663f918a41d91525b6ac51de9f8ac6decef179c813fc30145be876c50
5
5
  SHA512:
6
- metadata.gz: 5c936191102548a99cc30fddd737e95df0e9319adcfe6fbd12cd1d2a6b6b0228566c0f000da74125fbefa47ce63fe13e61417fce00ac69b3da531c71f7de9bb8
7
- data.tar.gz: '09dffba5565f6c5207a396b943fd23bebe30eec94122ea4c86ade7ebeeebaa12294aa9378eb7cf2c7f7ab99ced0fcc424f81349f1d0c840b44e2cd2038be7733'
6
+ metadata.gz: dc66bbeaf202e6b288f79d4a6fb9b93cc66585771f9543c14a14980252f5a112eb4e6a2cad21d15e4132bda2400f74cdb5567eb9a47a4f7ac7b6161105c2ae9c
7
+ data.tar.gz: 222d602fb10b842955d921ede2c7bae8bba4fd56dcdb1bcbcc74c12f795959c58250141f05943b607f0de80cdb3a07dc7425219e38f534c375236a0029d29ce2
@@ -1 +1,5 @@
1
+ ---
2
+ sudo: false
1
3
  language: ruby
4
+ cache: bundler
5
+ before_install: gem install bundler -v 1.16.1
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danconia (0.2.7)
4
+ danconia (0.2.8)
5
5
  activerecord (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.0)
11
- activesupport (= 6.0.0)
12
- activerecord (6.0.0)
13
- activemodel (= 6.0.0)
14
- activesupport (= 6.0.0)
15
- activesupport (6.0.0)
10
+ activemodel (6.0.3.1)
11
+ activesupport (= 6.0.3.1)
12
+ activerecord (6.0.3.1)
13
+ activemodel (= 6.0.3.1)
14
+ activesupport (= 6.0.3.1)
15
+ activesupport (6.0.3.1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
- zeitwerk (~> 2.1, >= 2.1.8)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
21
  addressable (2.5.2)
22
22
  public_suffix (>= 2.0.2, < 4.0)
23
23
  coderay (1.1.2)
24
- concurrent-ruby (1.1.5)
24
+ concurrent-ruby (1.1.6)
25
25
  crack (0.4.3)
26
26
  safe_yaml (~> 1.0.0)
27
27
  diff-lcs (1.3)
@@ -42,7 +42,7 @@ GEM
42
42
  guard-compat (~> 1.1)
43
43
  rspec (>= 2.99.0, < 4.0)
44
44
  hashdiff (0.3.7)
45
- i18n (1.7.0)
45
+ i18n (1.8.3)
46
46
  concurrent-ruby (~> 1.0)
47
47
  listen (3.1.5)
48
48
  rb-fsevent (~> 0.9, >= 0.9.4)
@@ -50,7 +50,7 @@ GEM
50
50
  ruby_dep (~> 1.2)
51
51
  lumberjack (1.0.13)
52
52
  method_source (0.9.0)
53
- minitest (5.13.0)
53
+ minitest (5.14.1)
54
54
  nenv (0.3.0)
55
55
  notiffany (0.1.1)
56
56
  nenv (~> 0.1)
@@ -59,7 +59,7 @@ GEM
59
59
  coderay (~> 1.1.0)
60
60
  method_source (~> 0.9.0)
61
61
  public_suffix (3.0.2)
62
- rake (10.3.2)
62
+ rake (13.0.1)
63
63
  rb-fsevent (0.10.3)
64
64
  rb-inotify (0.9.10)
65
65
  ffi (>= 0.5.0, < 2)
@@ -82,13 +82,13 @@ GEM
82
82
  sqlite3 (1.4.1)
83
83
  thor (0.20.0)
84
84
  thread_safe (0.3.6)
85
- tzinfo (1.2.5)
85
+ tzinfo (1.2.7)
86
86
  thread_safe (~> 0.1)
87
87
  webmock (3.4.2)
88
88
  addressable (>= 2.3.6)
89
89
  crack (>= 0.3.2)
90
90
  hashdiff
91
- zeitwerk (2.1.10)
91
+ zeitwerk (2.3.0)
92
92
 
93
93
  PLATFORMS
94
94
  ruby
@@ -103,4 +103,4 @@ DEPENDENCIES
103
103
  webmock
104
104
 
105
105
  BUNDLED WITH
106
- 1.16.1
106
+ 1.17.3
@@ -45,17 +45,17 @@ module Danconia
45
45
  amount <=> other
46
46
  end
47
47
 
48
- def exchange_to other_currency
48
+ def exchange_to other_currency, exchange: @exchange
49
49
  other_currency = other_currency.presence && Currency.find(other_currency, exchange) || currency
50
50
  rate = exchange.rate currency.code, other_currency.code
51
- clone_with amount * rate, other_currency
51
+ clone_with amount * rate, other_currency, exchange
52
52
  end
53
53
 
54
54
  %w(+ - * /).each do |op|
55
55
  class_eval <<-EOR, __FILE__, __LINE__ + 1
56
56
  def #{op} other
57
- other = other.exchange_to(currency).amount if other.is_a? Money
58
- clone_with amount #{op} other
57
+ other = other.exchange_to(currency, exchange: @exchange).amount if other.is_a? Money
58
+ clone_with(amount #{op} other)
59
59
  end
60
60
  EOR
61
61
  end
@@ -94,7 +94,7 @@ module Danconia
94
94
  BigDecimal(object.to_s) rescue BigDecimal(0)
95
95
  end
96
96
 
97
- def clone_with amount, currency = @currency
97
+ def clone_with amount, currency = @currency, exchange = @exchange
98
98
  Money.new amount, currency, decimals: decimals, exchange: exchange
99
99
  end
100
100
  end
@@ -1,3 +1,3 @@
1
1
  module Danconia
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -39,7 +39,7 @@ module Danconia
39
39
  end
40
40
 
41
41
  it 'should exchange the other currency if it is different' do
42
- expect(Money(1, 'ARS') + Money(1, 'USD', exchange: fake_exchange(rate: 4))).to eq Money(5, 'ARS')
42
+ expect(Money(1, 'ARS', exchange: fake_exchange(rate: 4)) + Money(1, 'USD')).to eq Money(5, 'ARS')
43
43
  end
44
44
 
45
45
  it 'should return a new object with the same options' do
@@ -121,17 +121,29 @@ module Danconia
121
121
  end
122
122
 
123
123
  context 'exchange_to' do
124
- it 'should use the exchange passed to the instance to get the rate' do
125
- expect(Money(2, 'USD', exchange: fake_exchange(rate: 3)).exchange_to('ARS')).to eq Money(6, 'ARS')
126
- end
127
-
128
- it 'should use the default exchange if not set' do
124
+ it 'should use a default exchange if not overriden' do
129
125
  TestHelpers.with_rates 'USDEUR' => 3, 'USDARS' => 4 do
130
126
  expect(Money(2, 'USD').exchange_to('EUR')).to eq Money(6, 'EUR')
131
127
  expect(Money(2, 'USD').exchange_to('ARS')).to eq Money(8, 'ARS')
132
128
  end
133
129
  end
134
130
 
131
+ it 'should allow to pass the exchange to the instance' do
132
+ expect(Money(2, 'USD', exchange: fake_exchange(rate: 3)).exchange_to('ARS')).to eq Money(6, 'ARS')
133
+ end
134
+
135
+ it 'should allow to pass the exchange when converting' do
136
+ expect(Money(2, 'USD').exchange_to('ARS', exchange: fake_exchange(rate: 4))).to eq Money(8, 'ARS')
137
+ end
138
+
139
+ it 'when overriding the exchange, should preserve it in the new instances' do
140
+ m1 = Money(1, 'USD').exchange_to('ARS', exchange: fake_exchange(rate: 2))
141
+ m2 = m1 + Money(3, 'USD')
142
+ m3 = m2 * Money(1, 'USD')
143
+ expect(m2).to eq Money(8, 'ARS')
144
+ expect(m3).to eq Money(16, 'ARS')
145
+ end
146
+
135
147
  it 'if no rate if found should raise error' do
136
148
  expect { Money(2, 'USD').exchange_to('ARS') }.to raise_error Errors::ExchangeRateNotFound
137
149
  end
@@ -178,7 +190,7 @@ module Danconia
178
190
  end
179
191
 
180
192
  def fake_exchange args = {}
181
- double 'exchange', args.reverse_merge(rate: nil)
193
+ double 'Danconia::Exchanges::Exchange', args.reverse_merge(rate: nil)
182
194
  end
183
195
  end
184
196
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danconia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Nicolau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord