mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
Fix minitest deprecations
This commit is contained in:
parent
cb8dd05177
commit
52e57475ab
@ -4,5 +4,8 @@ Metrics/BlockLength:
|
|||||||
ExcludedMethods: ['describe', 'helpers']
|
ExcludedMethods: ['describe', 'helpers']
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Max: 13
|
Max: 13
|
||||||
|
Minitest:
|
||||||
|
Include:
|
||||||
|
- '**/*_spec.rb'
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
@ -15,32 +15,32 @@ module Bank
|
|||||||
|
|
||||||
it 'fetches current rates' do
|
it 'fetches current rates' do
|
||||||
feed = Feed.current
|
feed = Feed.current
|
||||||
feed.count.must_be :==, 1
|
_(feed.count).must_be :==, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches rates for the past 90 days' do
|
it 'fetches rates for the past 90 days' do
|
||||||
feed = Feed.ninety_days
|
feed = Feed.ninety_days
|
||||||
feed.count.must_be :>, 1
|
_(feed.count).must_be :>, 1
|
||||||
feed.count.must_be :<=, 90
|
_(feed.count).must_be :<=, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches historical rates' do
|
it 'fetches historical rates' do
|
||||||
feed = Feed.historical
|
feed = Feed.historical
|
||||||
feed.count.must_be :>, 90
|
_(feed.count).must_be :>, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses dates' do
|
it 'parses dates' do
|
||||||
feed = Feed.current
|
feed = Feed.current
|
||||||
day = feed.first
|
day = feed.first
|
||||||
day[:date].must_be_kind_of Date
|
_(day[:date]).must_be_kind_of Date
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses rates' do
|
it 'parses rates' do
|
||||||
feed = Feed.current
|
feed = Feed.current
|
||||||
day = feed.first
|
day = feed.first
|
||||||
day[:rates].each do |iso_code, value|
|
day[:rates].each do |iso_code, value|
|
||||||
iso_code.must_be_kind_of String
|
_(iso_code).must_be_kind_of String
|
||||||
value.must_be_kind_of Float
|
_(value).must_be_kind_of Float
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,46 +22,46 @@ describe Bank do
|
|||||||
|
|
||||||
it 'fetches all rates' do
|
it 'fetches all rates' do
|
||||||
Bank.fetch_all!
|
Bank.fetch_all!
|
||||||
Day.count.must_be :>, 90
|
_(Day.count).must_be :>, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not duplicate when fetching all rates' do
|
it 'does not duplicate when fetching all rates' do
|
||||||
Bank.fetch_all!
|
Bank.fetch_all!
|
||||||
count = Day.count
|
count = Day.count
|
||||||
Bank.fetch_all!
|
Bank.fetch_all!
|
||||||
Day.count.must_equal count
|
_(Day.count).must_equal count
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches rates for last 90 days' do
|
it 'fetches rates for last 90 days' do
|
||||||
Bank.fetch_ninety_days!
|
Bank.fetch_ninety_days!
|
||||||
Day.count.must_be :>, 1
|
_(Day.count).must_be :>, 1
|
||||||
Day.count.must_be :<, 90
|
_(Day.count).must_be :<, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'seeds rates with saved data' do
|
it 'seeds rates with saved data' do
|
||||||
Bank.seed_with_saved_data!
|
Bank.seed_with_saved_data!
|
||||||
Day.count.must_be :>, 90
|
_(Day.count).must_be :>, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not duplicate when fetching rates for last 90 days' do
|
it 'does not duplicate when fetching rates for last 90 days' do
|
||||||
Bank.fetch_ninety_days!
|
Bank.fetch_ninety_days!
|
||||||
count = Day.count
|
count = Day.count
|
||||||
Bank.fetch_ninety_days!
|
Bank.fetch_ninety_days!
|
||||||
Day.count.must_equal count
|
_(Day.count).must_equal count
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches current rates' do
|
it 'fetches current rates' do
|
||||||
Bank.fetch_current!
|
Bank.fetch_current!
|
||||||
Day.count.must_equal 1
|
_(Day.count).must_equal 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not duplicate when fetching current rates' do
|
it 'does not duplicate when fetching current rates' do
|
||||||
2.times { Bank.fetch_current! }
|
2.times { Bank.fetch_current! }
|
||||||
Day.count.must_equal 1
|
_(Day.count).must_equal 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'replaces all rates' do
|
it 'replaces all rates' do
|
||||||
Bank.replace_all!
|
Bank.replace_all!
|
||||||
Day.count.must_be :>, 90
|
_(Day.count).must_be :>, 90
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,10 +9,10 @@ describe CurrencyNames do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns currency codes and names' do
|
it 'returns currency codes and names' do
|
||||||
currency_names.formatted['USD'].must_equal 'United States Dollar'
|
_(currency_names.formatted['USD']).must_equal 'United States Dollar'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a cache key' do
|
it 'has a cache key' do
|
||||||
currency_names.cache_key.wont_be :empty?
|
_(currency_names.cache_key).wont_be :empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
require 'currency'
|
require 'currency'
|
||||||
|
require 'minitest/autorun'
|
||||||
|
|
||||||
describe Currency do
|
describe Currency do
|
||||||
describe '.latest' do
|
describe '.latest' do
|
||||||
it 'returns latest rates' do
|
it 'returns latest rates' do
|
||||||
data = Currency.latest.all
|
data = Currency.latest.all
|
||||||
data.count.must_be :>, 1
|
_(data.count).must_be :>, 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,18 +19,18 @@ describe Currency do
|
|||||||
|
|
||||||
it 'returns everything up to a year' do
|
it 'returns everything up to a year' do
|
||||||
interval = day..day + 365
|
interval = day..day + 365
|
||||||
Currency.between(interval).map(:date).uniq.count.must_be :>, 52
|
_(Currency.between(interval).map(:date).uniq.count).must_be :>, 52
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'samples weekly over a year' do
|
it 'samples weekly over a year' do
|
||||||
interval = day..day + 366
|
interval = day..day + 366
|
||||||
Currency.between(interval).map(:date).uniq.count.must_be :<, 54
|
_(Currency.between(interval).map(:date).uniq.count).must_be :<, 54
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts by date' do
|
it 'sorts by date' do
|
||||||
interval = day..day + 100
|
interval = day..day + 100
|
||||||
dates = Currency.between(interval).map(:date)
|
dates = Currency.between(interval).map(:date)
|
||||||
dates.must_equal dates.sort
|
_(dates).must_equal dates.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,11 +38,11 @@ describe Currency do
|
|||||||
it 'filters symbols' do
|
it 'filters symbols' do
|
||||||
iso_codes = %w[CAD USD]
|
iso_codes = %w[CAD USD]
|
||||||
data = Currency.latest.only(*iso_codes).all
|
data = Currency.latest.only(*iso_codes).all
|
||||||
data.map(&:iso_code).sort.must_equal iso_codes
|
_(data.map(&:iso_code).sort).must_equal iso_codes
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nothing if no matches' do
|
it 'returns nothing if no matches' do
|
||||||
Currency.only('FOO').all.must_be_empty
|
_(Currency.only('FOO').all).must_be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,11 +8,11 @@ describe Day do
|
|||||||
it 'returns latest rates before given date' do
|
it 'returns latest rates before given date' do
|
||||||
date = Date.parse('2010-01-01')
|
date = Date.parse('2010-01-01')
|
||||||
data = Day.latest(date)
|
data = Day.latest(date)
|
||||||
data.first.date.must_be :<=, date
|
_(data.first.date).must_be :<=, date
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nothing if there are no rates before given date' do
|
it 'returns nothing if there are no rates before given date' do
|
||||||
Day.latest(Date.parse('1998-01-01')).must_be_empty
|
_(Day.latest(Date.parse('1998-01-01'))).must_be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -21,13 +21,13 @@ describe Day do
|
|||||||
start_date = Date.parse('2010-01-01')
|
start_date = Date.parse('2010-01-01')
|
||||||
end_date = Date.parse('2010-01-31')
|
end_date = Date.parse('2010-01-31')
|
||||||
dates = Day.between((start_date..end_date)).map(:date).sort
|
dates = Day.between((start_date..end_date)).map(:date).sort
|
||||||
dates.first.must_be :>=, start_date
|
_(dates.first).must_be :>=, start_date
|
||||||
dates.last.must_be :<=, end_date
|
_(dates.last).must_be :<=, end_date
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nothing if there are no rates between given dates' do
|
it 'returns nothing if there are no rates between given dates' do
|
||||||
interval = (Date.parse('1998-01-01')..Date.parse('1998-01-31'))
|
interval = (Date.parse('1998-01-01')..Date.parse('1998-01-31'))
|
||||||
Day.between(interval).must_be_empty
|
_(Day.between(interval)).must_be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,27 +15,27 @@ describe 'the server' do
|
|||||||
|
|
||||||
it 'handles unfound pages' do
|
it 'handles unfound pages' do
|
||||||
get '/foo'
|
get '/foo'
|
||||||
last_response.status.must_equal 404
|
_(last_response.status).must_equal 404
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not process an invalid date' do
|
it 'will not process an invalid date' do
|
||||||
get '/2010-31-01'
|
get '/2010-31-01'
|
||||||
last_response.must_be :unprocessable?
|
_(last_response).must_be :unprocessable?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not process a date before 2000' do
|
it 'will not process a date before 2000' do
|
||||||
get '/1999-01-01'
|
get '/1999-01-01'
|
||||||
last_response.must_be :not_found?
|
_(last_response).must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not process an unavailable base' do
|
it 'will not process an unavailable base' do
|
||||||
get '/latest?base=UAH'
|
get '/latest?base=UAH'
|
||||||
last_response.must_be :not_found?
|
_(last_response).must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles malformed queries' do
|
it 'handles malformed queries' do
|
||||||
get '/latest?base=USD?callback=?'
|
get '/latest?base=USD?callback=?'
|
||||||
last_response.must_be :not_found?
|
_(last_response).must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not return stale dates' do
|
it 'does not return stale dates' do
|
||||||
@ -44,7 +44,7 @@ describe 'the server' do
|
|||||||
date = json['date']
|
date = json['date']
|
||||||
Day.latest.delete
|
Day.latest.delete
|
||||||
get '/latest'
|
get '/latest'
|
||||||
json['date'].wont_equal date
|
_(json['date']).wont_equal date
|
||||||
raise Sequel::Rollback
|
raise Sequel::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,69 +5,69 @@ require 'query'
|
|||||||
|
|
||||||
describe Query do
|
describe Query do
|
||||||
it 'builds a query hash' do
|
it 'builds a query hash' do
|
||||||
Query.build(date: '2014-01-01').must_be_kind_of Hash
|
_(Query.build(date: '2014-01-01')).must_be_kind_of Hash
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns given amount' do
|
it 'returns given amount' do
|
||||||
query = Query.new(amount: '100')
|
query = Query.new(amount: '100')
|
||||||
query.amount.must_equal 100.0
|
_(query.amount).must_equal 100.0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'defaults amount to nothing' do
|
it 'defaults amount to nothing' do
|
||||||
query = Query.new
|
query = Query.new
|
||||||
query.amount.must_be_nil
|
_(query.amount).must_be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns given base' do
|
it 'returns given base' do
|
||||||
query = Query.new(base: 'USD')
|
query = Query.new(base: 'USD')
|
||||||
query.base.must_equal 'USD'
|
_(query.base).must_equal 'USD'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'upcases given base' do
|
it 'upcases given base' do
|
||||||
query = Query.new(base: 'usd')
|
query = Query.new(base: 'usd')
|
||||||
query.base.must_equal 'USD'
|
_(query.base).must_equal 'USD'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'defaults base to nothing' do
|
it 'defaults base to nothing' do
|
||||||
query = Query.new
|
query = Query.new
|
||||||
query.base.must_be_nil
|
_(query.base).must_be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'aliases base with from' do
|
it 'aliases base with from' do
|
||||||
query = Query.new(from: 'USD')
|
query = Query.new(from: 'USD')
|
||||||
query.base.must_equal 'USD'
|
_(query.base).must_equal 'USD'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns given symbols' do
|
it 'returns given symbols' do
|
||||||
query = Query.new(symbols: 'USD,GBP')
|
query = Query.new(symbols: 'USD,GBP')
|
||||||
query.symbols.must_equal %w[USD GBP]
|
_(query.symbols).must_equal %w[USD GBP]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'upcases given symbols' do
|
it 'upcases given symbols' do
|
||||||
query = Query.new(symbols: 'usd,gbp')
|
query = Query.new(symbols: 'usd,gbp')
|
||||||
query.symbols.must_equal %w[USD GBP]
|
_(query.symbols).must_equal %w[USD GBP]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'aliases symbols with to' do
|
it 'aliases symbols with to' do
|
||||||
query = Query.new(to: 'USD')
|
query = Query.new(to: 'USD')
|
||||||
query.symbols.must_equal ['USD']
|
_(query.symbols).must_equal ['USD']
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'defaults symbols to nothing' do
|
it 'defaults symbols to nothing' do
|
||||||
query = Query.new
|
query = Query.new
|
||||||
query.symbols.must_be_nil
|
_(query.symbols).must_be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns given date' do
|
it 'returns given date' do
|
||||||
date = '2014-01-01'
|
date = '2014-01-01'
|
||||||
query = Query.new(date: date)
|
query = Query.new(date: date)
|
||||||
query.date.must_equal Date.parse(date)
|
_(query.date).must_equal Date.parse(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns given date interval' do
|
it 'returns given date interval' do
|
||||||
start_date = '2014-01-01'
|
start_date = '2014-01-01'
|
||||||
end_date = '2014-12-31'
|
end_date = '2014-12-31'
|
||||||
query = Query.new(start_date: start_date, end_date: end_date)
|
query = Query.new(start_date: start_date, end_date: end_date)
|
||||||
query.date.must_equal((Date.parse(start_date)..Date.parse(end_date)))
|
_(query.date).must_equal((Date.parse(start_date)..Date.parse(end_date)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,23 +14,23 @@ module Quote
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'requires data' do
|
it 'requires data' do
|
||||||
-> { quote.perform }.must_raise NotImplementedError
|
_ { quote.perform }.must_raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not know how to format result' do
|
it 'does not know how to format result' do
|
||||||
-> { quote.formatted }.must_raise NotImplementedError
|
_ { quote.formatted }.must_raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not know how to generate a cache key' do
|
it 'does not know how to generate a cache key' do
|
||||||
-> { quote.cache_key }.must_raise NotImplementedError
|
_ { quote.cache_key }.must_raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'defaults base to Euro' do
|
it 'defaults base to Euro' do
|
||||||
quote.base.must_equal 'EUR'
|
_(quote.base).must_equal 'EUR'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'defaults amount to 1' do
|
it 'defaults amount to 1' do
|
||||||
quote.amount.must_equal 1
|
_(quote.amount).must_equal 1
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when given data' do
|
describe 'when given data' do
|
||||||
@ -67,7 +67,7 @@ module Quote
|
|||||||
|
|
||||||
it 'finds nothing' do
|
it 'finds nothing' do
|
||||||
quote.perform
|
quote.perform
|
||||||
quote.not_found?.must_equal true
|
_(quote.not_found?).must_equal true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ module Quote
|
|||||||
|
|
||||||
it 'finds nothing' do
|
it 'finds nothing' do
|
||||||
quote.perform
|
quote.perform
|
||||||
quote.not_found?.must_equal true
|
_(quote.not_found?).must_equal true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,24 +18,24 @@ module Quote
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns rates' do
|
it 'returns rates' do
|
||||||
quote.formatted[:rates].wont_be :empty?
|
_(quote.formatted[:rates]).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes given date' do
|
it 'quotes given date' do
|
||||||
Date.parse(quote.formatted[:date]).must_be :<=, date
|
_(Date.parse(quote.formatted[:date])).must_be :<=, date
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes against the Euro' do
|
it 'quotes against the Euro' do
|
||||||
quote.formatted[:rates].keys.wont_include 'EUR'
|
_(quote.formatted[:rates].keys).wont_include 'EUR'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
rates = quote.formatted[:rates]
|
rates = quote.formatted[:rates]
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a cache key' do
|
it 'has a cache key' do
|
||||||
quote.cache_key.wont_be :empty?
|
_(quote.cache_key).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'given a new base' do
|
describe 'given a new base' do
|
||||||
@ -44,12 +44,12 @@ module Quote
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes against that base' do
|
it 'quotes against that base' do
|
||||||
quote.formatted[:rates].keys.wont_include 'USD'
|
_(quote.formatted[:rates].keys).wont_include 'USD'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
rates = quote.formatted[:rates]
|
rates = quote.formatted[:rates]
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,13 +60,13 @@ module Quote
|
|||||||
|
|
||||||
it 'quotes only for those symbols' do
|
it 'quotes only for those symbols' do
|
||||||
rates = quote.formatted[:rates]
|
rates = quote.formatted[:rates]
|
||||||
rates.keys.must_include 'USD'
|
_(rates.keys).must_include 'USD'
|
||||||
rates.keys.wont_include 'CAD'
|
_(rates.keys).wont_include 'CAD'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
rates = quote.formatted[:rates]
|
rates = quote.formatted[:rates]
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ module Quote
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'calculates quotes for that amount' do
|
it 'calculates quotes for that amount' do
|
||||||
quote.formatted[:rates]['USD'].must_be :>, 10
|
_(quote.formatted[:rates]['USD']).must_be :>, 10
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,12 +5,12 @@ require 'quote/interval'
|
|||||||
|
|
||||||
module Quote
|
module Quote
|
||||||
describe Interval do
|
describe Interval do
|
||||||
let(:date_interval) do
|
let(:dates) do
|
||||||
(Date.parse('2010-01-01')..Date.parse('2010-12-31'))
|
(Date.parse('2010-01-01')..Date.parse('2010-12-31'))
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:quote) do
|
let(:quote) do
|
||||||
Interval.new(date: date_interval)
|
Interval.new(date: dates)
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@ -18,75 +18,75 @@ module Quote
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns rates' do
|
it 'returns rates' do
|
||||||
quote.formatted[:rates].wont_be :empty?
|
_(quote.formatted[:rates]).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes given date interval' do
|
it 'quotes given date interval' do
|
||||||
Date.parse(quote.formatted[:start_date]).must_be :>=, date_interval.first
|
_(Date.parse(quote.formatted[:start_date])).must_be :>=, dates.first
|
||||||
Date.parse(quote.formatted[:end_date]).must_be :<=, date_interval.last
|
_(Date.parse(quote.formatted[:end_date])).must_be :<=, dates.last
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes against the Euro' do
|
it 'quotes against the Euro' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.wont_include 'EUR'
|
_(rates.keys).wont_include 'EUR'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a cache key' do
|
it 'has a cache key' do
|
||||||
quote.cache_key.wont_be :empty?
|
_(quote.cache_key).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'given a new base' do
|
describe 'given a new base' do
|
||||||
let(:quote) do
|
let(:quote) do
|
||||||
Interval.new(date: date_interval, base: 'USD')
|
Interval.new(date: dates, base: 'USD')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes against that base' do
|
it 'quotes against that base' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.wont_include 'USD'
|
_(rates.keys).wont_include 'USD'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'given symbols' do
|
describe 'given symbols' do
|
||||||
let(:quote) do
|
let(:quote) do
|
||||||
Interval.new(date: date_interval, symbols: %w[USD GBP JPY])
|
Interval.new(date: dates, symbols: %w[USD GBP JPY])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'quotes only for those symbols' do
|
it 'quotes only for those symbols' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.must_include 'USD'
|
_(rates.keys).must_include 'USD'
|
||||||
rates.keys.wont_include 'CAD'
|
_(rates.keys).wont_include 'CAD'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sorts rates' do
|
it 'sorts rates' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates.keys.must_equal rates.keys.sort
|
_(rates.keys).must_equal rates.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when given an amount' do
|
describe 'when given an amount' do
|
||||||
let(:quote) do
|
let(:quote) do
|
||||||
Interval.new(date: date_interval, amount: 100)
|
Interval.new(date: dates, amount: 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calculates quotes for that amount' do
|
it 'calculates quotes for that amount' do
|
||||||
quote.formatted[:rates].each_value do |rates|
|
quote.formatted[:rates].each_value do |rates|
|
||||||
rates['USD'].must_be :>, 10
|
_(rates['USD']).must_be :>, 10
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,46 +13,46 @@ describe 'the server' do
|
|||||||
|
|
||||||
it 'redirects root to documentation site' do
|
it 'redirects root to documentation site' do
|
||||||
get '/'
|
get '/'
|
||||||
last_response.must_be :redirect?
|
_(last_response).must_be :redirect?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns latest quotes' do
|
it 'returns latest quotes' do
|
||||||
get '/latest'
|
get '/latest'
|
||||||
last_response.must_be :ok?
|
_(last_response).must_be :ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets base currency' do
|
it 'sets base currency' do
|
||||||
get '/latest'
|
get '/latest'
|
||||||
res = Oj.load(last_response.body)
|
res = Oj.load(last_response.body)
|
||||||
get '/latest?from=USD'
|
get '/latest?from=USD'
|
||||||
json.wont_equal res
|
_(json).wont_equal res
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets base amount' do
|
it 'sets base amount' do
|
||||||
get '/latest?amount=10'
|
get '/latest?amount=10'
|
||||||
json['rates']['USD'].must_be :>, 10
|
_(json['rates']['USD']).must_be :>, 10
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters symbols' do
|
it 'filters symbols' do
|
||||||
get '/latest?to=USD'
|
get '/latest?to=USD'
|
||||||
json['rates'].keys.must_equal %w[USD]
|
_(json['rates'].keys).must_equal %w[USD]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns historical quotes' do
|
it 'returns historical quotes' do
|
||||||
get '/2012-11-20'
|
get '/2012-11-20'
|
||||||
json['rates'].wont_be :empty?
|
_(json['rates']).wont_be :empty?
|
||||||
json['date'].must_equal '2012-11-20'
|
_(json['date']).must_equal '2012-11-20'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'works around holidays' do
|
it 'works around holidays' do
|
||||||
get '/2010-01-01'
|
get '/2010-01-01'
|
||||||
json['rates'].wont_be :empty?
|
_(json['rates']).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an ETag' do
|
it 'returns an ETag' do
|
||||||
%w[/latest /2012-11-20].each do |path|
|
%w[/latest /2012-11-20].each do |path|
|
||||||
get path
|
get path
|
||||||
headers['ETag'].wont_be_nil
|
_(headers['ETag']).wont_be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,30 +76,30 @@ describe 'the server' do
|
|||||||
|
|
||||||
it 'converts an amount' do
|
it 'converts an amount' do
|
||||||
get '/latest?from=GBP&to=USD&amount=100'
|
get '/latest?from=GBP&to=USD&amount=100'
|
||||||
json['rates']['USD'].must_be :>, 100
|
_(json['rates']['USD']).must_be :>, 100
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns rates for a given period' do
|
it 'returns rates for a given period' do
|
||||||
get '/2010-01-01..2010-12-31'
|
get '/2010-01-01..2010-12-31'
|
||||||
json['start_date'].wont_be :empty?
|
_(json['start_date']).wont_be :empty?
|
||||||
json['end_date'].wont_be :empty?
|
_(json['end_date']).wont_be :empty?
|
||||||
json['rates'].wont_be :empty?
|
_(json['rates']).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns rates when given period does not include end date' do
|
it 'returns rates when given period does not include end date' do
|
||||||
get '/2010-01-01..'
|
get '/2010-01-01..'
|
||||||
json['start_date'].wont_be :empty?
|
_(json['start_date']).wont_be :empty?
|
||||||
json['end_date'].wont_be :empty?
|
_(json['end_date']).wont_be :empty?
|
||||||
json['rates'].wont_be :empty?
|
_(json['rates']).wont_be :empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns currencies' do
|
it 'returns currencies' do
|
||||||
get '/currencies'
|
get '/currencies'
|
||||||
json['USD'].must_equal 'United States Dollar'
|
_(json['USD']).must_equal 'United States Dollar'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles JSONP' do
|
it 'handles JSONP' do
|
||||||
get '/latest?callback=foo'
|
get '/latest?callback=foo'
|
||||||
last_response.body.must_be :start_with?, 'foo'
|
_(last_response.body).must_be :start_with?, 'foo'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user