money-open-exchange-rates 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 437aaa9ee1ba378244b8d8e2826df7b2c62030245cad2c0842c4985917d49c7f
4
- data.tar.gz: df74b76387cc6bbb7850e9b8aabf200c45aa4c15c3a0b76a0acc991eb6dd448b
3
+ metadata.gz: 2ccf18d87ab1263df713ece79feed894fa64b59112b5f64a51416c01f558f5e0
4
+ data.tar.gz: abde5b9fe07e938bd8121ce423acd9d4e3a744ce811a4b455580ff86f75f3329
5
5
  SHA512:
6
- metadata.gz: da4cc8071242bf6a520167453e12dfa8a07cedbf7b088cf39c8e0561515a3669049bc0eab0729657045d3fd4580f62722dcc57e962351fbf14c5a87584184112
7
- data.tar.gz: 286222c2ad6c009ae563bcafa813bec513614b96a77d09da457ee8e7d91022667daf50af34b3b3f517acbe0679aeb5be6a338955ad760d728b636d06ce572084
6
+ metadata.gz: 9c8fe6c2357a1fa560f327c9cbdf38293cdcf0e46db2aa08f9c65a289f24a668eae9cf4f3d4f47786d42dcf6cbc0e6fe46fb7d6f18f251245036be1939c0fcaf
7
+ data.tar.gz: 11085f010f58fbf3cc7e7c256a5532574ac29ae4dd388861d8f0090a21b35c7b26a6775b4398d3a0a1ea20020e80c1ff2d1dcb56218b0dd54822c682df4505ae
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'coveralls', require: false
data/History.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ v1.2.2 / 2018-03-31
3
+ ===================
4
+
5
+ * Warn secure_connection= is deprecated
6
+ * More simple code on calc_pair_rate_using_base
7
+ * Increase code coverage on source_url
8
+ * Fix parse error specs on refresh_rates
9
+ * Use Coveralls for coverage
10
+ * Add tests for rates_timestamp issue
11
+
2
12
  v1.2.1 / 2018-03-31
3
13
  ===================
4
14
 
