Add spaces around method arguments when setting default values

Closes #5288
This commit is contained in:
mune 2020-08-31 20:46:43 +09:00 committed by Carlos Antonio da Silva
parent 97aa37bb50
commit eed641d2be
23 changed files with 47 additions and 47 deletions

View File

@ -4,26 +4,26 @@ if defined?(ActionMailer)
class Devise::Mailer < Devise.parent_mailer.constantize
include Devise::Mailers::Helpers
def confirmation_instructions(record, token, opts={})
def confirmation_instructions(record, token, opts = {})
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
def reset_password_instructions(record, token, opts={})
def reset_password_instructions(record, token, opts = {})
@token = token
devise_mail(record, :reset_password_instructions, opts)
end
def unlock_instructions(record, token, opts={})
def unlock_instructions(record, token, opts = {})
@token = token
devise_mail(record, :unlock_instructions, opts)
end
def email_changed(record, opts={})
def email_changed(record, opts = {})
devise_mail(record, :email_changed, opts)
end
def password_change(record, opts={})
def password_change(record, opts = {})
devise_mail(record, :password_change, opts)
end
end

View File

@ -36,11 +36,11 @@ module Devise
# before_action ->{ authenticate_blogger! :admin } # Redirects to the admin login page
# current_blogger :user # Preferably returns a User if one is signed in
#
def devise_group(group_name, opts={})
def devise_group(group_name, opts = {})
mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{group_name}!(favorite=nil, opts={})
def authenticate_#{group_name}!(favorite = nil, opts = {})
unless #{group_name}_signed_in?
mappings = #{mappings}
mappings.unshift mappings.delete(favorite.to_sym) if favorite
@ -57,7 +57,7 @@ module Devise
end
end
def current_#{group_name}(favorite=nil)
def current_#{group_name}(favorite = nil)
mappings = #{mappings}
mappings.unshift mappings.delete(favorite.to_sym) if favorite
mappings.each do |mapping|
@ -113,7 +113,7 @@ module Devise
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts={})
def authenticate_#{mapping}!(opts = {})
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end

View File

@ -10,7 +10,7 @@ module Devise
# cause exceptions to be thrown from this method; if you simply want to check
# if a scope has already previously been authenticated without running
# authentication hooks, you can directly call `warden.authenticated?(scope: scope)`
def signed_in?(scope=nil)
def signed_in?(scope = nil)
[scope || Devise.mappings.keys].flatten.any? do |_scope|
warden.authenticate?(scope: _scope)
end
@ -77,7 +77,7 @@ module Devise
# sign_out :user # sign_out(scope)
# sign_out @user # sign_out(resource)
#
def sign_out(resource_or_scope=nil)
def sign_out(resource_or_scope = nil)
return sign_out_all_scopes unless resource_or_scope
scope = Devise::Mapping.find_scope!(resource_or_scope)
user = warden.user(scope: scope, run_callbacks: false) # If there is no user
@ -92,7 +92,7 @@ module Devise
# Sign out all active users or scopes. This helper is useful for signing out all roles
# in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout
# and false if there was no user logged in on all scopes.
def sign_out_all_scopes(lock=true)
def sign_out_all_scopes(lock = true)
users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
warden.logout

View File

@ -34,7 +34,7 @@ module Devise
end
end
def self.generate_helpers!(routes=nil)
def self.generate_helpers!(routes = nil)
routes ||= begin
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
Devise::URL_HELPERS.slice(*mappings)

View File

@ -46,7 +46,7 @@ module Devise
raise "Could not find a valid mapping for #{obj.inspect}"
end
def self.find_by_path!(path, path_type=:fullpath)
def self.find_by_path!(path, path_type = :fullpath)
Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) }
raise "Could not find a valid mapping for path #{path.inspect}"
end

View File

@ -276,17 +276,17 @@ module Devise
find_first_by_auth_conditions(tainted_conditions)
end
def find_first_by_auth_conditions(tainted_conditions, opts={})
def find_first_by_auth_conditions(tainted_conditions, opts = {})
to_adapter.find_first(devise_parameter_filter.filter(tainted_conditions).merge(opts))
end
# Find or initialize a record setting an error if it can't be found.
def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:
def find_or_initialize_with_error_by(attribute, value, error = :invalid) #:nodoc:
find_or_initialize_with_errors([attribute], { attribute => value }, error)
end
# Find or initialize a record with group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc:
attributes.try(:permit!)
attributes = attributes.to_h.with_indifferent_access
.slice(*required_attributes)

