From 9c9ebdf557a4bbcb5e57f7eb7697b1079f716a25 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Fri, 27 May 2022 21:57:06 +0200 Subject: [PATCH] Bundle update rubocop and auto correct style issues --- .rubocop_todo.yml | 5 +++++ Gemfile.lock | 20 +++++++++---------- config.ru | 2 +- config/initializers/secret_token.rb | 2 +- lib/foodsoft_config.rb | 2 +- lib/tasks/foodsoft.rake | 4 ++-- lib/tasks/multicoops.rake | 8 ++++---- lib/tasks/seeds.rake | 2 +- spec/integration/balancing_spec.rb | 2 +- .../bank_account_information_importer_spec.rb | 12 +++++------ spec/lib/bank_transaction_reference_spec.rb | 16 +++++++-------- spec/lib/foodsoft_config_spec.rb | 2 +- spec/models/bank_transaction_spec.rb | 2 +- 13 files changed, 42 insertions(+), 37 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dfccf2f0..bff6260c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -892,6 +892,11 @@ Rails/SquishedSQLHeredocs: Rails/TimeZone: Enabled: false +# Offense count: 1 +Rails/TransactionExitStatement: + Exclude: + - 'app/models/bank_transaction.rb' + # Offense count: 3 # Configuration parameters: Include. # Include: app/models/**/*.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7c08ec69..7b855a6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -309,8 +309,8 @@ GEM nokogiri (1.13.4) mini_portile2 (~> 2.8.0) racc (~> 1.4) - parallel (1.21.0) - parser (3.1.0.0) + parallel (1.22.1) + parser (3.1.2.0) ast (~> 2.4.1) pdf-core (0.9.0) polyglot (0.3.5) @@ -393,7 +393,7 @@ GEM redis-namespace (1.8.1) redis (>= 3.0.4) ref (2.0.0) - regexp_parser (2.2.1) + regexp_parser (2.4.0) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -434,22 +434,22 @@ GEM rspec-rerun (1.1.0) rspec (~> 3.0) rspec-support (3.11.0) - rubocop (1.25.1) + rubocop (1.30.0) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.15.2) - parser (>= 3.0.1.1) - rubocop-rails (2.13.2) + rubocop-ast (1.18.0) + parser (>= 3.1.1.0) + rubocop-rails (2.14.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) - rubocop-rspec (2.8.0) + rubocop-rspec (2.11.1) rubocop (~> 1.19) ruby-filemagic (0.7.3) ruby-ole (1.2.12.2) diff --git a/config.ru b/config.ru index e0faca0f..f986eadb 100644 --- a/config.ru +++ b/config.ru @@ -3,6 +3,6 @@ require ::File.expand_path('../config/environment', __FILE__) # https://gist.github.com/ebeigarts/5450422 -map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do +map ENV.fetch('RAILS_RELATIVE_URL_ROOT', '/') do run Foodsoft::Application end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index d56487f0..4f01f173 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -5,7 +5,7 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Foodsoft::Application.config.secret_key_base = begin - if (token = ENV['SECRET_KEY_BASE']).present? + if (token = ENV.fetch('SECRET_KEY_BASE', nil)).present? token elsif Rails.env.production? || Rails.env.staging? raise "You must set SECRET_KEY_BASE" diff --git a/lib/foodsoft_config.rb b/lib/foodsoft_config.rb index e7aed5c9..5a370459 100644 --- a/lib/foodsoft_config.rb +++ b/lib/foodsoft_config.rb @@ -47,7 +47,7 @@ class FoodsoftConfig # Configuration file location. # Taken from environment variable +FOODSOFT_APP_CONFIG+, # or else +config/app_config.yml+. - APP_CONFIG_FILE = ENV['FOODSOFT_APP_CONFIG'] || 'config/app_config.yml' + APP_CONFIG_FILE = ENV.fetch('FOODSOFT_APP_CONFIG', 'config/app_config.yml') # Loaded configuration APP_CONFIG = ActiveSupport::HashWithIndifferentAccess.new diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 5a5c6fa0..760cd5bc 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -51,13 +51,13 @@ namespace :foodsoft do desc "Parse incoming email on stdin (options: RECIPIENT=foodcoop.handling)" task :parse_reply_email => :environment do - FoodsoftMailReceiver.received ENV['RECIPIENT'], STDIN.read + FoodsoftMailReceiver.received ENV.fetch('RECIPIENT', nil), STDIN.read end desc "Start STMP server for incoming email (options: SMTP_SERVER_PORT=2525, SMTP_SERVER_HOST=0.0.0.0)" task :reply_email_smtp_server => :environment do port = ENV['SMTP_SERVER_PORT'].present? ? ENV['SMTP_SERVER_PORT'].to_i : 2525 - host = ENV['SMTP_SERVER_HOST'] + host = ENV.fetch('SMTP_SERVER_HOST', nil) rake_say "Started SMTP server for incoming email on port #{port}." server = FoodsoftMailReceiver.new(ports: port, hosts: host, max_processings: 1, logger: Rails.logger) server.start diff --git a/lib/tasks/multicoops.rake b/lib/tasks/multicoops.rake index cb2f280a..f0c76b8f 100644 --- a/lib/tasks/multicoops.rake +++ b/lib/tasks/multicoops.rake @@ -5,7 +5,7 @@ namespace :multicoops do desc 'Runs a specific rake task for each registered foodcoop, use rake multicoops:run TASK=db:migrate' task :run => :environment do - task_to_run = ENV['TASK'] + task_to_run = ENV.fetch('TASK', nil) last_error = nil FoodsoftConfig.each_coop do |coop| begin @@ -21,9 +21,9 @@ namespace :multicoops do desc 'Runs a specific rake task for a single coop, use rake mutlicoops:run_single TASK=db:migrate FOODCOOP=demo' task :run_single => :environment do - task_to_run = ENV['TASK'] - FoodsoftConfig.select_foodcoop ENV['FOODCOOP'] - rake_say "Run '#{task_to_run}' for #{ENV['FOODCOOP']}" + task_to_run = ENV.fetch('TASK', nil) + FoodsoftConfig.select_foodcoop ENV.fetch('FOODCOOP', nil) + rake_say "Run '#{task_to_run}' for #{ENV.fetch('FOODCOOP', nil)}" Rake::Task[task_to_run].execute end end diff --git a/lib/tasks/seeds.rake b/lib/tasks/seeds.rake index 36e0c201..2437befe 100644 --- a/lib/tasks/seeds.rake +++ b/lib/tasks/seeds.rake @@ -6,7 +6,7 @@ require 'pathname' namespace :db do namespace :seed do - Dir.glob(Rails.root.join('db/seeds/*.seeds.rb')).each do |seedfile| + Dir.glob(Rails.root.join('db/seeds/*.seeds.rb')).sort.each do |seedfile| desc "Load the seed data from #{Pathname.new(seedfile).relative_path_from(Rails.root)}" task File.basename(seedfile, '.seeds.rb') => :environment do require_relative seedfile diff --git a/spec/integration/balancing_spec.rb b/spec/integration/balancing_spec.rb index 55573e19..2239d068 100644 --- a/spec/integration/balancing_spec.rb +++ b/spec/integration/balancing_spec.rb @@ -180,6 +180,6 @@ feature 'settling an order', js: true do end expect(page).to_not have_selector('form#new_order_article') expect(page).to have_content(new_article.name) - expect(order.order_articles.where(article_id: new_article.id)).to_not be nil + expect(order.order_articles.where(article_id: new_article.id)).to_not be_nil end end diff --git a/spec/lib/bank_account_information_importer_spec.rb b/spec/lib/bank_account_information_importer_spec.rb index 3937056c..53b9cad3 100644 --- a/spec/lib/bank_account_information_importer_spec.rb +++ b/spec/lib/bank_account_information_importer_spec.rb @@ -8,7 +8,7 @@ describe BankTransaction do JSON importer = BankAccountInformationImporter.new(bank_account) - expect(importer.import!(content)).to be(nil) + expect(importer.import!(content)).to be_nil end it 'invalid JSON' do @@ -241,7 +241,7 @@ describe BankTransaction do expect(bt.amount).to eq(-238.68) expect(bt.date).to eq('2019-02-13'.to_date) expect(bt.text).to eq('Hammersmith Inc.') - expect(bt.iban).to be(nil) + expect(bt.iban).to be_nil expect(bt.reference).to eq("Corvette Ersatzteile\nMartin Schöneicher, Inv# 123453423, Thx") expect(bt.receipt).to eq('Auslands-Überweisung') end @@ -277,7 +277,7 @@ describe BankTransaction do expect(bt.amount).to eq(-12.3) expect(bt.date).to eq('2019-02-14'.to_date) expect(bt.text).to eq('superbank AG') - expect(bt.iban).to be(nil) + expect(bt.iban).to be_nil expect(bt.reference).to eq("Überweisung US, Wechselspesen u Provision") expect(bt.receipt).to eq('Spesen/Gebühren') end @@ -399,14 +399,14 @@ describe BankTransaction do expect(bt2.text).to eq('CN2') expect(bt2.iban).to eq('CH9300762011623852957') expect(bt2.reference).to eq('RI2') - expect(bt2.receipt).to be(nil) + expect(bt2.receipt).to be_nil bt3 = bank_account.bank_transactions.find_by_external_id("T3") expect(bt3.amount).to eq(33) expect(bt3.date).to eq('2000-03-01'.to_date) expect(bt3.text).to eq('DN3') - expect(bt3.iban).to be(nil) + expect(bt3.iban).to be_nil expect(bt3.reference).to eq('') - expect(bt3.receipt).to be(nil) + expect(bt3.receipt).to be_nil end end diff --git a/spec/lib/bank_transaction_reference_spec.rb b/spec/lib/bank_transaction_reference_spec.rb index 6d5a5490..a03e901b 100644 --- a/spec/lib/bank_transaction_reference_spec.rb +++ b/spec/lib/bank_transaction_reference_spec.rb @@ -2,35 +2,35 @@ require_relative '../spec_helper' describe BankTransactionReference do it 'returns nil for empty input' do - expect(BankTransactionReference.parse('')).to be nil + expect(BankTransactionReference.parse('')).to be_nil end it 'returns nil for invalid string' do - expect(BankTransactionReference.parse('invalid')).to be nil + expect(BankTransactionReference.parse('invalid')).to be_nil end it 'returns nil for FS1A' do - expect(BankTransactionReference.parse('FS1A')).to be nil + expect(BankTransactionReference.parse('FS1A')).to be_nil end it 'returns nil for FS1.1A' do - expect(BankTransactionReference.parse('FS1.1A')).to be nil + expect(BankTransactionReference.parse('FS1.1A')).to be_nil end it 'returns nil for xFS1A1' do - expect(BankTransactionReference.parse('xFS1A1')).to be nil + expect(BankTransactionReference.parse('xFS1A1')).to be_nil end it 'returns nil for .FS1A1' do - expect(BankTransactionReference.parse('.FS1A1')).to be nil + expect(BankTransactionReference.parse('.FS1A1')).to be_nil end it 'returns nil for FS1A1x' do - expect(BankTransactionReference.parse('FS1A1x')).to be nil + expect(BankTransactionReference.parse('FS1A1x')).to be_nil end it 'returns nil for FS1A1.' do - expect(BankTransactionReference.parse('FS1A1.')).to be nil + expect(BankTransactionReference.parse('FS1A1.')).to be_nil end it 'returns correct value for FS1A1' do diff --git a/spec/lib/foodsoft_config_spec.rb b/spec/lib/foodsoft_config_spec.rb index be058f38..a6aa0539 100644 --- a/spec/lib/foodsoft_config_spec.rb +++ b/spec/lib/foodsoft_config_spec.rb @@ -9,7 +9,7 @@ describe FoodsoftConfig do end it 'returns an empty default value' do - expect(FoodsoftConfig[:protected][:LIUhniuyGNKUQTWfbiOQIWYexngo78hqexul]).to be nil + expect(FoodsoftConfig[:protected][:LIUhniuyGNKUQTWfbiOQIWYexngo78hqexul]).to be_nil end it 'returns a configuration value' do diff --git a/spec/models/bank_transaction_spec.rb b/spec/models/bank_transaction_spec.rb index 984d39ae..21d6185e 100644 --- a/spec/models/bank_transaction_spec.rb +++ b/spec/models/bank_transaction_spec.rb @@ -59,7 +59,7 @@ describe BankTransaction do let!(:bank_transaction8) { create :bank_transaction, bank_account: bank_account, reference: "FS#{ordergroup.id}X10", amount: 10 } it 'ignores transaction with invalid reference' do - expect(bank_transaction1.assign_to_ordergroup).to be nil + expect(bank_transaction1.assign_to_ordergroup).to be_nil end it 'ignores transaction with invalid ordergroup' do