data/README.md CHANGED
@@ -194,5 +194,5 @@ Copyright © 2011-2018 Laurent Arnoud <laurent@spkdev.net>
194
194
  [![Version](https://img.shields.io/gem/v/money-open-exchange-rates.svg)](https://rubygems.org/gems/money-open-exchange-rates)
195
195
  [![Documentation](https://img.shields.io/badge/doc-rubydoc-blue.svg)](http://www.rubydoc.info/gems/money-open-exchange-rates)
196
196
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT "MIT")
197
- [![Code Climate](https://img.shields.io/codeclimate/github/spk/money-open-exchange-rates.svg)](https://codeclimate.com/github/spk/money-open-exchange-rates)
197
+ [![Coverage Status](https://img.shields.io/coveralls/github/spk/money-open-exchange-rates.svg)](https://coveralls.io/github/spk/money-open-exchange-rates?branch=master)
198
198
  [![Inline docs](https://inch-ci.org/github/spk/money-open-exchange-rates.svg?branch=master)](http://inch-ci.org/github/spk/money-open-exchange-rates)
@@ -33,7 +33,8 @@ class Money
33
33
 
34
34
  # @deprecated secure_connection is deprecated and has no effect
35
35
  def secure_connection=(*)
36
- 'secure_connection is deprecated and has no effect'
36
+ warn 'secure_connection is deprecated and has no effect'
37
+ nil
37
38
  end
38
39
 
39
40
  # As of the end of August 2012 all requests to the Open Exchange Rates
@@ -292,12 +293,19 @@ class Money
292
293
  result if valid_rates?(result)
293
294
  end
294
295
 
296
+ # Read API
297
+ #
298
+ # @return [String]
299
+ def json_response
300
+ open(source_url).read
301
+ end
302
+
295
303
  # Read from url
296
304
  #
297
305
  # @return [String] JSON content
298
306
  def read_from_url
299
307
  raise NoAppId if app_id.nil? || app_id.empty?
300
- @json_response = open(source_url).read
308
+ @json_response = json_response
301
309
  save_cache if cache
302
310
  @json_response
303
311
  end
@@ -361,12 +369,11 @@ class Money
361
369
  def calc_pair_rate_using_base(from_currency, to_currency, opts)
362
370
  from_base_rate = get_rate_or_calc_inverse(source, from_currency, opts)
363
371
  to_base_rate = get_rate_or_calc_inverse(source, to_currency, opts)
364
- if to_base_rate && from_base_rate
365
- rate = BigDecimal(to_base_rate.to_s) / from_base_rate
366
- add_rate(from_currency, to_currency, rate)
367
- return rate
368
- end
369
- nil
372
+ return unless to_base_rate
373
+ return unless from_base_rate
374
+ rate = BigDecimal(to_base_rate.to_s) / from_base_rate
375
+ add_rate(from_currency, to_currency, rate)
376
+ rate
370
377
  end
371
378
  end
372
379
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Module for version constant
4
4
  module OpenExchangeRatesBank
5
- VERSION = '1.2.1'.freeze
5
+ VERSION = '1.2.2'.freeze
6
6
  end
@@ -7,6 +7,9 @@ describe Money::Bank::OpenExchangeRatesBank do
7
7
  let(:oer_historical_url) do
8
8
  Money::Bank::OpenExchangeRatesBank::OER_HISTORICAL_URL
9
9
  end
10
+ let(:default_source) do
11
+ Money::Bank::OpenExchangeRatesBank::OE_SOURCE
12
+ end
10
13
 
11
14
  let(:temp_cache_path) do
12
15
  data_file('tmp.json')
@@ -67,6 +70,12 @@ describe Money::Bank::OpenExchangeRatesBank do
67
70
  subject.exchange_with(money, 'TJS').must_equal Money.new(250, 'TJS')
68
71
  end
69
72
 
73
+ it "should raise if it can't find an currency" do
74
+ money = Money.new(0, 'USD')
75
+ proc { subject.exchange_with(money, 'PLP') }
76
+ .must_raise Money::Currency::UnknownCurrency
77
+ end
78
+
70
79
  it "should raise if it can't find an exchange rate" do
71
80
  money = Money.new(0, 'USD')
72
81
  proc { subject.exchange_with(money, 'SSP') }
@@ -134,10 +143,6 @@ describe Money::Bank::OpenExchangeRatesBank do
134
143
  it 'should raise an error if no App ID is set' do
135
144
  proc { subject.update_rates }.must_raise Money::Bank::NoAppId
136
145
  end
137
-
138
- # TODO: As App IDs are compulsory soon, need to add more tests handle
139
- # app_id-specific errors from
140
- # https://openexchangerates.org/documentation#errors
141
146
  end
142
147
 
143
148
  describe 'no cache' do
@@ -185,6 +190,15 @@ describe Money::Bank::OpenExchangeRatesBank do
185
190
  subject.source_url.must_include '/api/latest.json'
186
191
  end
187
192
  end
193
+
194
+ describe 'secure_connection=' do
195
+ it 'do nothing' do
196
+ _out, err = capture_io do
197
+ subject.secure_connection = false
198
+ end
199
+ err.must_include 'deprecated'
200
+ end
201
+ end
188
202
  end
189
203
 
190
204
  describe 'no valid file for cache' do
@@ -226,8 +240,9 @@ describe Money::Bank::OpenExchangeRatesBank do
226
240
 
227
241
  describe '#refresh_rates' do
228
242
  before do
229
- add_to_webmock(subject)
243
+ subject.app_id = TEST_APP_ID
230
244
  subject.cache = temp_cache_path
245
+ stub(subject).json_response { File.read(oer_latest_path) }
231
246
  subject.update_rates
232
247
  end
233
248
 
@@ -245,21 +260,21 @@ describe Money::Bank::OpenExchangeRatesBank do
245
260
 
246
261
  it 'should not break an existing file if save fails to read' do
247
262
  initial_size = File.read(temp_cache_path).size
248
- stub(subject).read_from_url { '' }
263
+ stub(subject).json_response { '' }
249
264
  subject.refresh_rates
250
265
  File.open(temp_cache_path).read.size.must_equal initial_size
251
266
  end
252
267
 
253
268
  it 'should not break an existing file if save returns json without rates' do
254
269
  initial_size = File.read(temp_cache_path).size
255
- stub(subject).read_from_url { '{"error": "An error"}' }
270
+ stub(subject).json_response { '{"error": "An error"}' }
256
271
  subject.refresh_rates
257
272
  File.open(temp_cache_path).read.size.must_equal initial_size
258
273
  end
259
274
 
260
275
  it 'should not break an existing file if save returns a invalid json' do
261
276
  initial_size = File.read(temp_cache_path).size
262
- stub(subject).read_from_url { '{invalid_json: "An error"}' }
277
+ stub(subject).json_response { '{invalid_json: "An error"}' }
263
278
  subject.refresh_rates
264
279
  File.open(temp_cache_path).read.size.must_equal initial_size
265
280
  end
@@ -270,6 +285,10 @@ describe Money::Bank::OpenExchangeRatesBank do
270
285
  add_to_webmock(subject)
271
286
  end
272
287
 
288
+ it 'should be now when not updated from api' do
289
+ subject.rates_timestamp.must_be :>, Time.at(1_414_008_044)
290
+ end
291
+
273
292
  it 'should be set on update_rates' do
274
293
  subject.update_rates
275
294
  subject.rates_timestamp.must_equal Time.at(1_414_008_044)
@@ -375,13 +394,17 @@ describe Money::Bank::OpenExchangeRatesBank do
375
394
 
376
395
  describe 'source currency' do
377
396
  it 'should be changed when a known currency is given' do
378
- subject.source = 'EUR'
379
- subject.source.must_equal 'EUR'
397
+ source = 'EUR'
398
+ subject.source = source
399
+ subject.source.must_equal source
400
+ subject.source_url.must_include "base=#{source}"
380
401
  end
381
402
 
382
403
  it 'should use USD when given unknown currency' do
383
- subject.source = 'invalid'
384
- subject.source.must_equal 'USD'
404
+ source = 'invalid'
405
+ subject.source = source
406
+ subject.source.must_equal default_source
407
+ subject.source_url.wont_include "base=#{default_source}"
385
408
  end
386
409
  end
387
410
 
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
3
6
  require 'minitest/autorun'
4
7
  require 'rr'
5
8
  require 'webmock/minitest'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-open-exchange-rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Arnoud