diff --git a/Gemfile b/Gemfile index 4239d7f7..0bf0d832 100644 --- a/Gemfile +++ b/Gemfile @@ -89,7 +89,7 @@ group :development do end group :development, :test do - gem 'rubocop', '1.50.2', require: false + gem 'rubocop', require: false gem 'rubocop-rails', require: false gem 'rubocop-rspec', require: false gem 'ruby-prof', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 72a3eff2..4c2d9a37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -316,10 +316,9 @@ GEM nokogiri (1.13.1) mini_portile2 (~> 2.7.0) racc (~> 1.4) - parallel (1.24.0) - parser (3.3.0.2) + parallel (1.21.0) + parser (3.1.0.0) ast (~> 2.4.1) - racc pdf-core (0.9.0) polyglot (0.3.5) prawn (2.4.0) @@ -401,7 +400,7 @@ GEM redis-namespace (1.8.1) redis (>= 3.0.4) ref (2.0.0) - regexp_parser (2.9.0) + regexp_parser (2.2.1) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -411,7 +410,7 @@ GEM redis-namespace (~> 1.6) sinatra (>= 0.9.2) vegas (~> 0.1.2) - rexml (3.2.6) + rexml (3.2.5) roo (2.8.3) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) @@ -442,18 +441,17 @@ GEM rspec-rerun (1.1.0) rspec (~> 3.0) rspec-support (3.11.0) - rubocop (1.50.2) - json (~> 2.3) + rubocop (1.25.1) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rexml + rubocop-ast (>= 1.15.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.15.2) + parser (>= 3.0.1.1) rubocop-rails (2.13.2) activesupport (>= 4.2.0) rack (>= 1.1) @@ -463,7 +461,7 @@ GEM ruby-filemagic (0.7.3) ruby-ole (1.2.12.2) ruby-prof (1.4.3) - ruby-progressbar (1.13.0) + ruby-progressbar (1.11.0) ruby-units (2.3.2) ruby2_keywords (0.0.5) ruby_parser (3.18.1) @@ -542,7 +540,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8) - unicode-display_width (2.5.0) + unicode-display_width (2.1.0) uniform_notifier (1.14.2) vegas (0.1.11) rack (>= 1.0.0) @@ -634,7 +632,7 @@ DEPENDENCIES rspec-core rspec-rails rspec-rerun - rubocop (= 1.50.2) + rubocop rubocop-rails rubocop-rspec ruby-filemagic diff --git a/app/controllers/concerns/locale.rb b/app/controllers/concerns/locale.rb index 794d7c24..22686c15 100644 --- a/app/controllers/concerns/locale.rb +++ b/app/controllers/concerns/locale.rb @@ -18,7 +18,7 @@ def session_language end def browser_language - request.env['HTTP_ACCEPT_LANGUAGE']&.scan(/^[a-z]{2}/)&.first + request.env['HTTP_ACCEPT_LANGUAGE'] ? request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first : nil end def default_language diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 42769f08..5b3d0780 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,9 @@ class SessionsController < ApplicationController layout 'login' def new - respond_to(&:html) + respond_to do |format| + format.html + end end def create diff --git a/app/models/article.rb b/app/models/article.rb index 001180ea..46aeb014 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -101,7 +101,7 @@ def in_open_order @in_open_order ||= begin order_articles = OrderArticle.where(order_id: Order.open.collect(&:id)) order_article = order_articles.detect { |oa| oa.article_version.article_id == id } - order_article&.order + order_article ? order_article.order : nil end end diff --git a/app/models/article_version.rb b/app/models/article_version.rb index 50cf1b37..fbe08d89 100644 --- a/app/models/article_version.rb +++ b/app/models/article_version.rb @@ -138,7 +138,7 @@ def duplicate_including_article_unit_ratios # @return [Hash] Changed attributes with new values def self.compare_attributes(attributes) unequal_attributes = attributes.select { |_name, values| values[0] != values[1] && !(values[0].blank? && values[1].blank?) } - unequal_attributes.to_a.to_h { |a| [a[0], a[1].last] } + unequal_attributes.to_a.map { |a| [a[0], a[1].last] }.to_h end protected diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 4d74bab4..c00208ab 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -64,14 +64,14 @@ def update_quantities(quantity, tolerance) logger.debug("Need to decrease quantities for GroupOrderArticleQuantity[#{quantities[i].id}]") if (quantity < self.quantity && quantities[i].quantity > 0) delta = self.quantity - quantity - delta = [delta, quantities[i].quantity].min + delta = (delta > quantities[i].quantity ? quantities[i].quantity : delta) logger.debug("Decreasing quantity by #{delta}") quantities[i].quantity -= delta self.quantity -= delta end if (tolerance < self.tolerance && quantities[i].tolerance > 0) delta = self.tolerance - tolerance - delta = [delta, quantities[i].tolerance].min + delta = (delta > quantities[i].tolerance ? quantities[i].tolerance : delta) logger.debug("Decreasing tolerance by #{delta}") quantities[i].tolerance -= delta self.tolerance -= delta diff --git a/config/environments/production.rb b/config/environments/production.rb index ab83a4f6..0560b38d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -98,7 +98,7 @@ end # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = Logger::Formatter.new + config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' diff --git a/config/initializers/currency_display.rb b/config/initializers/currency_display.rb index 71d108d2..7caa6a64 100644 --- a/config/initializers/currency_display.rb +++ b/config/initializers/currency_display.rb @@ -1,7 +1,7 @@ # remove all currency translations, so that we can set the default language and # have it shown in all other languages too -I18n.available_locales.each do |locale| - unless locale == I18n.default_locale - I18n.backend.store_translations(locale, number: { currency: { format: { unit: nil } } }) +::I18n.available_locales.each do |locale| + unless locale == ::I18n.default_locale + ::I18n.backend.store_translations(locale, number: { currency: { format: { unit: nil } } }) end end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 6d310e32..14054341 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.fetch('SECRET_KEY_BASE', nil)).present? + if (token = ENV['SECRET_KEY_BASE']).present? token elsif Rails.env.production? || Rails.env.staging? raise "You must set SECRET_KEY_BASE" diff --git a/lib/apple_bar.rb b/lib/apple_bar.rb index 81d1a1ea..a2176ea3 100644 --- a/lib/apple_bar.rb +++ b/lib/apple_bar.rb @@ -26,7 +26,7 @@ def group_bar_state # Use apples as percentage, but show at least 10 percent def group_bar_width - [@ordergroup.apples, 2].max + @ordergroup.apples < 2 ? 2 : @ordergroup.apples end def mean_order_amount_per_job diff --git a/lib/tasks/db_shared.rake b/lib/tasks/db_shared.rake index f2fd7046..eb0230b4 100644 --- a/lib/tasks/db_shared.rake +++ b/lib/tasks/db_shared.rake @@ -3,21 +3,21 @@ task spec: ['shared:db:test:prepare'] namespace :shared do namespace :db do |ns| [:drop, :create, :setup, :migrate, :rollback, :seed, :version].each do |task_name| - task task_name => :environment do + task task_name do Rake::Task["db:#{task_name}"].invoke end end namespace :schema do [:load, :dump].each do |task_name| - task task_name => :environment do + task task_name do Rake::Task["db:schema:#{task_name}"].invoke end end end namespace :test do - task prepare: :environment do + task :prepare do Rake::Task['db:test:prepare'].invoke end end @@ -33,7 +33,7 @@ namespace :shared do task set_custom_config: :environment do # save current vars @original_config = { - env_schema: ENV.fetch('SCHEMA', nil), + env_schema: ENV['SCHEMA'], config: Rails.application.config.dup } diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 760cd5bc..5a5c6fa0 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.fetch('RECIPIENT', nil), STDIN.read + FoodsoftMailReceiver.received ENV['RECIPIENT'], 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.fetch('SMTP_SERVER_HOST', nil) + host = ENV['SMTP_SERVER_HOST'] 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 f0c76b8f..cb2f280a 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.fetch('TASK', nil) + task_to_run = ENV['TASK'] 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.fetch('TASK', nil) - FoodsoftConfig.select_foodcoop ENV.fetch('FOODCOOP', nil) - rake_say "Run '#{task_to_run}' for #{ENV.fetch('FOODCOOP', nil)}" + task_to_run = ENV['TASK'] + FoodsoftConfig.select_foodcoop ENV['FOODCOOP'] + rake_say "Run '#{task_to_run}' for #{ENV['FOODCOOP']}" Rake::Task[task_to_run].execute end end diff --git a/lib/tasks/seeds.rake b/lib/tasks/seeds.rake index 2437befe..36e0c201 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')).sort.each do |seedfile| + Dir.glob(Rails.root.join('db/seeds/*.seeds.rb')).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/plugins/discourse/foodsoft_discourse.gemspec b/plugins/discourse/foodsoft_discourse.gemspec index 4400bcf4..6d2fb5d4 100644 --- a/plugins/discourse/foodsoft_discourse.gemspec +++ b/plugins/discourse/foodsoft_discourse.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Allow SSO login via Discourse" s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "deface", "~> 1.0" diff --git a/plugins/documents/foodsoft_documents.gemspec b/plugins/documents/foodsoft_documents.gemspec index 1301fa11..c0a4f8fd 100644 --- a/plugins/documents/foodsoft_documents.gemspec +++ b/plugins/documents/foodsoft_documents.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Adds simple document management to foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "deface", "~> 1.0" diff --git a/plugins/links/foodsoft_links.gemspec b/plugins/links/foodsoft_links.gemspec index e899c082..04fc03f9 100644 --- a/plugins/links/foodsoft_links.gemspec +++ b/plugins/links/foodsoft_links.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Adds simple link management to foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "deface", "~> 1.0" diff --git a/plugins/messages/foodsoft_messages.gemspec b/plugins/messages/foodsoft_messages.gemspec index 0dfc7163..13050bf8 100644 --- a/plugins/messages/foodsoft_messages.gemspec +++ b/plugins/messages/foodsoft_messages.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Adds the ability to exchange messages to foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "base32" diff --git a/plugins/polls/foodsoft_polls.gemspec b/plugins/polls/foodsoft_polls.gemspec index 63e7db29..e5b25173 100644 --- a/plugins/polls/foodsoft_polls.gemspec +++ b/plugins/polls/foodsoft_polls.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Adds possibility to do polls with foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "deface", "~> 1.0" diff --git a/plugins/printer/foodsoft_printer.gemspec b/plugins/printer/foodsoft_printer.gemspec index d0eea89a..cf249593 100644 --- a/plugins/printer/foodsoft_printer.gemspec +++ b/plugins/printer/foodsoft_printer.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Add a printer queue to foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency "deface", "~> 1.0" diff --git a/plugins/wiki/foodsoft_wiki.gemspec b/plugins/wiki/foodsoft_wiki.gemspec index 371872c5..07f0c182 100644 --- a/plugins/wiki/foodsoft_wiki.gemspec +++ b/plugins/wiki/foodsoft_wiki.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.description = "Adds a wiki to foodsoft." s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] + s.test_files = Dir["test/**/*"] s.add_dependency "rails" s.add_dependency 'wikicloth' diff --git a/spec/lib/bank_account_information_importer_spec.rb b/spec/lib/bank_account_information_importer_spec.rb index a5d32485..a98441d2 100644 --- a/spec/lib/bank_account_information_importer_spec.rb +++ b/spec/lib/bank_account_information_importer_spec.rb @@ -4,7 +4,8 @@ let(:bank_account) { create :bank_account } it 'empty content' do - content = '' + content = <<-JSON + JSON importer = BankAccountInformationImporter.new(bank_account) expect(importer.import!(content)).to be(nil)