View File

@ -76,7 +76,7 @@ module Devise
# Confirm a user by setting it's confirmed_at to actual time. If the user
# is already confirmed, add an error to email field. If the user is invalid
# add errors
def confirm(args={})
def confirm(args = {})
pending_any_confirmation do
if confirmation_period_expired?
self.errors.add(:email, :confirmation_period_expired,
@ -334,7 +334,7 @@ module Devise
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
# field. If no user is found, returns a new user with an email not found error.
# Options must contain the user email
def send_confirmation_instructions(attributes={})
def send_confirmation_instructions(attributes = {})
confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
unless confirmable.try(:persisted?)
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)

View File

@ -168,7 +168,7 @@ module Devise
# unlock instructions to it. If not user is found, returns a new user
# with an email not found error.
# Options must contain the user's unlock keys
def send_unlock_instructions(attributes={})
def send_unlock_instructions(attributes = {})
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_instructions if lockable.persisted?
lockable

View File

@ -131,7 +131,7 @@ module Devise
# password instructions to it. If user is not found, returns a new user
# with an email not found error.
# Attributes must contain the user's email
def send_reset_password_instructions(attributes={})
def send_reset_password_instructions(attributes = {})
recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
recoverable.send_reset_password_instructions if recoverable.persisted?
recoverable
@ -142,7 +142,7 @@ module Devise
# try saving the record. If not user is found, returns a new user
# containing an error in reset_password_token attribute.
# Attributes must contain reset_password_token, password and confirmation
def reset_password_by_token(attributes={})
def reset_password_by_token(attributes = {})
original_token = attributes[:reset_password_token]
reset_password_token = Devise.token_generator.digest(self, :reset_password_token, original_token)

View File

@ -287,7 +287,7 @@ module ActionDispatch::Routing
# root to: "admin/dashboard#show", as: :user_root
# end
#
def authenticate(scope=nil, block=nil)
def authenticate(scope = nil, block = nil)
constraints_for(:authenticate!, scope, block) do
yield
end
@ -311,7 +311,7 @@ module ActionDispatch::Routing
#
# root to: 'landing#show'
#
def authenticated(scope=nil, block=nil)
def authenticated(scope = nil, block = nil)
constraints_for(:authenticate?, scope, block) do
yield
end
@ -328,7 +328,7 @@ module ActionDispatch::Routing
#
# root to: 'dashboard#show'
#
def unauthenticated(scope=nil)
def unauthenticated(scope = nil)
constraint = lambda do |request|
not request.env["warden"].authenticate? scope: scope
end
@ -474,7 +474,7 @@ ERROR
@scope = current_scope
end
def constraints_for(method_to_apply, scope=nil, block=nil)
def constraints_for(method_to_apply, scope = nil, block = nil)
constraint = lambda do |request|
request.env['warden'].send(method_to_apply, scope: scope) &&
(block.nil? || block.call(request.env["warden"].user(scope)))

View File

@ -5,7 +5,7 @@ require 'test_helper'
class RoutesTest < Devise::ControllerTestCase
tests ApplicationController
def assert_path_and_url(name, prepend_path=nil)
def assert_path_and_url(name, prepend_path = nil)
@request.path = '/users/session'
prepend_path = "#{prepend_path}_" if prepend_path

View File

