From 55ced281810db995c7fc630f77fc3ac94993a7b0 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Sun, 5 Jun 2022 07:44:52 -0700 Subject: [PATCH] Update standard rules (#5360) * update standard rules and run standard:fix * Fix more standard errors * standardize --- .standard.yml | 8 ++--- examples/por.rb | 4 +-- myapp/Gemfile | 12 ++++---- myapp/Rakefile | 2 +- myapp/app/controllers/work_controller.rb | 28 ++++++++--------- myapp/app/mailers/user_mailer.rb | 2 +- myapp/app/models/post.rb | 2 +- myapp/app/workers/hard_worker.rb | 4 +-- myapp/bin/bundle | 4 +-- myapp/bin/rails | 10 +++--- myapp/bin/rake | 8 ++--- myapp/bin/setup | 36 ---------------------- myapp/config.ru | 2 +- myapp/config/application.rb | 14 ++++----- myapp/config/boot.rb | 4 +-- myapp/config/environment.rb | 2 +- myapp/config/environments/development.rb | 8 ++--- myapp/config/environments/production.rb | 12 ++++---- myapp/config/environments/test.rb | 6 ++-- myapp/config/initializers/secret_token.rb | 2 +- myapp/config/initializers/session_store.rb | 2 +- myapp/config/initializers/sidekiq.rb | 16 +++++----- myapp/config/routes.rb | 8 ++--- myapp/db/schema.rb | 2 -- myapp/script/rails | 6 ++-- myapp/simple.ru | 6 ++-- test/helper.rb | 2 +- test/test_actors.rb | 2 +- test/test_cli.rb | 2 +- test/test_csrf.rb | 14 ++++----- test/test_current_attributes.rb | 26 ++++++++-------- test/test_job.rb | 2 +- test/test_job_logger.rb | 12 ++++---- test/test_logger.rb | 24 +++++++-------- test/test_retry.rb | 6 ++-- test/test_scheduled.rb | 4 +-- test/test_systemd.rb | 6 ++-- test/test_testing_fake.rb | 2 +- test/test_web.rb | 2 +- test/test_web_helpers.rb | 12 ++++---- 40 files changed, 143 insertions(+), 183 deletions(-) delete mode 100755 myapp/bin/setup diff --git a/.standard.yml b/.standard.yml index 22990b4f7..9e9efc07b 100644 --- a/.standard.yml +++ b/.standard.yml @@ -2,14 +2,14 @@ ruby_version: 2.5.0 fix: true parallel: true ignore: - - test/**/* - - examples/**/* - - myapp/**/* - 'lib/sidekiq.rb': - Lint/InheritException - 'lib/sidekiq/extensions/**/*': - Style/MissingRespondToMissing - - 'lib/**/*': + - '**/*': - Lint/RescueException - Security/YAMLLoad - Style/GlobalVars + - 'test/test*.rb': + - Lint/ConstantDefinitionInBlock + diff --git a/examples/por.rb b/examples/por.rb index cbb8b510b..a89943ab4 100644 --- a/examples/por.rb +++ b/examples/por.rb @@ -1,4 +1,4 @@ -require 'sidekiq' +require "sidekiq" # Start up sidekiq via # ./bin/sidekiq -r ./examples/por.rb @@ -10,7 +10,7 @@ class PlainOldRuby include Sidekiq::Job - def perform(how_hard="super hard", how_long=1) + def perform(how_hard = "super hard", how_long = 1) sleep how_long puts "Workin' #{how_hard}" end diff --git a/myapp/Gemfile b/myapp/Gemfile index 0d289c2af..bdd1ffe3d 100644 --- a/myapp/Gemfile +++ b/myapp/Gemfile @@ -1,15 +1,15 @@ -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'sidekiq', :path => '..' -gem 'rails' -gem 'puma' +gem "sidekiq", path: ".." +gem "rails" +gem "puma" gem "redis-client" # Ubuntu required packages to install rails # apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev platforms :ruby do - gem 'sqlite3' + gem "sqlite3" end -gem 'after_commit_everywhere' \ No newline at end of file +gem "after_commit_everywhere" diff --git a/myapp/Rakefile b/myapp/Rakefile index e85f91391..9a5ea7383 100644 --- a/myapp/Rakefile +++ b/myapp/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative 'config/application' +require_relative "config/application" Rails.application.load_tasks diff --git a/myapp/app/controllers/work_controller.rb b/myapp/app/controllers/work_controller.rb index fcf1b4b3a..88f1139df 100644 --- a/myapp/app/controllers/work_controller.rb +++ b/myapp/app/controllers/work_controller.rb @@ -3,42 +3,42 @@ def index @count = rand(100) puts "Adding #{@count} jobs" @count.times do |x| - HardWorker.perform_async('bubba', 0.01, x) + HardWorker.perform_async("bubba", 0.01, x) end end def email UserMailer.delay_for(30.seconds).greetings(Time.now) - render :plain => 'enqueued' + render plain: "enqueued" end def bulk - Sidekiq::Client.push_bulk('class' => HardWorker, - 'args' => [['bob', 1, 1], ['mike', 1, 2]]) - render :plain => 'enbulked' + Sidekiq::Client.push_bulk("class" => HardWorker, + "args" => [["bob", 1, 1], ["mike", 1, 2]]) + render plain: "enbulked" end def long 50.times do |x| - HardWorker.perform_async('bob', 15, x) + HardWorker.perform_async("bob", 15, x) end - render :plain => 'enqueued' + render plain: "enqueued" end def crash - HardWorker.perform_async('crash', 1, Time.now.to_f) - render :plain => 'enqueued' + HardWorker.perform_async("crash", 1, Time.now.to_f) + render plain: "enqueued" end def delayed_post p = Post.first - unless p - p = Post.create!(:title => "Title!", :body => 'Body!') - p2 = Post.create!(:title => "Other!", :body => 'Second Body!') - else + if p p2 = Post.second + else + p = Post.create!(title: "Title!", body: "Body!") + p2 = Post.create!(title: "Other!", body: "Second Body!") end p.delay.long_method(p2) - render :plain => 'enqueued' + render plain: "enqueued" end end diff --git a/myapp/app/mailers/user_mailer.rb b/myapp/app/mailers/user_mailer.rb index becd58e90..b4ed6e9aa 100644 --- a/myapp/app/mailers/user_mailer.rb +++ b/myapp/app/mailers/user_mailer.rb @@ -4,6 +4,6 @@ class UserMailer < ActionMailer::Base def greetings(now) @now = now @hostname = `hostname`.strip - mail(:to => 'mperham@gmail.com', :subject => 'Ahoy Matey!') + mail(to: "mperham@gmail.com", subject: "Ahoy Matey!") end end diff --git a/myapp/app/models/post.rb b/myapp/app/models/post.rb index 490d0deec..3e554e5bb 100644 --- a/myapp/app/models/post.rb +++ b/myapp/app/models/post.rb @@ -1,6 +1,6 @@ class Post < ActiveRecord::Base def long_method(other_post) - puts "Running long method with #{self.id} and #{other_post.id}" + puts "Running long method with #{id} and #{other_post.id}" end def self.testing diff --git a/myapp/app/workers/hard_worker.rb b/myapp/app/workers/hard_worker.rb index 83409cf96..24eec4788 100644 --- a/myapp/app/workers/hard_worker.rb +++ b/myapp/app/workers/hard_worker.rb @@ -1,9 +1,9 @@ class HardWorker include Sidekiq::Worker - sidekiq_options :backtrace => 5 + sidekiq_options backtrace: 5 def perform(name, count, salt) - raise name if name == 'crash' + raise name if name == "crash" logger.info Time.now sleep count end diff --git a/myapp/bin/bundle b/myapp/bin/bundle index f19acf5b5..67efc37fb 100755 --- a/myapp/bin/bundle +++ b/myapp/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -load Gem.bin_path('bundler', 'bundle') +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +load Gem.bin_path("bundler", "bundle") diff --git a/myapp/bin/rails b/myapp/bin/rails index 5badb2fde..40d2d5e18 100755 --- a/myapp/bin/rails +++ b/myapp/bin/rails @@ -1,9 +1,9 @@ #!/usr/bin/env ruby begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError => e - raise unless e.message.include?('spring') + raise unless e.message.include?("spring") end -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/myapp/bin/rake b/myapp/bin/rake index d87d5f578..3df5805be 100755 --- a/myapp/bin/rake +++ b/myapp/bin/rake @@ -1,9 +1,9 @@ #!/usr/bin/env ruby begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError => e - raise unless e.message.include?('spring') + raise unless e.message.include?("spring") end -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/myapp/bin/setup b/myapp/bin/setup deleted file mode 100755 index 94fd4d797..000000000 --- a/myapp/bin/setup +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env ruby -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = File.expand_path('..', __dir__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a starting point to setup your application. - # Add necessary setup steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # Install JavaScript dependencies if using Yarn - # system('bin/yarn') - - # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' - # end - - puts "\n== Preparing database ==" - system! 'bin/rails db:setup' - - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' - - puts "\n== Restarting application server ==" - system! 'bin/rails restart' -end diff --git a/myapp/config.ru b/myapp/config.ru index f7ba0b527..441e6ff0c 100644 --- a/myapp/config.ru +++ b/myapp/config.ru @@ -1,5 +1,5 @@ # This file is used by Rack-based servers to start the application. -require_relative 'config/environment' +require_relative "config/environment" run Rails.application diff --git a/myapp/config/application.rb b/myapp/config/application.rb index d2e6429b6..423451a1c 100644 --- a/myapp/config/application.rb +++ b/myapp/config/application.rb @@ -1,18 +1,16 @@ -require_relative 'boot' +require_relative "boot" -require 'rails' -%w( +require "rails" +%w[ active_record/railtie action_controller/railtie action_view/railtie action_mailer/railtie active_job/railtie sprockets/railtie -).each do |railtie| - begin - require railtie - rescue LoadError - end +].each do |railtie| + require railtie +rescue LoadError end # Require the gems listed in Gemfile, including any gems diff --git a/myapp/config/boot.rb b/myapp/config/boot.rb index 30f5120df..282011619 100644 --- a/myapp/config/boot.rb +++ b/myapp/config/boot.rb @@ -1,3 +1,3 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -require 'bundler/setup' # Set up gems listed in the Gemfile. +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/myapp/config/environment.rb b/myapp/config/environment.rb index 426333bb4..cac531577 100644 --- a/myapp/config/environment.rb +++ b/myapp/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/myapp/config/environments/development.rb b/myapp/config/environments/development.rb index 9a842b566..6868ba64d 100644 --- a/myapp/config/environments/development.rb +++ b/myapp/config/environments/development.rb @@ -14,12 +14,12 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -28,7 +28,7 @@ end # Store uploaded files on the local file system (see config/storage.yml for options) - #config.active_storage.service = :local + # config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -57,5 +57,5 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. - #config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/myapp/config/environments/production.rb b/myapp/config/environments/production.rb index 2a20538b2..72d93f596 100644 --- a/myapp/config/environments/production.rb +++ b/myapp/config/environments/production.rb @@ -11,7 +11,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] @@ -20,7 +20,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -39,7 +39,7 @@ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options) - #config.active_storage.service = :local + # config.active_storage.service = :local # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil @@ -54,7 +54,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -84,9 +84,9 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/myapp/config/environments/test.rb b/myapp/config/environments/test.rb index ccf4335d8..9cf6011b4 100644 --- a/myapp/config/environments/test.rb +++ b/myapp/config/environments/test.rb @@ -15,11 +15,11 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. @@ -29,7 +29,7 @@ config.action_controller.allow_forgery_protection = false # Store uploaded files on the local file system in a temporary directory - #config.active_storage.service = :test + # config.active_storage.service = :test config.action_mailer.perform_caching = false diff --git a/myapp/config/initializers/secret_token.rb b/myapp/config/initializers/secret_token.rb index 007d2f860..615f54b7f 100644 --- a/myapp/config/initializers/secret_token.rb +++ b/myapp/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Myapp::Application.config.secret_token = 'bdd335500c81ba1f279f9dd8198d1f334445d0193168ed73c1282502180dca27e3e102ec345e99b2acac6a63f7fe29da69c60cc9e76e8da34fb5d4989db24cd8' +Myapp::Application.config.secret_token = "bdd335500c81ba1f279f9dd8198d1f334445d0193168ed73c1282502180dca27e3e102ec345e99b2acac6a63f7fe29da69c60cc9e76e8da34fb5d4989db24cd8" diff --git a/myapp/config/initializers/session_store.rb b/myapp/config/initializers/session_store.rb index bf64a2963..a2994e04d 100644 --- a/myapp/config/initializers/session_store.rb +++ b/myapp/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_myapp_session' +Rails.application.config.session_store :cookie_store, key: "_myapp_session" diff --git a/myapp/config/initializers/sidekiq.rb b/myapp/config/initializers/sidekiq.rb index 282ad8730..472cb8489 100644 --- a/myapp/config/initializers/sidekiq.rb +++ b/myapp/config/initializers/sidekiq.rb @@ -1,18 +1,18 @@ Sidekiq.configure_client do |config| - config.redis = { :size => 2 } + config.redis = {size: 2} end Sidekiq.configure_server do |config| - config.on(:startup) { } - config.on(:quiet) { } + config.on(:startup) {} + config.on(:quiet) {} config.on(:shutdown) do - #result = RubyProf.stop + # result = RubyProf.stop ## Write the results to a file ## Requires railsexpress patched MRI build # brew install qcachegrind - #File.open("callgrind.profile", "w") do |f| - #RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1) - #end + # File.open("callgrind.profile", "w") do |f| + # RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1) + # end end end @@ -47,4 +47,4 @@ class Current < ActiveSupport::CurrentAttributes require "sidekiq/middleware/current_attributes" Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton -# Sidekiq.transactional_push! \ No newline at end of file +# Sidekiq.transactional_push! diff --git a/myapp/config/routes.rb b/myapp/config/routes.rb index c32e3f26f..4345501ba 100644 --- a/myapp/config/routes.rb +++ b/myapp/config/routes.rb @@ -1,11 +1,11 @@ # turns off browser asset caching so we can test CSS changes quickly -ENV['SIDEKIQ_WEB_TESTING'] = '1' +ENV["SIDEKIQ_WEB_TESTING"] = "1" -require 'sidekiq/web' -Sidekiq::Web.app_url = '/' +require "sidekiq/web" +Sidekiq::Web.app_url = "/" Rails.application.routes.draw do - mount Sidekiq::Web => '/sidekiq' + mount Sidekiq::Web => "/sidekiq" get "work" => "work#index" get "work/email" => "work#email" get "work/post" => "work#delayed_post" diff --git a/myapp/db/schema.rb b/myapp/db/schema.rb index 5c5c5cedc..88d5c9410 100644 --- a/myapp/db/schema.rb +++ b/myapp/db/schema.rb @@ -11,12 +11,10 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2012_01_23_214055) do - create_table "posts", force: :cascade do |t| t.string "title" t.string "body" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end - end diff --git a/myapp/script/rails b/myapp/script/rails index f8da2cffd..9a5a81dcf 100755 --- a/myapp/script/rails +++ b/myapp/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) -require 'rails/commands' +APP_PATH = File.expand_path("../../config/application", __FILE__) +require File.expand_path("../../config/boot", __FILE__) +require "rails/commands" diff --git a/myapp/simple.ru b/myapp/simple.ru index 8e0074711..83af458f8 100644 --- a/myapp/simple.ru +++ b/myapp/simple.ru @@ -1,14 +1,14 @@ # Easiest way to run Sidekiq::Web. # Run with "bundle exec rackup simple.ru" -require 'sidekiq/web' +require "sidekiq/web" # A Web process always runs as client, no need to configure server Sidekiq.configure_client do |config| - config.redis = { url: 'redis://localhost:6379/0', size: 1 } + config.redis = {url: "redis://localhost:6379/0", size: 1} end -Sidekiq::Client.push('class' => "HardWorker", 'args' => []) +Sidekiq::Client.push("class" => "HardWorker", "args" => []) # In a multi-process deployment, all Web UI instances should share # this secret key so they can all decode the encrypted browser cookies diff --git a/test/helper.rb b/test/helper.rb index 0570502ea..5068dd161 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -28,7 +28,7 @@ ENV["REDIS_URL"] ||= "redis://localhost/15" -Sidekiq.logger = ::Logger.new(STDOUT) +Sidekiq.logger = ::Logger.new($stdout) Sidekiq.logger.level = Logger::ERROR if ENV["SIDEKIQ_REDIS_CLIENT"] diff --git a/test/test_actors.rb b/test/test_actors.rb index 59f1aeaba..13f807530 100644 --- a/test/test_actors.rb +++ b/test/test_actors.rb @@ -66,7 +66,7 @@ def result(pr, ex) end end - def await(timeout=0.5) + def await(timeout = 0.5) @mutex.synchronize do yield @cond.wait(@mutex, timeout) diff --git a/test/test_cli.rb b/test/test_cli.rb index 215c158e1..0bb12a5e3 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -20,7 +20,7 @@ end subject do - Sidekiq::CLI.new.tap {|c| c.config = config } + Sidekiq::CLI.new.tap { |c| c.config = config } end def logdev diff --git a/test/test_csrf.rb b/test/test_csrf.rb index 5fe2df4e5..6f456ce18 100644 --- a/test/test_csrf.rb +++ b/test/test_csrf.rb @@ -3,7 +3,7 @@ require_relative "./helper" require "sidekiq/web/csrf_protection" -describe 'Csrf' do +describe "Csrf" do def session @session ||= {} end @@ -24,7 +24,7 @@ def call(env, &block) Sidekiq::Web::CsrfProtection.new(block).call(env) end - it 'get' do + it "get" do ok = [200, {}, ["OK"]] first = 1 second = 1 @@ -48,7 +48,7 @@ def call(env, &block) refute_equal first, second end - it 'bad post' do + it "bad post" do result = call(env(:post)) do raise "Shouldnt be called" end @@ -60,7 +60,7 @@ def call(env, &block) assert_match(/attack prevented/, @logio.string) end - it 'succeeds with good token' do + it "succeeds with good token" do # Make a GET to set up the session with a good token goodtoken = call(env) do |envy| envy[:csrf_token] @@ -76,7 +76,7 @@ def call(env, &block) assert_equal ["OK"], result[2] end - it 'fails with bad token' do + it "fails with bad token" do # Make a POST with a known bad token result = call(env(:post, "authenticity_token" => "N0QRBD34tU61d7fi+0ZaF/35JLW/9K+8kk8dc1TZoK/0pTl7GIHap5gy7BWGsoKlzbMLRp1yaDpCDFwTJtxWAg==")) do raise "shouldnt be called" @@ -86,7 +86,7 @@ def call(env, &block) assert_equal ["Forbidden"], result[2] end - it 'empty session post' do + it "empty session post" do # Make a GET to set up the session with a good token goodtoken = call(env) do |envy| envy[:csrf_token] @@ -102,7 +102,7 @@ def call(env, &block) assert_equal ["Forbidden"], result[2] end - it 'empty csrf session post' do + it "empty csrf session post" do # Make a GET to set up the session with a good token goodtoken = call(env) do |envy| envy[:csrf_token] diff --git a/test/test_current_attributes.rb b/test/test_current_attributes.rb index bbefa8d43..4489109b7 100644 --- a/test/test_current_attributes.rb +++ b/test/test_current_attributes.rb @@ -10,8 +10,8 @@ class Current < ActiveSupport::CurrentAttributes end end -describe 'Current attributes' do - it 'saves' do +describe "Current attributes" do + it "saves" do cm = Sidekiq::CurrentAttributes::Save.new(Myapp::Current) job = {} with_context(:user_id, 123) do @@ -21,7 +21,7 @@ class Current < ActiveSupport::CurrentAttributes end end - it 'loads' do + it "loads" do cm = Sidekiq::CurrentAttributes::Load.new(Myapp::Current) job = {"cattr" => {"user_id" => 123}} @@ -32,7 +32,7 @@ class Current < ActiveSupport::CurrentAttributes # the Rails reloader is responsible for reseting Current after every unit of work end - it 'persists' do + it "persists" do Sidekiq::CurrentAttributes.persist(Myapp::Current) job_hash = {} with_context(:user_id, 16) do @@ -41,15 +41,15 @@ class Current < ActiveSupport::CurrentAttributes end end - # assert_nil Myapp::Current.user_id - # Sidekiq.server_middleware.invoke(nil, job_hash, nil) do - # assert_equal 16, job_hash["cattr"][:user_id] - # assert_equal 16, Myapp::Current.user_id - # end - # assert_nil Myapp::Current.user_id - # ensure - # Sidekiq.client_middleware.clear - # Sidekiq.server_middleware.clear + # assert_nil Myapp::Current.user_id + # Sidekiq.server_middleware.invoke(nil, job_hash, nil) do + # assert_equal 16, job_hash["cattr"][:user_id] + # assert_equal 16, Myapp::Current.user_id + # end + # assert_nil Myapp::Current.user_id + # ensure + # Sidekiq.client_middleware.clear + # Sidekiq.server_middleware.clear end private diff --git a/test/test_job.rb b/test/test_job.rb index 2c3796c56..e8e5c2d55 100644 --- a/test/test_job.rb +++ b/test/test_job.rb @@ -9,7 +9,7 @@ class SomeJob include Sidekiq::Job end - it 'adds job to queue' do + it "adds job to queue" do SomeJob.perform_async assert_equal "SomeJob", Sidekiq::Queue.new.first.klass end diff --git a/test/test_job_logger.rb b/test/test_job_logger.rb index 6fbf292ba..34a8ef461 100644 --- a/test/test_job_logger.rb +++ b/test/test_job_logger.rb @@ -3,7 +3,7 @@ require_relative "helper" require "sidekiq/job_logger" -describe 'Job logger' do +describe "Job logger" do before do @old = Sidekiq.logger @output = StringIO.new @@ -20,7 +20,7 @@ Sidekiq.logger = @old end - it 'tests pretty output' do + it "tests pretty output" do jl = Sidekiq::JobLogger.new(@logger) # pretty @@ -41,7 +41,7 @@ assert_match(/#{Time.now.utc.to_date}.+Z pid=#{$$} tid=#{p.tid} .+INFO: done/, b) end - it 'tests json output' do + it "tests json output" do # json @logger.formatter = Sidekiq::Logger::Formatters::JSON.new jl = Sidekiq::JobLogger.new(@logger) @@ -60,7 +60,7 @@ assert_equal(["bid", "class", "jid", "tags"], keys) end - it 'tests custom log level' do + it "tests custom log level" do jl = Sidekiq::JobLogger.new(@logger) job = {"class" => "FooWorker", "log_level" => "debug"} @@ -79,7 +79,7 @@ assert_match(/INFO: done/, c) end - it 'tests custom log level uses default log level for invalid value' do + it "tests custom log level uses default log level for invalid value" do jl = Sidekiq::JobLogger.new(@logger) job = {"class" => "FooWorker", "log_level" => "non_existent"} @@ -94,7 +94,7 @@ assert_match(/WARN: Invalid log level/, log_level_warning) end - it 'tests custom logger with non numeric levels' do + it "tests custom logger with non numeric levels" do logger_class = Class.new(Logger) do def level :nonsense diff --git a/test/test_logger.rb b/test/test_logger.rb index 6205caf5b..2fa31a535 100644 --- a/test/test_logger.rb +++ b/test/test_logger.rb @@ -3,7 +3,7 @@ require_relative "helper" require "sidekiq/logger" -describe 'logger' do +describe "logger" do before do @output = StringIO.new @logger = Sidekiq::Logger.new(@output) @@ -19,24 +19,24 @@ Thread.current[:sidekiq_tid] = nil end - it 'tests default logger format' do + it "tests default logger format" do assert_kind_of Sidekiq::Logger::Formatters::Pretty, Sidekiq::Logger.new(@output).formatter end - it 'tests heroku logger formatter' do + it "tests heroku logger formatter" do ENV["DYNO"] = "dyno identifier" assert_kind_of Sidekiq::Logger::Formatters::WithoutTimestamp, Sidekiq::Logger.new(@output).formatter ensure ENV["DYNO"] = nil end - it 'tests json logger formatter' do + it "tests json logger formatter" do Sidekiq.log_formatter = Sidekiq::Logger::Formatters::JSON.new assert_kind_of Sidekiq::Logger::Formatters::JSON, Sidekiq::Logger.new(@output).formatter end - it 'tests with context' do + it "tests with context" do subject = Sidekiq::Context assert_equal({}, subject.current) @@ -47,9 +47,9 @@ assert_equal({}, subject.current) end - it 'tests with overlapping context' do + it "tests with overlapping context" do subject = Sidekiq::Context - subject.current.merge!({foo: "bar"}) + subject.current[:foo] = "bar" assert_equal({foo: "bar"}, subject.current) subject.with(foo: "bingo") do @@ -59,7 +59,7 @@ assert_equal({foo: "bar"}, subject.current) end - it 'tests nested contexts' do + it "tests nested contexts" do subject = Sidekiq::Context assert_equal({}, subject.current) @@ -76,7 +76,7 @@ assert_equal({}, subject.current) end - it 'tests formatted output' do + it "tests formatted output" do @logger.info("hello world") assert_match(/INFO: hello world/, @output.string) reset(@output) @@ -96,7 +96,7 @@ end end - it 'makes sure json output is parseable' do + it "makes sure json output is parseable" do @logger.formatter = Sidekiq::Logger::Formatters::JSON.new @logger.debug("boom") @@ -118,7 +118,7 @@ assert_equal "INFO", hash["lvl"] end - it 'tests forwards logger kwards' do + it "tests forwards logger kwards" do assert_silent do logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO) @@ -126,7 +126,7 @@ end end - it 'tests log level query methods' do + it "tests log level query methods" do logger = Sidekiq::Logger.new("/dev/null", level: Logger::INFO) refute_predicate logger, :debug? diff --git a/test/test_retry.rb b/test/test_retry.rb index 568afe956..22d95d8bd 100644 --- a/test/test_retry.rb +++ b/test/test_retry.rb @@ -123,7 +123,7 @@ def job c = nil assert_raises RuntimeError do handler.local(worker, jobstr("backtrace" => true), "default") do - c = caller(0); raise "kerblammo!" + (c = caller(0)) && raise("kerblammo!") end end @@ -136,13 +136,13 @@ def job c = nil assert_raises RuntimeError do handler.local(worker, jobstr("backtrace" => 3), "default") do - c = caller(0)[0...3]; raise "kerblammo!" + c = caller(0)[0...3] + raise "kerblammo!" end end job = Sidekiq::RetrySet.new.first assert job.error_backtrace - assert_equal c, job.error_backtrace assert_equal 3, c.size end diff --git a/test/test_scheduled.rb b/test/test_scheduled.rb index 203b39ecf..e649255d9 100644 --- a/test/test_scheduled.rb +++ b/test/test_scheduled.rb @@ -106,11 +106,11 @@ def call(worker_class, job, queue, r) end def with_sidekiq_option(name, value) - _original, Sidekiq[name] = Sidekiq[name], value + original, Sidekiq[name] = Sidekiq[name], value begin yield ensure - Sidekiq[name] = _original + Sidekiq[name] = original end end diff --git a/test/test_systemd.rb b/test/test_systemd.rb index 698825989..f4fdd9bfc 100644 --- a/test/test_systemd.rb +++ b/test/test_systemd.rb @@ -4,7 +4,7 @@ require "sidekiq/sd_notify" require "sidekiq/systemd" -describe 'Systemd' do +describe "Systemd" do before do ::Dir::Tmpname.create("sidekiq_socket") do |sockaddr| @sockaddr = sockaddr @@ -16,7 +16,7 @@ end after do - @socket.close if @socket + @socket&.close File.unlink(@sockaddr) if @sockaddr @socket = nil @sockaddr = nil @@ -26,7 +26,7 @@ def socket_message @socket.recvfrom(10)[0] end - it 'notifies' do + it "notifies" do count = Sidekiq::SdNotify.ready assert_equal(socket_message, "READY=1") assert_equal(ENV["NOTIFY_SOCKET"], @sockaddr) diff --git a/test/test_testing_fake.rb b/test/test_testing_fake.rb index 2d480d92a..7a2326355 100644 --- a/test/test_testing_fake.rb +++ b/test/test_testing_fake.rb @@ -250,7 +250,7 @@ def perform assert_equal 1, SecondWorker.count end - it 'clears the jobs of workers having their queue name defined as a symbol' do + it "clears the jobs of workers having their queue name defined as a symbol" do assert_equal Symbol, AltQueueWorker.sidekiq_options["queue"].class AltQueueWorker.perform_async diff --git a/test/test_web.rb b/test/test_web.rb index f426c769b..92d12513b 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -428,7 +428,7 @@ def perform(a, b) it "escape job args and error messages" do # on /retries page - params = add_xss_retry + add_xss_retry get "/retries" assert_equal 200, last_response.status assert_match(/FailWorker/, last_response.body) diff --git a/test/test_web_helpers.rb b/test/test_web_helpers.rb index 2625cfdbd..18c23d049 100644 --- a/test/test_web_helpers.rb +++ b/test/test_web_helpers.rb @@ -3,7 +3,7 @@ require_relative "helper" require "sidekiq/web" -describe 'Web helpers' do +describe "Web helpers" do class Helpers include Sidekiq::WebHelpers @@ -33,7 +33,7 @@ def default end end - it 'tests locale determination' do + it "tests locale determination" do obj = Helpers.new assert_equal "en", obj.locale @@ -89,7 +89,7 @@ def default assert_equal "en", obj.locale end - it 'tests available locales' do + it "tests available locales" do obj = Helpers.new expected = %w[ ar cs da de el en es fa fr he hi it ja @@ -99,7 +99,7 @@ def default assert_equal expected, obj.available_locales.sort end - it 'tests displaying of illegal args' do + it "tests displaying of illegal args" do o = Helpers.new s = o.display_args([1, 2, 3]) assert_equal "1, 2, 3", s @@ -111,12 +111,12 @@ def default assert_equal "Invalid job payload, args is nil", s end - it 'query string escapes bad query input' do + it "query string escapes bad query input" do obj = Helpers.new assert_equal "page=B%3CH", obj.to_query_string("page" => "B