Rubocop: Enable and fix Style/OptionHash (#9430)

* Enable and fix Style/OptionHash

* Add 10 seconds default timeout to DB statements
This commit is contained in:
rhymes 2020-07-25 10:41:21 +02:00 committed by GitHub
parent 95be4c6308
commit 0b4ad49cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 10 deletions

View file

@ -379,9 +379,9 @@ Style/ClassAndModuleChildren:
Enabled: true
SafeAutoCorrect: true
# Style/OptionHash:
# Description: "Don't use option hashes when you can use keyword arguments."
# Enabled: false
Style/OptionHash:
Description: "Don't use option hashes when you can use keyword arguments."
Enabled: true
Style/Next:
Description: 'Use `next` to skip iteration instead of a condition at the end.'

View file

@ -8,13 +8,20 @@ module FastlyHeaders
# Surrogate-Control is stripped at the cache, Cache-Control persists (in case of other caches in front of fastly)
# Defaults are:
# Cache-Control: 'public, no-cache'
# Surrogate-Control: 'max-age: 86400' - 30 days in seconds
# Surrogate-Control: 'max-age: 86400' - 1 day in seconds
# custom config example:
# {cache_control: 'public, no-cache, maxage=xyz', surrogate_control: 'max-age: 100'}
def set_cache_control_headers(max_age = 1.day.to_i, opts = {})
def set_cache_control_headers(
max_age = 1.day.to_i, cache_control: "public, no-cache",
surrogate_control: nil, stale_while_revalidate: nil, stale_if_error: 26_400
)
request.session_options[:skip] = true # no cookies
response.headers["Cache-Control"] = opts[:cache_control] || "public, no-cache"
response.headers["Surrogate-Control"] = opts[:surrogate_control] || build_surrogate_control(max_age, opts)
response.headers["Cache-Control"] = cache_control
response.headers["Surrogate-Control"] = surrogate_control.presence || build_surrogate_control(
max_age, stale_while_revalidate: stale_while_revalidate, stale_if_error: stale_if_error
)
end
# Sets Surrogate-Key HTTP header with one or more keys strips session data
@ -26,10 +33,8 @@ module FastlyHeaders
private
def build_surrogate_control(max_age, opts)
def build_surrogate_control(max_age, stale_while_revalidate: nil, stale_if_error: 26_400)
surrogate_control = "max-age=#{max_age}"
stale_while_revalidate = opts[:stale_while_revalidate]
stale_if_error = opts[:stale_if_error] || 26_400
surrogate_control += ", stale-while-revalidate=#{stale_while_revalidate}" if stale_while_revalidate
surrogate_control += ", stale-if-error=#{stale_if_error}" if stale_if_error

View file

@ -1,3 +1,4 @@
# rubocop:disable Style/OptionHash
module Authentication
# These are meant to be called from the specific providers
module Paths
@ -21,3 +22,4 @@ module Authentication
end
end
end
# rubocop:enable Style/OptionHash

View file

@ -42,12 +42,14 @@ module Authentication
SETTINGS_URL
end
# rubocop:disable Style/OptionHash
def self.sign_in_path(params = {})
::Authentication::Paths.sign_in_path(
provider_name,
params,
)
end
# rubocop:enable Style/OptionHash
protected

View file

@ -49,9 +49,11 @@ module Authentication
raise SubclassResponsibility
end
# rubocop:disable Style/OptionHash
def self.authentication_path(params = {})
::Authentication::Paths.authentication_path(provider_name, params)
end
# rubocop:enable Style/OptionHash
def self.sign_in_path(_params = {})
raise SubclassResponsibility

View file

@ -47,6 +47,7 @@ module Authentication
SETTINGS_URL
end
# rubocop:disable Style/OptionHash
def self.sign_in_path(params = {})
# see https://github.com/arunagw/omniauth-twitter#authentication-options
mandatory_params = { secure_image_url: true }
@ -56,6 +57,7 @@ module Authentication
params.merge(mandatory_params),
)
end
# rubocop:enable Style/OptionHash
protected

View file

@ -1,7 +1,9 @@
class NoOpHTTPClient
# rubocop:disable Style/OptionHash
def self.post(uri, params = {})
# bonus, you could log or observe posted params here
end
# rubocop:enable Style/OptionHash
end
def create_normal_notifier

View file

@ -11,6 +11,7 @@ RSpec.describe "CommentsCreate", type: :request do
sign_in user
end
# rubocop:disable Style/OptionHash
def comment_params(params = {})
{
comment: {
@ -20,6 +21,7 @@ RSpec.describe "CommentsCreate", type: :request do
}.merge(params)
}
end
# rubocop:enable Style/OptionHash
it "creates a comment with proper params" do
expect do

View file

@ -1,6 +1,7 @@
module Warden
module Test
module Helpers
# rubocop:disable Style/OptionHash
# Override Warden Test Helper login and logout methods with on_request
# instead of on_next_request in order to prevent the race condition where
# we make a request before the user is finished authenticating
@ -11,6 +12,7 @@ module Warden
proxy.set_user(user, opts)
end
end
# rubocop:enable Style/OptionHash
def logout(*scopes)
Warden::Manager.on_request do |proxy|