@ -73,7 +73,7 @@ class FailureTest < ActiveSupport::TestCase
instance_eval(&block)
end
def call_failure(env_params={})
def call_failure(env_params = {})
env = {
'REQUEST_URI' => 'http://test.host/',
'HTTP_HOST' => 'test.host',

View File

@ -77,7 +77,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
end
def assert_files(scope = nil, options={})
def assert_files(scope = nil, options = {})
scope = "devise" if scope.nil?
mail_template_engine = options[:mail_template_engine] || "html.erb"

View File

@ -282,7 +282,7 @@ class ConfirmationTest < Devise::IntegrationTest
end
class ConfirmationOnChangeTest < Devise::IntegrationTest
def create_second_admin(options={})
def create_second_admin(options = {})
@admin = nil
create_admin(options)
end

View File

@ -99,7 +99,7 @@ class HttpAuthenticationTest < Devise::IntegrationTest
end
private
def sign_in_as_new_user_with_http(username="user@test.com", password="12345678")
def sign_in_as_new_user_with_http(username = "user@test.com", password = "12345678")
user = create_user
get users_path(format: :xml), headers: { "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}" }
user

View File

@ -21,7 +21,7 @@ class PasswordTest < Devise::IntegrationTest
click_button 'Send me reset password instructions'
end
def reset_password(options={}, &block)
def reset_password(options = {}, &block)
unless options[:visit] == false
visit edit_user_password_path(reset_password_token: options[:reset_password_token] || "abcdef")
assert_response :success

View File

@ -3,7 +3,7 @@
require 'test_helper'
class RememberMeTest < Devise::IntegrationTest
def create_user_and_remember(add_to_token='')
def create_user_and_remember(add_to_token = '')
user = create_user
user.remember_me!
raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }

View File

@ -6,7 +6,7 @@ class FakeRequest < Struct.new(:path_info, :params)
end
class MappingTest < ActiveSupport::TestCase
def fake_request(path, params={})
def fake_request(path, params = {})
FakeRequest.new(path, params)
end

View File

@ -58,7 +58,7 @@ class SerializableTest < ActiveSupport::TestCase
assert !subject.key?(key), "Expected #{subject.inspect} to not have key #{key.inspect}"
end
def from_json(options=nil)
def from_json(options = nil)
ActiveSupport::JSON.decode(@user.to_json(options))["user"]
end
end

View File

@ -5,7 +5,7 @@ require 'test_helper'
class OmniAuthRoutesTest < ActionController::TestCase
tests ApplicationController
def assert_path(action, provider, with_param=true)
def assert_path(action, provider, with_param = true)
# Resource param
assert_equal @controller.send(action, :user, provider),
@controller.send("user_#{provider}_#{action}")

View File

@ -21,7 +21,7 @@ module SharedUserWithoutEmail
raise NoMethodError
end
def respond_to?(method_name, include_all=false)
def respond_to?(method_name, include_all = false)
return false if method_name.to_sym == :email_changed?
super(method_name, include_all)
end

View File

@ -27,32 +27,32 @@ class ActiveSupport::TestCase
"test#{@@email_count}@example.com"
end
def valid_attributes(attributes={})
def valid_attributes(attributes = {})
{ username: "usertest",
email: generate_unique_email,
password: '12345678',
password_confirmation: '12345678' }.update(attributes)
end
def new_user(attributes={})
def new_user(attributes = {})
User.new(valid_attributes(attributes))
end
def create_user(attributes={})
def create_user(attributes = {})
User.create!(valid_attributes(attributes))
end
def create_admin(attributes={})
def create_admin(attributes = {})
valid_attributes = valid_attributes(attributes)
valid_attributes.delete(:username)
Admin.create!(valid_attributes)
end
def create_user_without_email(attributes={})
def create_user_without_email(attributes = {})
UserWithoutEmail.create!(valid_attributes(attributes))
end
def create_user_with_validations(attributes={})
def create_user_with_validations(attributes = {})
UserWithValidations.create!(valid_attributes(attributes))
end

View File

@ -7,7 +7,7 @@ class ActionDispatch::IntegrationTest
request.env['warden']
end
def create_user(options={})
def create_user(options = {})
@user ||= begin
user = User.create!(
username: 'usertest',
@ -24,7 +24,7 @@ class ActionDispatch::IntegrationTest
end
end
def create_admin(options={})
def create_admin(options = {})
@admin ||= begin
admin = Admin.create!(
email: options[:email] || 'admin@test.com',
@ -36,7 +36,7 @@ class ActionDispatch::IntegrationTest
end
end
def sign_in_as_user(options={}, &block)
def sign_in_as_user(options = {}, &block)
user = create_user(options)
visit_with_option options[:visit], new_user_session_path
fill_in 'email', with: options[:email] || 'user@test.com'
@ -47,7 +47,7 @@ class ActionDispatch::IntegrationTest
user
end
def sign_in_as_admin(options={}, &block)
def sign_in_as_admin(options = {}, &block)
admin = create_admin(options)
visit_with_option options[:visit], new_admin_session_path
fill_in 'email', with: 'admin@test.com'