currency_coin_converter 0.3.2 → 0.3.3
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/CHANGELOG.md +1 -1
- data/lib/currency_coin_converter.rb +5 -5
- data/spec/currency_coin_converter_spec.rb +13 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e1acd506bad9c54078c6e93298eb1687f3c98384c40587c0982845e466564cf
|
4
|
+
data.tar.gz: 489940cb45f403da132769bb84dcdfc8785633c2f7d18db556332abbda8f2562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aedaef1ae1b57836423c9e481153cc0514ae39bcafd303302e6cc46b15248574e95f1bd36f335f0c3dc413159ca710c51103817ea2c039c9f2208e256682f1a
|
7
|
+
data.tar.gz: 65d932e61bbf521b30730cc62ad65be1426eba333d2d5f13edfa15696e9612a76e78993d23a3d3d4474a1aff8f43d381808fb12bbe6b81d621a08a80b86a5cad
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ require 'singleton'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module CurrencyCoinConverter
|
7
|
-
VERSION = "0.3.
|
7
|
+
VERSION = "0.3.3"
|
8
8
|
|
9
9
|
class Error < StandardError; end
|
10
10
|
|
@@ -16,12 +16,12 @@ module CurrencyCoinConverter
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def convert(amount, from:, to:, round: 2)
|
19
|
-
(amount * conversion_rate(from
|
19
|
+
(amount * conversion_rate(from: from, to: to)).round(round)
|
20
20
|
end
|
21
21
|
|
22
22
|
def conversion_rate(from:, to:)
|
23
23
|
conversion_rate = conversion_rates(from)[to]
|
24
|
-
return conversion_rate
|
24
|
+
return conversion_rate if conversion_rate
|
25
25
|
|
26
26
|
raise Error, "currency code is invalid: #{to}"
|
27
27
|
end
|
@@ -64,11 +64,11 @@ module CurrencyCoinConverter
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def convert(amount, from:, to:, round: 2)
|
67
|
-
instance.convert(amount, from
|
67
|
+
instance.convert(amount, from: from, to: to, round: round)
|
68
68
|
end
|
69
69
|
|
70
70
|
def conversion_rate(from:, to:)
|
71
|
-
instance.conversion_rate(from
|
71
|
+
instance.conversion_rate(from: from, to: to)
|
72
72
|
end
|
73
73
|
|
74
74
|
def conversion_rates(base_currency)
|
@@ -2,7 +2,14 @@ require 'currency_coin_converter'
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.before(:example, :mock_get => true) do
|
7
|
+
allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
RSpec.describe CurrencyCoinConverter::Base do
|
12
|
+
let(:response) { JSON.parse(File.read("spec/examples/inr.json")) }
|
6
13
|
before do
|
7
14
|
described_class.api_key = "fake_key"
|
8
15
|
end
|
@@ -15,24 +22,21 @@ RSpec.describe CurrencyCoinConverter::Base do
|
|
15
22
|
expect(described_class.api_version).to eq("v6")
|
16
23
|
end
|
17
24
|
|
18
|
-
it '#conversion_rates returns the conversion rate for a valid currency code' do
|
19
|
-
|
20
|
-
allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
25
|
+
it '#conversion_rates returns the conversion rate for a valid currency code', :mock_get => true do
|
26
|
+
# allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
21
27
|
|
22
28
|
expect(described_class.conversion_rates("INR")).to eq(response["conversion_rates"])
|
23
29
|
end
|
24
30
|
|
25
|
-
it '#conversion_rate returns the conversion rate for valid currency codes' do
|
26
|
-
|
27
|
-
allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
31
|
+
it '#conversion_rate returns the conversion rate for valid currency codes', :mock_get => true do
|
32
|
+
# allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
28
33
|
|
29
34
|
expect(described_class.conversion_rate(from: "INR", to: "USD")).to eq(response["conversion_rates"]["USD"])
|
30
35
|
expect { described_class.conversion_rate(from: "INR", to: "US") }.to raise_error CurrencyCoinConverter::Error, "currency code is invalid: US"
|
31
36
|
end
|
32
37
|
|
33
|
-
it '#convert returns the converted amount from one currency code to another' do
|
34
|
-
|
35
|
-
allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
38
|
+
it '#convert returns the converted amount from one currency code to another', :mock_get => true do
|
39
|
+
# allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
|
36
40
|
|
37
41
|
expect(described_class.convert(130, from: "INR", to: "USD")).to eq(1.55)
|
38
42
|
expect(described_class.convert(130, from: "INR", to: "USD", round: 1)).to eq(1.5)
|