Use Rubocop and fix existing offences

This commit is contained in:
Hakan Ensari 2016-10-11 16:54:28 +01:00
parent 597792c988
commit 4a1f4ca3c1
11 changed files with 40 additions and 13 deletions

View File

@ -18,5 +18,6 @@ group :development do
gem 'minitest-around'
gem 'pry'
gem 'rack-test'
gem 'rubocop'
gem 'shotgun'
end

View File

@ -16,7 +16,10 @@ GEM
ast
ruby-ll (~> 2.1)
oj (2.15.1)
parser (2.3.1.4)
ast (~> 2.2)
pg (0.18.4)
powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -27,11 +30,19 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
rainbow (2.1.0)
raindrops (0.16.0)
rake (11.1.2)
rubocop (0.43.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-ll (2.1.2)
ansi
ast
ruby-progressbar (1.8.1)
sequel (4.35.0)
sequel_pg (1.6.17)
pg (>= 0.8.0)
@ -44,6 +55,7 @@ GEM
tilt (>= 1.3, < 3)
slop (3.6.0)
tilt (2.0.5)
unicode-display_width (1.1.1)
unicorn (5.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
@ -61,6 +73,7 @@ DEPENDENCIES
rack-cors
rack-test
rake
rubocop
sequel_pg
shotgun
sinatra
@ -70,4 +83,4 @@ RUBY VERSION
ruby 2.3.1p112
BUNDLED WITH
1.12.3
1.13.6

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
Dir.glob('lib/tasks/*.rake').each { |r| import r }
task default: %w(db:migrate rates:load test)
task default: %w(db:migrate rates:load test rubocop)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require './config/environment'
require 'api'

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i
preload_app true
worker_processes((ENV['WORKER_PROCESSES'] || 4).to_i)
worker_processes worker_process_count
timeout 10
before_fork do |_, _|

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
oldrev, newrev = ARGV
def run(cmd)
@ -10,7 +12,7 @@ run 'whenever --update-crontab'
tasks = []
num_migrations = `git diff #{oldrev} #{newrev} --diff-filter=A --name-only -z db/migrate`.split("\0").size
tasks << 'db:migrate' if num_migrations > 0
tasks << 'db:migrate' if num_migrations.positive?
tasks << 'rates:load'
run "foreman run bundle exec rake #{tasks.join(' ')}"

View File

@ -11,8 +11,7 @@ class Currency < Sequel::Model
end
def current_date
currency = recent.first
currency.date if currency
recent.first&.date
end
def current_date_before(value)

View File

@ -27,7 +27,7 @@ class Quote
private
def base=(base)
@base = base ? base.upcase : DEFAULT_BASE
@base = base&.upcase || DEFAULT_BASE
end
def date=(date)
@ -35,12 +35,9 @@ class Quote
raise Invalid, 'Date too old' unless current_date
@date = current_date
rescue Sequel::DatabaseError => ex
if ex.wrapped_exception.is_a?(PG::DataException)
raise Invalid, 'Invalid date'
else
raise Invalid, 'Invalid date' if ex.wrapped_exception.is_a?(PG::DataException)
raise
end
end
def find_rates
quoted_against_default_base? ? find_default_rates : find_rebased_rates

5
lib/tasks/rubocop.rake Normal file
View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
require 'rubocop/rake_task'
RuboCop::RakeTask.new

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'helper'
require 'converter'
@ -29,7 +31,7 @@ describe Converter do
end
it 'should raise with invalid currency' do
quote.stub :rates, Hash.new do
quote.stub :rates, {} do
-> { converter.convert(quote) }.must_raise Quote::Invalid, 'Invalid to'
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'helper'
require 'rack/test'
require 'api'