mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-24 03:52:31 +01:00
Fix rubocop offenses
This commit is contained in:
parent
bbbd280762
commit
62fd0e4b09
@ -1,7 +1,7 @@
|
||||
Metrics/AbcSize:
|
||||
Max: 25.04
|
||||
Metrics/BlockLength:
|
||||
IgnoredMethods: ['describe', 'route']
|
||||
AllowedMethods: ['describe', 'route']
|
||||
Metrics/MethodLength:
|
||||
Max: 13
|
||||
Minitest:
|
||||
|
@ -6,5 +6,5 @@ require 'sequel'
|
||||
Sequel.extension :pg_json_ops
|
||||
Sequel.single_threaded = true
|
||||
Sequel.connect(ENV['DATABASE_URL'] ||
|
||||
"postgres://localhost:#{ENV['PGPORT']}/frankfurter_#{App.env}")
|
||||
"postgres://localhost:#{ENV.fetch('PGPORT', nil)}/frankfurter_#{App.env}")
|
||||
.extension :pg_json
|
||||
|
@ -32,6 +32,6 @@ class Query
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ amount: amount, base: base, date: date, symbols: symbols }.compact
|
||||
{ amount:, base:, date:, symbols: }.compact
|
||||
end
|
||||
end
|
||||
|
@ -6,8 +6,8 @@ require 'digest'
|
||||
module Quote
|
||||
class EndOfDay < Base
|
||||
def formatted
|
||||
{ amount: amount,
|
||||
base: base,
|
||||
{ amount:,
|
||||
base:,
|
||||
date: result.keys.first,
|
||||
rates: result.values.first }
|
||||
end
|
||||
|
@ -5,8 +5,8 @@ require 'quote/base'
|
||||
module Quote
|
||||
class Interval < Base
|
||||
def formatted
|
||||
{ amount: amount,
|
||||
base: base,
|
||||
{ amount:,
|
||||
base:,
|
||||
start_date: result.keys.first,
|
||||
end_date: result.keys.last,
|
||||
rates: result }
|
||||
|
@ -13,18 +13,18 @@ module Roundable
|
||||
if value > 5000
|
||||
value.round
|
||||
elsif value > 80
|
||||
Float(format('%<value>.2f', value: value))
|
||||
Float(format('%<value>.2f', value:))
|
||||
elsif value > 20
|
||||
Float(format('%<value>.3f', value: value))
|
||||
Float(format('%<value>.3f', value:))
|
||||
elsif value > 1
|
||||
Float(format('%<value>.4f', value: value))
|
||||
Float(format('%<value>.4f', value:))
|
||||
# I had originally opted to round smaller numbers simply to five decimal
|
||||
# places but introduced this refinement to handle an edge case where a
|
||||
# lower-rate base currency like IDR produces less precise quotes.
|
||||
elsif value > 0.0001
|
||||
Float(format('%<value>.5f', value: value))
|
||||
Float(format('%<value>.5f', value:))
|
||||
else
|
||||
Float(format('%<value>.6f', value: value))
|
||||
Float(format('%<value>.6f', value:))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -60,14 +60,14 @@ describe Query do
|
||||
|
||||
it 'returns given date' do
|
||||
date = '2014-01-01'
|
||||
query = Query.new(date: date)
|
||||
query = Query.new(date:)
|
||||
_(query.date).must_equal Date.parse(date)
|
||||
end
|
||||
|
||||
it 'returns given date interval' do
|
||||
start_date = '2014-01-01'
|
||||
end_date = '2014-12-31'
|
||||
query = Query.new(start_date: start_date, end_date: end_date)
|
||||
query = Query.new(start_date:, end_date:)
|
||||
_(query.date).must_equal((Date.parse(start_date)..Date.parse(end_date)))
|
||||
end
|
||||
end
|
||||
|
@ -46,6 +46,7 @@ module Quote
|
||||
|
||||
it 'performs only once' do
|
||||
quote.perform
|
||||
|
||||
refute quote.perform
|
||||
end
|
||||
end
|
||||
@ -56,12 +57,12 @@ module Quote
|
||||
end
|
||||
|
||||
let(:quote) do
|
||||
klass.new(date: date, base: 'ILS')
|
||||
klass.new(date:, base: 'ILS')
|
||||
end
|
||||
|
||||
before do
|
||||
def quote.fetch_data
|
||||
[{ date: date, iso_code: 'USD', rate: 1 }]
|
||||
[{ date:, iso_code: 'USD', rate: 1 }]
|
||||
end
|
||||
end
|
||||
|
||||
@ -77,12 +78,12 @@ module Quote
|
||||
end
|
||||
|
||||
let(:quote) do
|
||||
klass.new(date: date, base: 'USD', symbols: ['FOO'])
|
||||
klass.new(date:, base: 'USD', symbols: ['FOO'])
|
||||
end
|
||||
|
||||
before do
|
||||
def quote.fetch_data
|
||||
[{ date: date, iso_code: 'USD', rate: 1 }]
|
||||
[{ date:, iso_code: 'USD', rate: 1 }]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -10,7 +10,7 @@ module Quote
|
||||
end
|
||||
|
||||
let(:quote) do
|
||||
EndOfDay.new(date: date)
|
||||
EndOfDay.new(date:)
|
||||
end
|
||||
|
||||
before do
|
||||
@ -40,7 +40,7 @@ module Quote
|
||||
|
||||
describe 'given a new base' do
|
||||
let(:quote) do
|
||||
EndOfDay.new(date: date, base: 'USD')
|
||||
EndOfDay.new(date:, base: 'USD')
|
||||
end
|
||||
|
||||
it 'quotes against that base' do
|
||||
@ -55,7 +55,7 @@ module Quote
|
||||
|
||||
describe 'given symbols' do
|
||||
let(:quote) do
|
||||
EndOfDay.new(date: date, symbols: %w[USD GBP JPY])
|
||||
EndOfDay.new(date:, symbols: %w[USD GBP JPY])
|
||||
end
|
||||
|
||||
it 'quotes only for those symbols' do
|
||||
@ -72,7 +72,7 @@ module Quote
|
||||
|
||||
describe 'when given an amount' do
|
||||
let(:quote) do
|
||||
EndOfDay.new(date: date, amount: 100)
|
||||
EndOfDay.new(date:, amount: 100)
|
||||
end
|
||||
|
||||
it 'calculates quotes for that amount' do
|
||||
|
@ -34,7 +34,7 @@ describe Roundable do
|
||||
end
|
||||
|
||||
it 'conforms to ECB conventions' do
|
||||
skip "We don't conform ¯\_(ツ)_/¯"
|
||||
skip "We don't conform ¯_(ツ)_/¯"
|
||||
require 'day'
|
||||
rates = Day.all.sample.rates.to_a
|
||||
rates.shuffle.each do |_currency, rate|
|
||||
|
@ -60,6 +60,7 @@ describe 'the server' do
|
||||
%w[/ /latest /2012-11-20].each do |path|
|
||||
header 'Origin', '*'
|
||||
get path
|
||||
|
||||
assert headers.key?('Access-Control-Allow-Methods')
|
||||
end
|
||||
end
|
||||
@ -70,6 +71,7 @@ describe 'the server' do
|
||||
header 'Access-Control-Request-Method', 'GET'
|
||||
header 'Access-Control-Request-Headers', 'Content-Type'
|
||||
options path
|
||||
|
||||
assert headers.key?('Access-Control-Allow-Methods')
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user