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 'minitest-around'
gem 'pry' gem 'pry'
gem 'rack-test' gem 'rack-test'
gem 'rubocop'
gem 'shotgun' gem 'shotgun'
end end

View File

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

View File

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

View File

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

View File

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

View File

@ -27,7 +27,7 @@ class Quote
private private
def base=(base) def base=(base)
@base = base ? base.upcase : DEFAULT_BASE @base = base&.upcase || DEFAULT_BASE
end end
def date=(date) def date=(date)
@ -35,11 +35,8 @@ class Quote
raise Invalid, 'Date too old' unless current_date raise Invalid, 'Date too old' unless current_date
@date = current_date @date = current_date
rescue Sequel::DatabaseError => ex rescue Sequel::DatabaseError => ex
if ex.wrapped_exception.is_a?(PG::DataException) raise Invalid, 'Invalid date' if ex.wrapped_exception.is_a?(PG::DataException)
raise Invalid, 'Invalid date' raise
else
raise
end
end end
def find_rates def find_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_relative 'helper'
require 'converter' require 'converter'
@ -29,7 +31,7 @@ describe Converter do
end end
it 'should raise with invalid currency' do 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' -> { converter.convert(quote) }.must_raise Quote::Invalid, 'Invalid to'
end end
end end

View File

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