diff --git a/app/mailers/devise/mailer.rb b/app/mailers/devise/mailer.rb index 11ef449c..e617edcd 100644 --- a/app/mailers/devise/mailer.rb +++ b/app/mailers/devise/mailer.rb @@ -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 diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index e0e6acc3..bc6e9fd8 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -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 diff --git a/lib/devise/controllers/sign_in_out.rb b/lib/devise/controllers/sign_in_out.rb index 19481b4d..526b41ea 100644 --- a/lib/devise/controllers/sign_in_out.rb +++ b/lib/devise/controllers/sign_in_out.rb @@ -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 diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 3da36423..2792a07c 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -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) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 7692020f..7c7ea008 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -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 diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index 3df93112..5b748ad2 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -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) diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 91258f4c..7faae516 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -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) diff --git a/lib/devise/models/lockable.rb b/lib/devise/models/lockable.rb index b8ec4dca..578f5294 100644 --- a/lib/devise/models/lockable.rb +++ b/lib/devise/models/lockable.rb @@ -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 diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index 75318d50..0cca30f0 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -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) diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 95a4ced7..004b9857 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -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))) diff --git a/test/controllers/url_helpers_test.rb b/test/controllers/url_helpers_test.rb index d5328a36..e4b6a309 100644 --- a/test/controllers/url_helpers_test.rb +++ b/test/controllers/url_helpers_test.rb @@ -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 diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 920e47cb..1b0aeb04 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -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', diff --git a/test/generators/views_generator_test.rb b/test/generators/views_generator_test.rb index 3b7349fa..1f8f90f3 100644 --- a/test/generators/views_generator_test.rb +++ b/test/generators/views_generator_test.rb @@ -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" diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 85b2f723..16595461 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -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 diff --git a/test/integration/http_authenticatable_test.rb b/test/integration/http_authenticatable_test.rb index 3a52c571..619a3cd8 100644 --- a/test/integration/http_authenticatable_test.rb +++ b/test/integration/http_authenticatable_test.rb @@ -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 diff --git a/test/integration/recoverable_test.rb b/test/integration/recoverable_test.rb index d3cbb96b..2f1ca6e9 100644 --- a/test/integration/recoverable_test.rb +++ b/test/integration/recoverable_test.rb @@ -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 diff --git a/test/integration/rememberable_test.rb b/test/integration/rememberable_test.rb index cd6f2f10..62547e76 100644 --- a/test/integration/rememberable_test.rb +++ b/test/integration/rememberable_test.rb @@ -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 } diff --git a/test/mapping_test.rb b/test/mapping_test.rb index 0fc10c1a..0c874570 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -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 diff --git a/test/models/serializable_test.rb b/test/models/serializable_test.rb index 52a19813..602cbe37 100644 --- a/test/models/serializable_test.rb +++ b/test/models/serializable_test.rb @@ -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 diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index 41d4f501..a8098c74 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -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}") diff --git a/test/rails_app/lib/shared_user_without_email.rb b/test/rails_app/lib/shared_user_without_email.rb index f030c195..5a86729f 100644 --- a/test/rails_app/lib/shared_user_without_email.rb +++ b/test/rails_app/lib/shared_user_without_email.rb @@ -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 diff --git a/test/support/helpers.rb b/test/support/helpers.rb index fe7cf1b5..11ac4486 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -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 diff --git a/test/support/integration.rb b/test/support/integration.rb index 94554cba..76d297a4 100644 --- a/test/support/integration.rb +++ b/test/support/integration.rb @@ -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'