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