From dc1b399a8b7f03b4a876109de10fe6c8b771acd0 Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Tue, 25 Feb 2014 22:12:55 +0530 Subject: [PATCH] Updated ruby 1.9 hash syntax --- .../devise/confirmations_controller.rb | 4 +- .../devise/omniauth_callbacks_controller.rb | 4 +- .../devise/passwords_controller.rb | 6 +- .../devise/registrations_controller.rb | 14 +- app/controllers/devise/sessions_controller.rb | 12 +- app/controllers/devise/unlocks_controller.rb | 4 +- app/controllers/devise_controller.rb | 6 +- app/helpers/devise_helper.rb | 4 +- lib/devise.rb | 6 +- lib/devise/controllers/helpers.rb | 8 +- lib/devise/controllers/rememberable.rb | 6 +- lib/devise/controllers/sign_in_out.rb | 16 +- lib/devise/failure_app.rb | 6 +- lib/devise/hooks/activatable.rb | 2 +- lib/devise/hooks/lockable.rb | 2 +- lib/devise/hooks/proxy.rb | 2 +- lib/devise/hooks/rememberable.rb | 2 +- lib/devise/hooks/timeoutable.rb | 2 +- lib/devise/hooks/trackable.rb | 2 +- lib/devise/mailers/helpers.rb | 16 +- lib/devise/models/authenticatable.rb | 6 +- lib/devise/models/confirmable.rb | 18 +- lib/devise/models/database_authenticatable.rb | 2 +- lib/devise/models/lockable.rb | 12 +- lib/devise/models/omniauthable.rb | 2 +- lib/devise/models/recoverable.rb | 2 +- lib/devise/models/rememberable.rb | 6 +- lib/devise/models/trackable.rb | 2 +- lib/devise/models/validatable.rb | 12 +- lib/devise/modules.rb | 18 +- lib/devise/rails/routes.rb | 162 +++++++++--------- lib/devise/test_helpers.rb | 4 +- lib/devise/time_inflector.rb | 2 +- .../active_record/devise_generator.rb | 12 +- .../active_record/templates/migration.rb | 8 +- .../templates/migration_existing.rb | 8 +- lib/generators/devise/devise_generator.rb | 6 +- lib/generators/devise/views_generator.rb | 22 +-- lib/generators/mongoid/devise_generator.rb | 38 ++-- lib/generators/templates/devise.rb | 8 +- test/controllers/helpers_test.rb | 62 +++---- test/controllers/internal_helpers_test.rb | 12 +- test/controllers/sessions_controller_test.rb | 36 ++-- test/controllers/url_helpers_test.rb | 8 +- test/delegator_test.rb | 2 +- test/devise_test.rb | 6 +- test/failure_app_test.rb | 42 ++--- .../active_record_generator_test.rb | 8 +- test/generators/devise_generator_test.rb | 4 +- test/generators/mongoid_generator_test.rb | 2 +- test/generators/views_generator_test.rb | 2 +- test/helpers/devise_helper_test.rb | 22 +-- test/integration/authenticatable_test.rb | 84 ++++----- test/integration/confirmable_test.rb | 92 +++++----- .../database_authenticatable_test.rb | 32 ++-- test/integration/http_authenticatable_test.rb | 22 +-- test/integration/lockable_test.rb | 74 ++++---- test/integration/omniauthable_test.rb | 6 +- test/integration/recoverable_test.rb | 82 ++++----- test/integration/registerable_test.rb | 98 +++++------ test/integration/rememberable_test.rb | 26 +-- test/integration/timeoutable_test.rb | 14 +- test/integration/trackable_test.rb | 4 +- .../mailers/confirmation_instructions_test.rb | 8 +- .../reset_password_instructions_test.rb | 6 +- test/mailers/unlock_instructions_test.rb | 4 +- test/models/authenticatable_test.rb | 6 +- test/models/confirmable_test.rb | 62 +++---- test/models/database_authenticatable_test.rb | 54 +++--- test/models/lockable_test.rb | 58 +++---- test/models/recoverable_test.rb | 38 ++-- test/models/rememberable_test.rb | 16 +- test/models/serializable_test.rb | 16 +- test/models/timeoutable_test.rb | 2 +- test/models/validatable_test.rb | 22 +-- test/omniauth/config_test.rb | 6 +- test/omniauth/url_helpers_test.rb | 6 +- test/parameter_sanitizer_test.rb | 2 +- .../app/controllers/admins_controller.rb | 2 +- .../app/controllers/application_controller.rb | 4 +- .../app/controllers/home_controller.rb | 2 +- .../users/omniauth_callbacks_controller.rb | 4 +- .../app/controllers/users_controller.rb | 10 +- test/rails_app/app/mailers/users/mailer.rb | 8 +- test/rails_app/app/mongoid/admin.rb | 22 +-- test/rails_app/app/mongoid/shim.rb | 4 +- test/rails_app/app/mongoid/user.rb | 38 ++-- test/rails_app/config/application.rb | 4 +- test/rails_app/config/initializers/devise.rb | 6 +- .../config/initializers/secret_token.rb | 2 +- test/rails_app/config/routes.rb | 86 +++++----- .../migrate/20100401102949_create_tables.rb | 14 +- test/rails_app/lib/shared_admin.rb | 8 +- test/routes_test.rb | 118 ++++++------- test/support/helpers.rb | 8 +- test/support/integration.rb | 24 +-- test/test_helpers_test.rb | 6 +- test/test_models.rb | 10 +- 98 files changed, 950 insertions(+), 950 deletions(-) diff --git a/app/controllers/devise/confirmations_controller.rb b/app/controllers/devise/confirmations_controller.rb index 314fab20..8b2cbbcf 100644 --- a/app/controllers/devise/confirmations_controller.rb +++ b/app/controllers/devise/confirmations_controller.rb @@ -10,7 +10,7 @@ class Devise::ConfirmationsController < DeviseController yield resource if block_given? if successfully_sent?(resource) - respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name)) + respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name)) else respond_with(resource) end @@ -25,7 +25,7 @@ class Devise::ConfirmationsController < DeviseController set_flash_message(:notice, :confirmed) if is_flashing_format? respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } else - respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } + respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } end end diff --git a/app/controllers/devise/omniauth_callbacks_controller.rb b/app/controllers/devise/omniauth_callbacks_controller.rb index 14b5ee1c..92e40676 100644 --- a/app/controllers/devise/omniauth_callbacks_controller.rb +++ b/app/controllers/devise/omniauth_callbacks_controller.rb @@ -2,11 +2,11 @@ class Devise::OmniauthCallbacksController < DeviseController prepend_before_filter { request.env["devise.skip_timeout"] = true } def passthru - render :status => 404, :text => "Not found. Authentication passthru." + render status: 404, text: "Not found. Authentication passthru." end def failure - set_flash_message :alert, :failure, :kind => OmniAuth::Utils.camelize(failed_strategy.name), :reason => failure_message + set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message redirect_to after_omniauth_failure_path_for(resource_name) end diff --git a/app/controllers/devise/passwords_controller.rb b/app/controllers/devise/passwords_controller.rb index ef8888e5..d88ebdb6 100644 --- a/app/controllers/devise/passwords_controller.rb +++ b/app/controllers/devise/passwords_controller.rb @@ -1,7 +1,7 @@ class Devise::PasswordsController < DeviseController prepend_before_filter :require_no_authentication # Render the #edit only if coming from a reset password email link - append_before_filter :assert_reset_token_passed, :only => :edit + append_before_filter :assert_reset_token_passed, only: :edit # GET /resource/password/new def new @@ -14,7 +14,7 @@ class Devise::PasswordsController < DeviseController yield resource if block_given? if successfully_sent?(resource) - respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) + respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name)) else respond_with(resource) end @@ -36,7 +36,7 @@ class Devise::PasswordsController < DeviseController flash_message = resource.active_for_authentication? ? :updated : :updated_not_active set_flash_message(:notice, flash_message) if is_flashing_format? sign_in(resource_name, resource) - respond_with resource, :location => after_resetting_password_path_for(resource) + respond_with resource, location: after_resetting_password_path_for(resource) else respond_with resource end diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 616a226a..07f43aa7 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -1,6 +1,6 @@ class Devise::RegistrationsController < DeviseController - prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ] - prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy] + prepend_before_filter :require_no_authentication, only: [ :new, :create, :cancel ] + prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy] # GET /resource/sign_up def new @@ -17,11 +17,11 @@ class Devise::RegistrationsController < DeviseController if resource.active_for_authentication? set_flash_message :notice, :signed_up if is_flashing_format? sign_up(resource_name, resource) - respond_with resource, :location => after_sign_up_path_for(resource) + respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? expire_data_after_sign_in! - respond_with resource, :location => after_inactive_sign_up_path_for(resource) + respond_with resource, location: after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource @@ -48,8 +48,8 @@ class Devise::RegistrationsController < DeviseController :update_needs_confirmation : :updated set_flash_message :notice, flash_key end - sign_in resource_name, resource, :bypass => true - respond_with resource, :location => after_update_path_for(resource) + sign_in resource_name, resource, bypass: true + respond_with resource, location: after_update_path_for(resource) else clean_up_passwords resource respond_with resource @@ -121,7 +121,7 @@ class Devise::RegistrationsController < DeviseController # Authenticates the current scope and gets the current resource from the session. def authenticate_scope! - send(:"authenticate_#{resource_name}!", :force => true) + send(:"authenticate_#{resource_name}!", force: true) self.resource = send(:"current_#{resource_name}") end diff --git a/app/controllers/devise/sessions_controller.rb b/app/controllers/devise/sessions_controller.rb index 6b78dd85..8005a3e4 100644 --- a/app/controllers/devise/sessions_controller.rb +++ b/app/controllers/devise/sessions_controller.rb @@ -1,7 +1,7 @@ class Devise::SessionsController < DeviseController - prepend_before_filter :require_no_authentication, :only => [ :new, :create ] - prepend_before_filter :allow_params_authentication!, :only => :create - prepend_before_filter :only => [ :create, :destroy ] { request.env["devise.skip_timeout"] = true } + prepend_before_filter :require_no_authentication, only: [ :new, :create ] + prepend_before_filter :allow_params_authentication!, only: :create + prepend_before_filter only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true } # GET /resource/sign_in def new @@ -16,7 +16,7 @@ class Devise::SessionsController < DeviseController set_flash_message(:notice, :signed_in) if is_flashing_format? sign_in(resource_name, resource) yield resource if block_given? - respond_with resource, :location => after_sign_in_path_for(resource) + respond_with resource, location: after_sign_in_path_for(resource) end # DELETE /resource/sign_out @@ -44,10 +44,10 @@ class Devise::SessionsController < DeviseController methods = resource_class.authentication_keys.dup methods = methods.keys if methods.is_a?(Hash) methods << :password if resource.respond_to?(:password) - { :methods => methods, :only => [:password] } + { methods: methods, only: [:password] } end def auth_options - { :scope => resource_name, :recall => "#{controller_path}#new" } + { scope: resource_name, recall: "#{controller_path}#new" } end end diff --git a/app/controllers/devise/unlocks_controller.rb b/app/controllers/devise/unlocks_controller.rb index ec9987f5..903dcdbb 100644 --- a/app/controllers/devise/unlocks_controller.rb +++ b/app/controllers/devise/unlocks_controller.rb @@ -12,7 +12,7 @@ class Devise::UnlocksController < DeviseController yield resource if block_given? if successfully_sent?(resource) - respond_with({}, :location => after_sending_unlock_instructions_path_for(resource)) + respond_with({}, location: after_sending_unlock_instructions_path_for(resource)) else respond_with(resource) end @@ -27,7 +27,7 @@ class Devise::UnlocksController < DeviseController set_flash_message :notice, :unlocked if is_flashing_format? respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) } else - respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } + respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } end end diff --git a/app/controllers/devise_controller.rb b/app/controllers/devise_controller.rb index b1b88b74..f9380343 100644 --- a/app/controllers/devise_controller.rb +++ b/app/controllers/devise_controller.rb @@ -30,7 +30,7 @@ class DeviseController < Devise.parent_controller.constantize # Returns a signed in resource from session (if one exists) def signed_in_resource - warden.authenticate(:scope => resource_name) + warden.authenticate(scope: resource_name) end # Attempt to find the mapped route for devise based on request path @@ -92,14 +92,14 @@ MESSAGE # Helper for use in before_filters where no authentication is required. # # Example: - # before_filter :require_no_authentication, :only => :new + # before_filter :require_no_authentication, only: :new def require_no_authentication assert_is_devise_resource! return unless is_navigational_format? no_input = devise_mapping.no_input_strategies authenticated = if no_input.present? - args = no_input.dup.push :scope => resource_name + args = no_input.dup.push scope: resource_name warden.authenticate?(*args) else warden.authenticated?(resource_name) diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index cfcbc821..f2d07261 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -10,8 +10,8 @@ module DeviseHelper messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join sentence = I18n.t("errors.messages.not_saved", - :count => resource.errors.count, - :resource => resource.class.model_name.human.downcase) + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) html = <<-HTML
diff --git a/lib/devise.rb b/lib/devise.rb index e5e3f9ed..153751ea 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -350,8 +350,8 @@ module Devise # == Examples: # # Devise.add_module(:party_module) - # Devise.add_module(:party_module, :strategy => true, :controller => :sessions) - # Devise.add_module(:party_module, :model => 'party_module/model') + # Devise.add_module(:party_module, strategy: true, controller: :sessions) + # Devise.add_module(:party_module, model: 'party_module/model') # def self.add_module(module_name, options = {}) ALL << module_name @@ -449,7 +449,7 @@ module Devise warden_config.intercept_401 = false Devise.mappings.each_value do |mapping| - warden_config.scope_defaults mapping.name, :strategies => mapping.strategies + warden_config.scope_defaults mapping.name, strategies: mapping.strategies warden_config.serialize_into_session(mapping.name) do |record| mapping.to.serialize_into_session(record) diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index d46f5a2e..1d3b2ef4 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -55,7 +55,7 @@ module Devise end def current_#{mapping} - @current_#{mapping} ||= warden.authenticate(:scope => :#{mapping}) + @current_#{mapping} ||= warden.authenticate(scope: :#{mapping}) end def #{mapping}_session @@ -77,7 +77,7 @@ module Devise # the controllers defined inside devise. Useful if you want to apply a before # filter to all controllers, except the ones in devise: # - # before_filter :my_filter, :unless => :devise_controller? + # before_filter :my_filter, unless: :devise_controller? def devise_controller? is_a?(::DeviseController) end @@ -121,10 +121,10 @@ module Devise # root path. For a user scope, you can define the default url in # the following way: # - # map.user_root '/users', :controller => 'users' # creates user_root_path + # map.user_root '/users', controller: 'users' # creates user_root_path # # map.namespace :user do |user| - # user.root :controller => 'users' # creates user_root_path + # user.root controller: 'users' # creates user_root_path # end # # If the resource root path is not defined, root_path is used. However, diff --git a/lib/devise/controllers/rememberable.rb b/lib/devise/controllers/rememberable.rb index c2958aab..76edfe89 100644 --- a/lib/devise/controllers/rememberable.rb +++ b/lib/devise/controllers/rememberable.rb @@ -31,11 +31,11 @@ module Devise end def remember_cookie_values(resource) - options = { :httponly => true } + options = { httponly: true } options.merge!(forget_cookie_values(resource)) options.merge!( - :value => resource.class.serialize_into_cookie(resource), - :expires => resource.remember_expires_at + value: resource.class.serialize_into_cookie(resource), + expires: resource.remember_expires_at ) end diff --git a/lib/devise/controllers/sign_in_out.rb b/lib/devise/controllers/sign_in_out.rb index 205a1e6e..42181945 100644 --- a/lib/devise/controllers/sign_in_out.rb +++ b/lib/devise/controllers/sign_in_out.rb @@ -7,7 +7,7 @@ module Devise # true if any scope is signed in. Does not run authentication hooks. def signed_in?(scope=nil) [ scope || Devise.mappings.keys ].flatten.any? do |_scope| - warden.authenticate?(:scope => _scope) + warden.authenticate?(scope: _scope) end end @@ -23,9 +23,9 @@ module Devise # # sign_in :user, @user # sign_in(scope, resource) # sign_in @user # sign_in(resource) - # sign_in @user, :event => :authentication # sign_in(resource, options) - # sign_in @user, :store => false # sign_in(resource, options) - # sign_in @user, :bypass => true # sign_in(resource, options) + # sign_in @user, event: :authentication # sign_in(resource, options) + # sign_in @user, store: false # sign_in(resource, options) + # sign_in @user, bypass: true # sign_in(resource, options) # def sign_in(resource_or_scope, *args) options = args.extract_options! @@ -40,7 +40,7 @@ module Devise # Do nothing. User already signed in and we are not forcing it. true else - warden.set_user(resource, options.merge!(:scope => scope)) + warden.set_user(resource, options.merge!(scope: scope)) end end @@ -56,11 +56,11 @@ module Devise 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 + user = warden.user(scope: scope, run_callbacks: false) # If there is no user warden.raw_session.inspect # Without this inspect here. The session does not clear. warden.logout(scope) - warden.clear_strategies_cache!(:scope => scope) + warden.clear_strategies_cache!(scope: scope) instance_variable_set(:"@current_#{scope}", nil) !!user @@ -70,7 +70,7 @@ module Devise # 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) - users = Devise.mappings.keys.map { |s| warden.user(:scope => s, :run_callbacks => false) } + users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) } warden.raw_session.inspect warden.logout diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index 34f6a5c5..fb5e4c79 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -15,7 +15,7 @@ module Devise include Devise::Controllers::StoreLocation - delegate :flash, :to => :request + delegate :flash, to: :request def self.call(env) @respond ||= action(:respond) @@ -151,9 +151,9 @@ module Devise return i18n_message unless request_format method = "to_#{request_format}" if method == "to_xml" - { :error => i18n_message }.to_xml(:root => "errors") + { error: i18n_message }.to_xml(root: "errors") elsif {}.respond_to?(method) - { :error => i18n_message }.send(method) + { error: i18n_message }.send(method) else i18n_message end diff --git a/lib/devise/hooks/activatable.rb b/lib/devise/hooks/activatable.rb index af32e2b0..0ec7c62d 100644 --- a/lib/devise/hooks/activatable.rb +++ b/lib/devise/hooks/activatable.rb @@ -6,6 +6,6 @@ Warden::Manager.after_set_user do |record, warden, options| if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication? scope = options[:scope] warden.logout(scope) - throw :warden, :scope => scope, :message => record.inactive_message + throw :warden, scope: scope, message: record.inactive_message end end diff --git a/lib/devise/hooks/lockable.rb b/lib/devise/hooks/lockable.rb index b7b1ea08..50b726b7 100644 --- a/lib/devise/hooks/lockable.rb +++ b/lib/devise/hooks/lockable.rb @@ -1,6 +1,6 @@ # After each sign in, if resource responds to failed_attempts, sets it to 0 # This is only triggered when the user is explicitly set (with set_user) -Warden::Manager.after_set_user :except => :fetch do |record, warden, options| +Warden::Manager.after_set_user except: :fetch do |record, warden, options| if record.respond_to?(:failed_attempts) && warden.authenticated?(options[:scope]) record.update_attribute(:failed_attempts, 0) unless record.failed_attempts.to_i.zero? end diff --git a/lib/devise/hooks/proxy.rb b/lib/devise/hooks/proxy.rb index 096f624a..f27e1d04 100644 --- a/lib/devise/hooks/proxy.rb +++ b/lib/devise/hooks/proxy.rb @@ -7,7 +7,7 @@ module Devise include Devise::Controllers::SignInOut attr_reader :warden - delegate :cookies, :env, :to => :warden + delegate :cookies, :env, to: :warden def initialize(warden) @warden = warden diff --git a/lib/devise/hooks/rememberable.rb b/lib/devise/hooks/rememberable.rb index f67e05d4..077be534 100644 --- a/lib/devise/hooks/rememberable.rb +++ b/lib/devise/hooks/rememberable.rb @@ -1,4 +1,4 @@ -Warden::Manager.after_set_user :except => :fetch do |record, warden, options| +Warden::Manager.after_set_user except: :fetch do |record, warden, options| scope = options[:scope] if record.respond_to?(:remember_me) && options[:store] != false && record.remember_me && warden.authenticated?(scope) diff --git a/lib/devise/hooks/timeoutable.rb b/lib/devise/hooks/timeoutable.rb index ac88ee90..cc181747 100644 --- a/lib/devise/hooks/timeoutable.rb +++ b/lib/devise/hooks/timeoutable.rb @@ -18,7 +18,7 @@ Warden::Manager.after_set_user do |record, warden, options| record.reset_authentication_token! end - throw :warden, :scope => scope, :message => :timeout + throw :warden, scope: scope, message: :timeout end unless env['devise.skip_trackable'] diff --git a/lib/devise/hooks/trackable.rb b/lib/devise/hooks/trackable.rb index 0b4bc661..9bb21288 100644 --- a/lib/devise/hooks/trackable.rb +++ b/lib/devise/hooks/trackable.rb @@ -2,7 +2,7 @@ # This is only triggered when the user is explicitly set (with set_user) # and on authentication. Retrieving the user from session (:fetch) does # not trigger it. -Warden::Manager.after_set_user :except => :fetch do |record, warden, options| +Warden::Manager.after_set_user except: :fetch do |record, warden, options| if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope]) && !warden.request.env['devise.skip_trackable'] record.update_tracked_fields!(warden.request) end diff --git a/lib/devise/mailers/helpers.rb b/lib/devise/mailers/helpers.rb index 06cd4b42..60bf612b 100644 --- a/lib/devise/mailers/helpers.rb +++ b/lib/devise/mailers/helpers.rb @@ -27,12 +27,12 @@ module Devise def headers_for(action, opts) headers = { - :subject => subject_for(action), - :to => resource.email, - :from => mailer_sender(devise_mapping), - :reply_to => mailer_reply_to(devise_mapping), - :template_path => template_paths, - :template_name => action + subject: subject_for(action), + to: resource.email, + from: mailer_sender(devise_mapping), + reply_to: mailer_reply_to(devise_mapping), + template_path: template_paths, + template_name: action }.merge(opts) @email = headers[:to] @@ -82,8 +82,8 @@ module Devise # subject: '...' # def subject_for(key) - I18n.t(:"#{devise_mapping.name}_subject", :scope => [:devise, :mailer, key], - :default => [:subject, key.to_s.humanize]) + I18n.t(:"#{devise_mapping.name}_subject", scope: [:devise, :mailer, key], + default: [:subject, key.to_s.humanize]) end end end diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index b3dc5a95..78be957b 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -29,7 +29,7 @@ module Devise # It also accepts an array specifying the strategies that should allow params authentication. # # * +skip_session_storage+: By default Devise will store the user in session. - # By default is set to :skip_session_storage => [:http_auth]. + # By default is set to skip_session_storage: [:http_auth]. # # == active_for_authentication? # @@ -59,7 +59,7 @@ module Devise :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at] included do - class_attribute :devise_modules, :instance_writer => false + class_attribute :devise_modules, instance_writer: false self.devise_modules ||= [] before_validation :downcase_keys @@ -231,7 +231,7 @@ module Devise # Example: # # def self.find_for_authentication(tainted_conditions) - # find_first_by_auth_conditions(tainted_conditions, :active => true) + # find_first_by_auth_conditions(tainted_conditions, active: true) # end # # Finally, notice that Devise also queries for users in other scenarios diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 4a66b578..102c8cdb 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -33,10 +33,10 @@ module Devise include ActionView::Helpers::DateHelper included do - before_create :generate_confirmation_token, :if => :confirmation_required? - after_create :send_on_create_confirmation_instructions, :if => :send_confirmation_notification? - before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, :if => :postpone_email_change? - after_update :send_reconfirmation_instructions, :if => :reconfirmation_required? + before_create :generate_confirmation_token, if: :confirmation_required? + after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification? + before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change? + after_update :send_reconfirmation_instructions, if: :reconfirmation_required? end def initialize(*args, &block) @@ -60,7 +60,7 @@ module Devise pending_any_confirmation do if confirmation_period_expired? self.errors.add(:email, :confirmation_period_expired, - :period => Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago)) + period: Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago)) return false end @@ -73,9 +73,9 @@ module Devise self.unconfirmed_email = nil # We need to validate in such cases to enforce e-mail uniqueness - save(:validate => true) + save(validate: true) else - save(:validate => false) + save(validate: false) end after_confirmation if saved @@ -98,7 +98,7 @@ module Devise generate_confirmation_token! end - opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { } + opts = pending_reconfirmation? ? { to: unconfirmed_email } : { } send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts) end @@ -225,7 +225,7 @@ module Devise end def generate_confirmation_token! - generate_confirmation_token && save(:validate => false) + generate_confirmation_token && save(validate: false) end def postpone_email_change_until_confirmation_and_regenerate_confirmation_token diff --git a/lib/devise/models/database_authenticatable.rb b/lib/devise/models/database_authenticatable.rb index bb0744c1..6049eab6 100644 --- a/lib/devise/models/database_authenticatable.rb +++ b/lib/devise/models/database_authenticatable.rb @@ -4,7 +4,7 @@ require 'bcrypt' module Devise # Digests the password using bcrypt. def self.bcrypt(klass, password) - ::BCrypt::Password.create("#{password}#{klass.pepper}", :cost => klass.stretches).to_s + ::BCrypt::Password.create("#{password}#{klass.pepper}", cost: klass.stretches).to_s end module Models diff --git a/lib/devise/models/lockable.rb b/lib/devise/models/lockable.rb index 5efd484e..4fd5c94f 100644 --- a/lib/devise/models/lockable.rb +++ b/lib/devise/models/lockable.rb @@ -22,7 +22,7 @@ module Devise module Lockable extend ActiveSupport::Concern - delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class" + delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, to: "self.class" def self.required_fields(klass) attributes = [] @@ -36,14 +36,14 @@ module Devise # Lock a user setting its locked_at to actual time. # * +opts+: Hash options if you don't want to send email # when you lock access, you could pass the next hash - # `{ :send_instructions => false } as option`. + # `{ send_instructions: false } as option`. def lock_access!(opts = { }) self.locked_at = Time.now.utc if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true) send_unlock_instructions else - save(:validate => false) + save(validate: false) end end @@ -52,7 +52,7 @@ module Devise self.locked_at = nil self.failed_attempts = 0 if respond_to?(:failed_attempts=) self.unlock_token = nil if respond_to?(:unlock_token=) - save(:validate => false) + save(validate: false) end # Verifies whether a user is locked or not. @@ -64,7 +64,7 @@ module Devise def send_unlock_instructions raw, enc = Devise.token_generator.generate(self.class, :unlock_token) self.unlock_token = enc - self.save(:validate => false) + self.save(validate: false) send_devise_notification(:unlock_instructions, raw, {}) raw end @@ -104,7 +104,7 @@ module Devise if attempts_exceeded? lock_access! unless access_locked? else - save(:validate => false) + save(validate: false) end false end diff --git a/lib/devise/models/omniauthable.rb b/lib/devise/models/omniauthable.rb index 92d10d31..c1faf37a 100644 --- a/lib/devise/models/omniauthable.rb +++ b/lib/devise/models/omniauthable.rb @@ -10,7 +10,7 @@ module Devise # # * +omniauth_providers+: Which providers are available to this model. It expects an array: # - # devise_for :database_authenticatable, :omniauthable, :omniauth_providers => [:twitter] + # devise_for :database_authenticatable, :omniauthable, omniauth_providers: [:twitter] # module Omniauthable extend ActiveSupport::Concern diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index 3b4cfa35..0ae4dbee 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -49,7 +49,7 @@ module Devise self.reset_password_token = enc self.reset_password_sent_at = Time.now.utc - self.save(:validate => false) + self.save(validate: false) send_devise_notification(:reset_password_instructions, raw, {}) raw diff --git a/lib/devise/models/rememberable.rb b/lib/devise/models/rememberable.rb index 6c756e44..94bf8fe6 100644 --- a/lib/devise/models/rememberable.rb +++ b/lib/devise/models/rememberable.rb @@ -50,7 +50,7 @@ module Devise def remember_me!(extend_period=false) self.remember_token = self.class.remember_token if generate_remember_token? self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period) - save(:validate => false) if self.changed? + save(validate: false) if self.changed? end # If the record is persisted, remove the remember token (but only if @@ -59,7 +59,7 @@ module Devise return unless persisted? self.remember_token = nil if respond_to?(:remember_token=) self.remember_created_at = nil - save(:validate => false) + save(validate: false) end # Remember token should be expired if expiration time not overpass now. @@ -118,7 +118,7 @@ module Devise def remember_token #:nodoc: loop do token = Devise.friendly_token - break token unless to_adapter.find_first({ :remember_token => token }) + break token unless to_adapter.find_first({ remember_token: token }) end end diff --git a/lib/devise/models/trackable.rb b/lib/devise/models/trackable.rb index cfb70476..c7018774 100644 --- a/lib/devise/models/trackable.rb +++ b/lib/devise/models/trackable.rb @@ -27,7 +27,7 @@ module Devise self.sign_in_count ||= 0 self.sign_in_count += 1 - save(:validate => false) or raise "Devise trackable could not save #{inspect}." \ + save(validate: false) or raise "Devise trackable could not save #{inspect}." \ "Please make sure a model using trackable can be saved at sign in." end end diff --git a/lib/devise/models/validatable.rb b/lib/devise/models/validatable.rb index bc8ae225..2bfdf458 100644 --- a/lib/devise/models/validatable.rb +++ b/lib/devise/models/validatable.rb @@ -26,13 +26,13 @@ module Devise assert_validations_api!(base) base.class_eval do - validates_presence_of :email, :if => :email_required? - validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed? - validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed? + validates_presence_of :email, if: :email_required? + validates_uniqueness_of :email, allow_blank: true, if: :email_changed? + validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed? - validates_presence_of :password, :if => :password_required? - validates_confirmation_of :password, :if => :password_required? - validates_length_of :password, :within => password_length, :allow_blank => true + validates_presence_of :password, if: :password_required? + validates_confirmation_of :password, if: :password_required? + validates_length_of :password, within: password_length, allow_blank: true end end diff --git a/lib/devise/modules.rb b/lib/devise/modules.rb index b7cdc2f6..2af8820b 100644 --- a/lib/devise/modules.rb +++ b/lib/devise/modules.rb @@ -1,26 +1,26 @@ require 'active_support/core_ext/object/with_options' -Devise.with_options :model => true do |d| +Devise.with_options model: true do |d| # Strategies first - d.with_options :strategy => true do |s| + d.with_options strategy: true do |s| routes = [nil, :new, :destroy] - s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes } - s.add_module :rememberable, :no_input => true + s.add_module :database_authenticatable, controller: :sessions, route: { session: routes } + s.add_module :rememberable, no_input: true end # Other authentications - d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback + d.add_module :omniauthable, controller: :omniauth_callbacks, route: :omniauth_callback # Misc after routes = [nil, :new, :edit] - d.add_module :recoverable, :controller => :passwords, :route => { :password => routes } - d.add_module :registerable, :controller => :registrations, :route => { :registration => (routes << :cancel) } + d.add_module :recoverable, controller: :passwords, route: { password: routes } + d.add_module :registerable, controller: :registrations, route: { registration: (routes << :cancel) } d.add_module :validatable # The ones which can sign out after routes = [nil, :new] - d.add_module :confirmable, :controller => :confirmations, :route => { :confirmation => routes } - d.add_module :lockable, :controller => :unlocks, :route => { :unlock => routes } + d.add_module :confirmable, controller: :confirmations, route: { confirmation: routes } + d.add_module :lockable, controller: :unlocks, route: { unlock: routes } d.add_module :timeoutable # Stats for last, so we make sure the user is really signed in diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 8ffb9713..2951b141 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -43,20 +43,20 @@ module ActionDispatch::Routing # needed routes: # # # Session routes for Authenticatable (default) - # new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"} - # user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"} - # destroy_user_session DELETE /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"} + # new_user_session GET /users/sign_in {controller:"devise/sessions", action:"new"} + # user_session POST /users/sign_in {controller:"devise/sessions", action:"create"} + # destroy_user_session DELETE /users/sign_out {controller:"devise/sessions", action:"destroy"} # # # Password routes for Recoverable, if User model has :recoverable configured - # new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"} - # edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"} - # user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"} - # POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"} + # new_user_password GET /users/password/new(.:format) {controller:"devise/passwords", action:"new"} + # edit_user_password GET /users/password/edit(.:format) {controller:"devise/passwords", action:"edit"} + # user_password PUT /users/password(.:format) {controller:"devise/passwords", action:"update"} + # POST /users/password(.:format) {controller:"devise/passwords", action:"create"} # # # Confirmation routes for Confirmable, if User model has :confirmable configured - # new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"} - # user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"} - # POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"} + # new_user_confirmation GET /users/confirmation/new(.:format) {controller:"devise/confirmations", action:"new"} + # user_confirmation GET /users/confirmation(.:format) {controller:"devise/confirmations", action:"show"} + # POST /users/confirmation(.:format) {controller:"devise/confirmations", action:"create"} # # ==== Routes integration # @@ -84,22 +84,22 @@ module ActionDispatch::Routing # # You can configure your routes with some options: # - # * :class_name => setup a different class to be looked up by devise, if it cannot be + # * class_name: setup a different class to be looked up by devise, if it cannot be # properly found by the route name. # - # devise_for :users, :class_name => 'Account' + # devise_for :users, class_name: 'Account' # - # * :path => allows you to setup path name that will be used, as rails routes does. + # * path: allows you to setup path name that will be used, as rails routes does. # The following route configuration would setup your route as /accounts instead of /users: # - # devise_for :users, :path => 'accounts' + # devise_for :users, path: 'accounts' # - # * :singular => setup the singular name for the given resource. This is used as the instance variable + # * singular: setup the singular name for the given resource. This is used as the instance variable # name in controller, as the name in routes and the scope given to warden. # - # devise_for :users, :singular => :user + # devise_for :users, singular: :user # - # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up, + # * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up, # :password, :confirmation, :unlock. # # devise_for :users, path_names: { @@ -108,50 +108,50 @@ module ActionDispatch::Routing # registration: 'register', edit: 'edit/profile' # } # - # * :controllers => the controller which should be used. All routes by default points to Devise controllers. + # * controllers: the controller which should be used. All routes by default points to Devise controllers. # However, if you want them to point to custom controller, you should do: # - # devise_for :users, :controllers => { :sessions => "users/sessions" } + # devise_for :users, controllers: { sessions: "users/sessions" } # - # * :failure_app => a rack app which is invoked whenever there is a failure. Strings representing a given + # * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given # are also allowed as parameter. # - # * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get), + # * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get), # if you wish to restrict this to accept only :post or :delete requests you should do: # - # devise_for :users, :sign_out_via => [ :post, :delete ] + # devise_for :users, sign_out_via: [ :post, :delete ] # # You need to make sure that your sign_out controls trigger a request with a matching HTTP method. # - # * :module => the namespace to find controllers (default: "devise", thus + # * module: the namespace to find controllers (default: "devise", thus # accessing devise/sessions, devise/registrations, and so on). If you want # to namespace all at once, use module: # - # devise_for :users, :module => "users" + # devise_for :users, module: "users" # - # * :skip => tell which controller you want to skip routes from being created: + # * skip: tell which controller you want to skip routes from being created: # - # devise_for :users, :skip => :sessions + # devise_for :users, skip: :sessions # - # * :only => the opposite of :skip, tell which controllers only to generate routes to: + # * only: the opposite of :skip, tell which controllers only to generate routes to: # - # devise_for :users, :only => :sessions + # devise_for :users, only: :sessions # - # * :skip_helpers => skip generating Devise url helpers like new_session_path(@user). + # * skip_helpers: skip generating Devise url helpers like new_session_path(@user). # This is useful to avoid conflicts with previous routes and is false by default. # It accepts true as option, meaning it will skip all the helpers for the controllers # given in :skip but it also accepts specific helpers to be skipped: # - # devise_for :users, :skip => [:registrations, :confirmations], :skip_helpers => true - # devise_for :users, :skip_helpers => [:registrations, :confirmations] + # devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true + # devise_for :users, skip_helpers: [:registrations, :confirmations] # - # * :format => include "(.:format)" in the generated routes? true by default, set to false to disable: + # * format: include "(.:format)" in the generated routes? true by default, set to false to disable: # - # devise_for :users, :format => false + # devise_for :users, format: false # - # * :constraints => works the same as Rails' constraints + # * constraints: works the same as Rails' constraints # - # * :defaults => works the same as Rails' defaults + # * defaults: works the same as Rails' defaults # # ==== Scoping # @@ -173,7 +173,7 @@ module ActionDispatch::Routing # # class ApplicationController < ActionController::Base # def self.default_url_options - # { :locale => I18n.locale } + # { locale: I18n.locale } # end # end # @@ -198,7 +198,7 @@ module ActionDispatch::Routing # In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this: # # devise_scope :owner do - # post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration" + # post "deactivate", to: "registrations#deactivate", as: "deactivate_registration" # end # def devise_for(*resources) @@ -263,7 +263,7 @@ module ActionDispatch::Routing # end # # authenticate :user, lambda {|u| u.role == "admin"} do - # root :to => "admin/dashboard#show", :as => :user_root + # root to: "admin/dashboard#show", as: :user_root # end # def authenticate(scope=nil, block=nil) @@ -277,18 +277,18 @@ module ActionDispatch::Routing # a model and allows extra constraints to be done on the instance. # # authenticated :admin do - # root :to => 'admin/dashboard#show', :as => :admin_root + # root to: 'admin/dashboard#show', as: :admin_root # end # # authenticated do - # root :to => 'dashboard#show', :as => :authenticated_root + # root to: 'dashboard#show', as: :authenticated_root # end # # authenticated :user, lambda {|u| u.role == "admin"} do - # root :to => "admin/dashboard#show", :as => :user_root + # root to: "admin/dashboard#show", as: :user_root # end # - # root :to => 'landing#show' + # root to: 'landing#show' # def authenticated(scope=nil, block=nil) constraints_for(:authenticate?, scope, block) do @@ -301,15 +301,15 @@ module ActionDispatch::Routing # # unauthenticated do # as :user do - # root :to => 'devise/registrations#new' + # root to: 'devise/registrations#new' # end # end # - # root :to => 'dashboard#show' + # root to: 'dashboard#show' # def unauthenticated(scope=nil) constraint = lambda do |request| - not request.env["warden"].authenticate? :scope => scope + not request.env["warden"].authenticate? scope: scope end constraints(constraint) do @@ -322,7 +322,7 @@ module ActionDispatch::Routing # to which controller it is targetted. # # as :user do - # get "sign_in", :to => "devise/sessions#new" + # get "sign_in", to: "devise/sessions#new" # end # # Notice you cannot have two scopes mapping to the same URL. And remember, if @@ -354,42 +354,42 @@ module ActionDispatch::Routing protected def devise_session(mapping, controllers) #:nodoc: - resource :session, :only => [], :controller => controllers[:sessions], :path => "" do - get :new, :path => mapping.path_names[:sign_in], :as => "new" - post :create, :path => mapping.path_names[:sign_in] - match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via + resource :session, only: [], controller: controllers[:sessions], path: "" do + get :new, path: mapping.path_names[:sign_in], as: "new" + post :create, path: mapping.path_names[:sign_in] + match :destroy, path: mapping.path_names[:sign_out], as: "destroy", via: mapping.sign_out_via end end def devise_password(mapping, controllers) #:nodoc: - resource :password, :only => [:new, :create, :edit, :update], - :path => mapping.path_names[:password], :controller => controllers[:passwords] + resource :password, only: [:new, :create, :edit, :update], + path: mapping.path_names[:password], controller: controllers[:passwords] end def devise_confirmation(mapping, controllers) #:nodoc: - resource :confirmation, :only => [:new, :create, :show], - :path => mapping.path_names[:confirmation], :controller => controllers[:confirmations] + resource :confirmation, only: [:new, :create, :show], + path: mapping.path_names[:confirmation], controller: controllers[:confirmations] end def devise_unlock(mapping, controllers) #:nodoc: if mapping.to.unlock_strategy_enabled?(:email) - resource :unlock, :only => [:new, :create, :show], - :path => mapping.path_names[:unlock], :controller => controllers[:unlocks] + resource :unlock, only: [:new, :create, :show], + path: mapping.path_names[:unlock], controller: controllers[:unlocks] end end def devise_registration(mapping, controllers) #:nodoc: path_names = { - :new => mapping.path_names[:sign_up], - :edit => mapping.path_names[:edit], - :cancel => mapping.path_names[:cancel] + new: mapping.path_names[:sign_up], + edit: mapping.path_names[:edit], + cancel: mapping.path_names[:cancel] } options = { - :only => [:new, :create, :edit, :update, :destroy], - :path => mapping.path_names[:registration], - :path_names => path_names, - :controller => controllers[:registrations] + only: [:new, :create, :edit, :update, :destroy], + path: mapping.path_names[:registration], + path_names: path_names, + controller: controllers[:registrations] } resource :registration, options do @@ -405,16 +405,16 @@ and you have set #{mapping.fullpath.inspect}. You can work around by passing `skip: :omniauth_callbacks` and manually defining the routes. Here is an example: match "/users/auth/:provider", - :constraints => { :provider => /google|facebook/ }, - :to => "devise/omniauth_callbacks#passthru", - :as => :omniauth_authorize, - :via => [:get, :post] + constraints: { provider: /google|facebook/ }, + to: "devise/omniauth_callbacks#passthru", + as: :omniauth_authorize, + via: [:get, :post] match "/users/auth/:action/callback", - :constraints => { :action => /google|facebook/ }, - :to => "devise/omniauth_callbacks", - :as => :omniauth_callback, - :via => [:get, :post] + constraints: { action: /google|facebook/ }, + to: "devise/omniauth_callbacks", + as: :omniauth_callback, + via: [:get, :post] ERROR end @@ -426,16 +426,16 @@ ERROR providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) match "#{path_prefix}/:provider", - :constraints => { :provider => providers }, - :to => "#{controllers[:omniauth_callbacks]}#passthru", - :as => :omniauth_authorize, - :via => [:get, :post] + constraints: { provider: providers }, + to: "#{controllers[:omniauth_callbacks]}#passthru", + as: :omniauth_authorize, + via: [:get, :post] match "#{path_prefix}/:action/callback", - :constraints => { :action => providers }, - :to => controllers[:omniauth_callbacks], - :as => :omniauth_callback, - :via => [:get, :post] + constraints: { action: providers }, + to: controllers[:omniauth_callbacks], + as: :omniauth_callback, + via: [:get, :post] ensure @scope[:path] = path end @@ -446,7 +446,7 @@ ERROR old = {} DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] } - new = { :as => new_as, :path => new_path, :module => nil } + new = { as: new_as, path: new_path, module: nil } new.merge!(options.slice(:constraints, :defaults, :options)) @scope.merge!(new) @@ -457,7 +457,7 @@ ERROR def constraints_for(method_to_apply, scope=nil, block=nil) constraint = lambda do |request| - request.env['warden'].send(method_to_apply, :scope => scope) && + request.env['warden'].send(method_to_apply, scope: scope) && (block.nil? || block.call(request.env["warden"].user(scope))) end diff --git a/lib/devise/test_helpers.rb b/lib/devise/test_helpers.rb index 04070289..65adb602 100644 --- a/lib/devise/test_helpers.rb +++ b/lib/devise/test_helpers.rb @@ -109,8 +109,8 @@ module Devise status, headers, response = Devise.warden_config[:failure_app].call(env).to_a @controller.response.headers.merge!(headers) - @controller.send :render, :status => status, :text => response.body, - :content_type => headers["Content-Type"], :location => headers["Location"] + @controller.send :render, status: status, text: response.body, + content_type: headers["Content-Type"], location: headers["Location"] nil # causes process return @response end diff --git a/lib/devise/time_inflector.rb b/lib/devise/time_inflector.rb index cb311883..94795afd 100644 --- a/lib/devise/time_inflector.rb +++ b/lib/devise/time_inflector.rb @@ -6,7 +6,7 @@ module Devise class << self attr_reader :instance - delegate :time_ago_in_words, :to => :instance + delegate :time_ago_in_words, to: :instance end @instance = new diff --git a/lib/generators/active_record/devise_generator.rb b/lib/generators/active_record/devise_generator.rb index 28b529db..2d74d3f5 100644 --- a/lib/generators/active_record/devise_generator.rb +++ b/lib/generators/active_record/devise_generator.rb @@ -4,7 +4,7 @@ require 'generators/devise/orm_helpers' module ActiveRecord module Generators class DeviseGenerator < ActiveRecord::Generators::Base - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + argument :attributes, type: :array, default: [], banner: "field:type field:type" include Devise::Generators::OrmHelpers source_root File.expand_path("../templates", __FILE__) @@ -18,7 +18,7 @@ module ActiveRecord end def generate_model - invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke + invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke end def inject_devise_content @@ -39,8 +39,8 @@ module ActiveRecord def migration_data < false, :default => "" - t.string :encrypted_password, :null => false, :default => "" + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" ## Recoverable t.string :reset_password_token @@ -50,7 +50,7 @@ module ActiveRecord t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -63,7 +63,7 @@ module ActiveRecord # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable - # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at RUBY diff --git a/lib/generators/active_record/templates/migration.rb b/lib/generators/active_record/templates/migration.rb index 5a9d240c..71454226 100644 --- a/lib/generators/active_record/templates/migration.rb +++ b/lib/generators/active_record/templates/migration.rb @@ -10,9 +10,9 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration t.timestamps end - add_index :<%= table_name %>, :email, :unique => true - add_index :<%= table_name %>, :reset_password_token, :unique => true - # add_index :<%= table_name %>, :confirmation_token, :unique => true - # add_index :<%= table_name %>, :unlock_token, :unique => true + add_index :<%= table_name %>, :email, unique: true + add_index :<%= table_name %>, :reset_password_token, unique: true + # add_index :<%= table_name %>, :confirmation_token, unique: true + # add_index :<%= table_name %>, :unlock_token, unique: true end end diff --git a/lib/generators/active_record/templates/migration_existing.rb b/lib/generators/active_record/templates/migration_existing.rb index cc49ca42..1b0ff5dd 100644 --- a/lib/generators/active_record/templates/migration_existing.rb +++ b/lib/generators/active_record/templates/migration_existing.rb @@ -11,10 +11,10 @@ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration # t.timestamps end - add_index :<%= table_name %>, :email, :unique => true - add_index :<%= table_name %>, :reset_password_token, :unique => true - # add_index :<%= table_name %>, :confirmation_token, :unique => true - # add_index :<%= table_name %>, :unlock_token, :unique => true + add_index :<%= table_name %>, :email, unique: true + add_index :<%= table_name %>, :reset_password_token, unique: true + # add_index :<%= table_name %>, :confirmation_token, unique: true + # add_index :<%= table_name %>, :unlock_token, unique: true end def self.down diff --git a/lib/generators/devise/devise_generator.rb b/lib/generators/devise/devise_generator.rb index d7555631..80503951 100644 --- a/lib/generators/devise/devise_generator.rb +++ b/lib/generators/devise/devise_generator.rb @@ -13,12 +13,12 @@ module Devise hook_for :orm - class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true + class_option :routes, desc: "Generate routes", type: :boolean, default: true def add_devise_routes devise_route = "devise_for :#{plural_name}" - devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::") - devise_route << %Q(, :skip => :all) unless options.routes? + devise_route << %Q(, class_name: "#{class_name}") if class_name.include?("::") + devise_route << %Q(, skip: :all) unless options.routes? route devise_route end end diff --git a/lib/generators/devise/views_generator.rb b/lib/generators/devise/views_generator.rb index 79fbf570..d8acdec6 100644 --- a/lib/generators/devise/views_generator.rb +++ b/lib/generators/devise/views_generator.rb @@ -9,12 +9,12 @@ module Devise extend ActiveSupport::Concern included do - argument :scope, :required => false, :default => nil, - :desc => "The scope to copy views to" + argument :scope, required: false, default: nil, + desc: "The scope to copy views to" # Le sigh, ensure Thor won't handle opts as args # It should be fixed in future Rails releases - class_option :form_builder, :aliases => "-b" + class_option :form_builder, aliases: "-b" class_option :markerb public_task :copy_views @@ -107,18 +107,18 @@ module Devise class ViewsGenerator < Rails::Generators::Base desc "Copies Devise views to your application." - argument :scope, :required => false, :default => nil, - :desc => "The scope to copy views to" + argument :scope, required: false, default: nil, + desc: "The scope to copy views to" invoke SharedViewsGenerator - hook_for :form_builder, :aliases => "-b", - :desc => "Form builder to be used", - :default => defined?(SimpleForm) ? "simple_form_for" : "form_for" + hook_for :form_builder, aliases: "-b", + desc: "Form builder to be used", + default: defined?(SimpleForm) ? "simple_form_for" : "form_for" - hook_for :markerb, :desc => "Generate markerb instead of erb mail views", - :default => defined?(Markerb) ? :markerb : :erb, - :type => :boolean + hook_for :markerb, desc: "Generate markerb instead of erb mail views", + default: defined?(Markerb) ? :markerb : :erb, + type: :boolean end end end diff --git a/lib/generators/mongoid/devise_generator.rb b/lib/generators/mongoid/devise_generator.rb index 213c9533..4ff57f06 100644 --- a/lib/generators/mongoid/devise_generator.rb +++ b/lib/generators/mongoid/devise_generator.rb @@ -11,43 +11,43 @@ module Mongoid end def inject_field_types - inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists? + inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists? end def inject_devise_content - inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists? + inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists? end def migration_data < String, :default => "" - field :encrypted_password, :type => String, :default => "" + field :email, type: String, default: "" + field :encrypted_password, type: String, default: "" ## Recoverable - field :reset_password_token, :type => String - field :reset_password_sent_at, :type => Time + field :reset_password_token, type: String + field :reset_password_sent_at, type: Time ## Rememberable - field :remember_created_at, :type => Time + field :remember_created_at, type: Time ## Trackable - field :sign_in_count, :type => Integer, :default => 0 - field :current_sign_in_at, :type => Time - field :last_sign_in_at, :type => Time - field :current_sign_in_ip, :type => String - field :last_sign_in_ip, :type => String + field :sign_in_count, type: Integer, default: 0 + field :current_sign_in_at, type: Time + field :last_sign_in_at, type: Time + field :current_sign_in_ip, type: String + field :last_sign_in_ip, type: String ## Confirmable - # field :confirmation_token, :type => String - # field :confirmed_at, :type => Time - # field :confirmation_sent_at, :type => Time - # field :unconfirmed_email, :type => String # Only if using reconfirmable + # field :confirmation_token, type: String + # field :confirmed_at, type: Time + # field :confirmation_sent_at, type: Time + # field :unconfirmed_email, type: String # Only if using reconfirmable ## Lockable - # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts - # field :unlock_token, :type => String # Only if unlock strategy is :email or :both - # field :locked_at, :type => Time + # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts + # field :unlock_token, type: String # Only if unlock strategy is :email or :both + # field :locked_at, type: Time RUBY end end diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index bcf925ba..b56ef580 100644 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -80,7 +80,7 @@ Devise.setup do |config| # particular strategies by setting this option. # Notice that if you are skipping storage for all authentication paths, you # may want to disable generating routes to Devise's sessions controller by - # passing :skip => :sessions to `devise_for` in your config/routes.rb + # passing skip: :sessions to `devise_for` in your config/routes.rb config.skip_session_storage = [:http_auth] # By default, Devise cleans up the CSRF token on authentication to @@ -134,7 +134,7 @@ Devise.setup do |config| # config.extend_remember_period = false # Options to be passed to the created cookie. For instance, you can set - # :secure => true in order to force SSL only cookies. + # secure: true in order to force SSL only cookies. # config.rememberable_options = {} # ==> Configuration for :validatable @@ -231,7 +231,7 @@ Devise.setup do |config| # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or @@ -239,7 +239,7 @@ Devise.setup do |config| # # config.warden do |manager| # manager.intercept_401 = false - # manager.default_strategies(:scope => :user).unshift :some_external_strategy + # manager.default_strategies(scope: :user).unshift :some_external_strategy # end # ==> Mountable engine configurations diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 3abd0e19..4a7b6484 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -14,81 +14,81 @@ class ControllerAuthenticatableTest < ActionController::TestCase end test 'proxy signed_in?(scope) to authenticate?' do - @mock_warden.expects(:authenticate?).with(:scope => :my_scope) + @mock_warden.expects(:authenticate?).with(scope: :my_scope) @controller.signed_in?(:my_scope) end test 'proxy signed_in?(nil) to authenticate?' do Devise.mappings.keys.each do |scope| # :user, :admin, :manager - @mock_warden.expects(:authenticate?).with(:scope => scope) + @mock_warden.expects(:authenticate?).with(scope: scope) end @controller.signed_in? end test 'proxy current_user to authenticate with user scope' do - @mock_warden.expects(:authenticate).with(:scope => :user) + @mock_warden.expects(:authenticate).with(scope: :user) @controller.current_user end test 'proxy current_admin to authenticate with admin scope' do - @mock_warden.expects(:authenticate).with(:scope => :admin) + @mock_warden.expects(:authenticate).with(scope: :admin) @controller.current_admin end test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do - @mock_warden.expects(:authenticate).with(:scope => :publisher_account) + @mock_warden.expects(:authenticate).with(scope: :publisher_account) @controller.current_publisher_account end test 'proxy authenticate_user! to authenticate with user scope' do - @mock_warden.expects(:authenticate!).with(:scope => :user) + @mock_warden.expects(:authenticate!).with(scope: :user) @controller.authenticate_user! end test 'proxy authenticate_user! options to authenticate with user scope' do - @mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo") - @controller.authenticate_user!(:recall => "foo") + @mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo") + @controller.authenticate_user!(recall: "foo") end test 'proxy authenticate_admin! to authenticate with admin scope' do - @mock_warden.expects(:authenticate!).with(:scope => :admin) + @mock_warden.expects(:authenticate!).with(scope: :admin) @controller.authenticate_admin! end test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do - @mock_warden.expects(:authenticate!).with(:scope => :publisher_account) + @mock_warden.expects(:authenticate!).with(scope: :publisher_account) @controller.authenticate_publisher_account! end test 'proxy user_signed_in? to authenticate with user scope' do - @mock_warden.expects(:authenticate).with(:scope => :user).returns("user") + @mock_warden.expects(:authenticate).with(scope: :user).returns("user") assert @controller.user_signed_in? end test 'proxy admin_signed_in? to authenticatewith admin scope' do - @mock_warden.expects(:authenticate).with(:scope => :admin) + @mock_warden.expects(:authenticate).with(scope: :admin) assert_not @controller.admin_signed_in? end test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do - @mock_warden.expects(:authenticate).with(:scope => :publisher_account) + @mock_warden.expects(:authenticate).with(scope: :publisher_account) @controller.publisher_account_signed_in? end test 'proxy user_session to session scope in warden' do - @mock_warden.expects(:authenticate).with(:scope => :user).returns(true) + @mock_warden.expects(:authenticate).with(scope: :user).returns(true) @mock_warden.expects(:session).with(:user).returns({}) @controller.user_session end test 'proxy admin_session to session scope in warden' do - @mock_warden.expects(:authenticate).with(:scope => :admin).returns(true) + @mock_warden.expects(:authenticate).with(scope: :admin).returns(true) @mock_warden.expects(:session).with(:admin).returns({}) @controller.admin_session end test 'proxy publisher_account_session from namespaced scope to session scope in warden' do - @mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true) + @mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true) @mock_warden.expects(:session).with(:publisher_account).returns({}) @controller.publisher_account_session end @@ -96,14 +96,14 @@ class ControllerAuthenticatableTest < ActionController::TestCase test 'sign in proxy to set_user on warden' do user = User.new @mock_warden.expects(:user).returns(nil) - @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true) + @mock_warden.expects(:set_user).with(user, scope: :user).returns(true) @controller.sign_in(:user, user) end test 'sign in accepts a resource as argument' do user = User.new @mock_warden.expects(:user).returns(nil) - @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true) + @mock_warden.expects(:set_user).with(user, scope: :user).returns(true) @controller.sign_in(user) end @@ -117,15 +117,15 @@ class ControllerAuthenticatableTest < ActionController::TestCase test 'sign in again when the user is already in only if force is given' do user = User.new @mock_warden.expects(:user).returns(user) - @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true) - @controller.sign_in(user, :force => true) + @mock_warden.expects(:set_user).with(user, scope: :user).returns(true) + @controller.sign_in(user, force: true) end test 'sign in accepts bypass as option' do user = User.new @mock_warden.expects(:session_serializer).returns(serializer = mock()) serializer.expects(:store).with(user, :user) - @controller.sign_in(user, :bypass => true) + @controller.sign_in(user, bypass: true) end test 'sign out clears up any signed in user from all scopes' do @@ -141,18 +141,18 @@ class ControllerAuthenticatableTest < ActionController::TestCase test 'sign out logs out and clears up any signed in user by scope' do user = User.new - @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user) + @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user) @mock_warden.expects(:logout).with(:user).returns(true) - @mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true) + @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true) @controller.instance_variable_set(:@current_user, user) @controller.sign_out(:user) assert_equal nil, @controller.instance_variable_get(:@current_user) end test 'sign out accepts a resource as argument' do - @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true) + @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true) @mock_warden.expects(:logout).with(:user).returns(true) - @mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true) + @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true) @controller.sign_out(User.new) end @@ -227,7 +227,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase user = User.new @controller.session[:user_return_to] = "/foo.bar" @mock_warden.expects(:user).with(:user).returns(nil) - @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true) + @mock_warden.expects(:set_user).with(user, scope: :user).returns(true) @controller.expects(:redirect_to).with("/foo.bar") @controller.sign_in_and_redirect(user) end @@ -235,7 +235,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase test 'sign in and redirect uses the configured after sign in path' do admin = Admin.new @mock_warden.expects(:user).with(:admin).returns(nil) - @mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true) + @mock_warden.expects(:set_user).with(admin, scope: :admin).returns(true) @controller.expects(:redirect_to).with(admin_root_path) @controller.sign_in_and_redirect(admin) end @@ -249,10 +249,10 @@ class ControllerAuthenticatableTest < ActionController::TestCase end test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do - swap Devise, :sign_out_all_scopes => false do - @mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true) + swap Devise, sign_out_all_scopes: false do + @mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true) @mock_warden.expects(:logout).with(:admin).returns(true) - @mock_warden.expects(:clear_strategies_cache!).with(:scope => :admin).returns(true) + @mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true) @controller.expects(:redirect_to).with(admin_root_path) @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end" @controller.sign_out_and_redirect(:admin) @@ -260,7 +260,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase end test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do - swap Devise, :sign_out_all_scopes => true do + swap Devise, sign_out_all_scopes: true do @mock_warden.expects(:user).times(Devise.mappings.size) @mock_warden.expects(:logout).with().returns(true) @mock_warden.expects(:clear_strategies_cache!).with().returns(true) diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index 07aa6b95..914bab73 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -55,7 +55,7 @@ class HelpersTest < ActionController::TestCase end test 'require no authentication tests current mapping' do - @mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true) + @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true) @mock_warden.expects(:user).with(:user).returns(User.new) @controller.expects(:redirect_to).with(root_path) @controller.send :require_no_authentication @@ -71,7 +71,7 @@ class HelpersTest < ActionController::TestCase end test 'require no authentication sets a flash message' do - @mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true) + @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true) @mock_warden.expects(:user).with(:user).returns(User.new) @controller.expects(:redirect_to).with(root_path) @controller.send :require_no_authentication @@ -79,7 +79,7 @@ class HelpersTest < ActionController::TestCase end test 'signed in resource returns signed in resource for current scope' do - @mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new) + @mock_warden.expects(:authenticate).with(scope: :user).returns(User.new) assert_kind_of User, @controller.signed_in_resource end @@ -100,21 +100,21 @@ class HelpersTest < ActionController::TestCase end test 'uses custom i18n options' do - @controller.stubs(:devise_i18n_options).returns(:default => "devise custom options") + @controller.stubs(:devise_i18n_options).returns(default: "devise custom options") @controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions assert_equal 'devise custom options', flash[:notice] end test 'allows custom i18n options to override resource_name' do I18n.expects(:t).with("custom_resource_name.confirmed", anything) - @controller.stubs(:devise_i18n_options).returns(:resource_name => "custom_resource_name") + @controller.stubs(:devise_i18n_options).returns(resource_name: "custom_resource_name") @controller.send :set_flash_message, :notice, :confirmed end test 'navigational_formats not returning a wild card' do MyController.send(:public, :navigational_formats) - swap Devise, :navigational_formats => ['*/*', :html] do + swap Devise, navigational_formats: ['*/*', :html] do assert_not @controller.navigational_formats.include?("*/*") end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 38ee07d9..f82d1e9d 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -12,9 +12,9 @@ class SessionsControllerTest < ActionController::TestCase request.env["devise.mapping"] = Devise.mappings[:user] request.session["user_return_to"] = 'foo.bar' create_user - post :create, :user => { - :email => "wrong@email.com", - :password => "wrongpassword" + post :create, user: { + email: "wrong@email.com", + password: "wrongpassword" } assert_equal 200, @response.status ensure @@ -23,7 +23,7 @@ class SessionsControllerTest < ActionController::TestCase end test "#create works even with scoped views" do - swap Devise, :scoped_views => true do + swap Devise, scoped_views: true do request.env["devise.mapping"] = Devise.mappings[:user] post :create assert_equal 200, @response.status @@ -37,9 +37,9 @@ class SessionsControllerTest < ActionController::TestCase user = create_user user.confirm! - post :create, :user => { - :email => user.email, - :password => user.password + post :create, user: { + email: user.email, + password: user.password } assert_nil request.session["user_return_to"] @@ -51,9 +51,9 @@ class SessionsControllerTest < ActionController::TestCase user = create_user user.confirm! - post :create, :format => 'json', :user => { - :email => user.email, - :password => user.password + post :create, format: 'json', user: { + email: user.email, + password: user.password } assert_equal 'foo.bar', request.session["user_return_to"] @@ -61,9 +61,9 @@ class SessionsControllerTest < ActionController::TestCase test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do request.env["devise.mapping"] = Devise.mappings[:user] - post :create, :user => { - :email => "nosuchuser@example.com", - :password => "wevdude" + post :create, user: { + email: "nosuchuser@example.com", + password: "wevdude" } assert_equal 200, @response.status assert_template "devise/sessions/new" @@ -73,12 +73,12 @@ class SessionsControllerTest < ActionController::TestCase request.env["devise.mapping"] = Devise.mappings[:user] user = create_user user.confirm! - post :create, :format => 'json', :user => { - :email => user.email, - :password => user.password + post :create, format: 'json', user: { + email: user.email, + password: user.password } - delete :destroy, :format => 'json' + delete :destroy, format: 'json' assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}" assert_equal 204, @response.status end @@ -92,7 +92,7 @@ class SessionsControllerTest < ActionController::TestCase begin assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do - get :new, :user => { :email => "allez viens!" } + get :new, user: { email: "allez viens!" } end ensure ActiveRecord::Base.mass_assignment_sanitizer = :logger diff --git a/test/controllers/url_helpers_test.rb b/test/controllers/url_helpers_test.rb index 1b82bb8f..23ba5f15 100644 --- a/test/controllers/url_helpers_test.rb +++ b/test/controllers/url_helpers_test.rb @@ -14,10 +14,10 @@ class RoutesTest < ActionController::TestCase send(:"#{prepend_path}user_#{name}_url") # Default url params - assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123), - send(:"#{prepend_path}user_#{name}_path", :param => 123) - assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123), - send(:"#{prepend_path}user_#{name}_url", :param => 123) + assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123), + send(:"#{prepend_path}user_#{name}_path", param: 123) + assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123), + send(:"#{prepend_path}user_#{name}_url", param: 123) @request.path = nil # With an object diff --git a/test/delegator_test.rb b/test/delegator_test.rb index 1618be10..65dda06e 100644 --- a/test/delegator_test.rb +++ b/test/delegator_test.rb @@ -14,6 +14,6 @@ class DelegatorTest < ActiveSupport::TestCase end test 'failure_app returns associated failure app by scope in the given environment' do - assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}}) + assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}}) end end diff --git a/test/devise_test.rb b/test/devise_test.rb index 27f46811..2ee39a99 100644 --- a/test/devise_test.rb +++ b/test/devise_test.rb @@ -23,7 +23,7 @@ class DeviseTest < ActiveSupport::TestCase end test 'model options can be configured through Devise' do - swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do + swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do assert_equal 113, Devise.allow_unconfirmed_access_for assert_equal "foo", Devise.pepper end @@ -60,12 +60,12 @@ class DeviseTest < ActiveSupport::TestCase assert_not defined?(Devise::Models::Coconut) Devise::ALL.delete(:coconut) - assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) } + assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) } assert_equal :fruits, Devise::STRATEGIES[:banana] Devise::ALL.delete(:banana) Devise::STRATEGIES.delete(:banana) - assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) } + assert_nothing_raised(Exception) { Devise.add_module(:kivi, controller: :fruits) } assert_equal :fruits, Devise::CONTROLLERS[:kivi] Devise::ALL.delete(:kivi) Devise::CONTROLLERS.delete(:kivi) diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index bab34c28..a057b1da 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -10,7 +10,7 @@ class FailureTest < ActiveSupport::TestCase class FailureWithI18nOptions < Devise::FailureApp def i18n_options(options) - options.merge(:name => 'Steve') + options.merge(name: 'Steve') end end @@ -23,11 +23,11 @@ class FailureTest < ActiveSupport::TestCase 'REQUEST_URI' => 'http://test.host/', 'HTTP_HOST' => 'test.host', 'REQUEST_METHOD' => 'GET', - 'warden.options' => { :scope => :user }, + 'warden.options' => { scope: :user }, 'rack.session' => {}, 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML), 'rack.input' => "", - 'warden' => OpenStruct.new(:message => nil) + 'warden' => OpenStruct.new(message: nil) }.merge!(env_params) @response = (env.delete(:app) || Devise::FailureApp).call(env).to_a @@ -49,8 +49,8 @@ class FailureTest < ActiveSupport::TestCase end test 'returns to the root path if no session path is available' do - swap Devise, :router_name => :fake_app do - call_failure :app => RootFailureApp + swap Devise, router_name: :fake_app do + call_failure app: RootFailureApp assert_equal 302, @response.first assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert] assert_equal 'http://test.host/', @response.second['Location'] @@ -59,7 +59,7 @@ class FailureTest < ActiveSupport::TestCase if Rails.application.config.respond_to?(:relative_url_root) test 'returns to the default redirect location considering the relative url root' do - swap Rails.application.config, :relative_url_root => "/sample" do + swap Rails.application.config, relative_url_root: "/sample" do call_failure assert_equal 302, @response.first assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location'] @@ -68,18 +68,18 @@ class FailureTest < ActiveSupport::TestCase end test 'uses the proxy failure message as symbol' do - call_failure('warden' => OpenStruct.new(:message => :invalid)) + call_failure('warden' => OpenStruct.new(message: :invalid)) assert_equal 'Invalid email or password.', @request.flash[:alert] assert_equal 'http://test.host/users/sign_in', @response.second["Location"] end test 'uses custom i18n options' do - call_failure('warden' => OpenStruct.new(:message => :does_not_exist), :app => FailureWithI18nOptions) + call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions) assert_equal 'User Steve does not exist', @request.flash[:alert] end test 'uses the proxy failure message as string' do - call_failure('warden' => OpenStruct.new(:message => 'Hello world')) + call_failure('warden' => OpenStruct.new(message: 'Hello world')) assert_equal 'Hello world', @request.flash[:alert] assert_equal 'http://test.host/users/sign_in', @response.second["Location"] end @@ -97,14 +97,14 @@ class FailureTest < ActiveSupport::TestCase end test 'works for any navigational format' do - swap Devise, :navigational_formats => [:xml] do + swap Devise, navigational_formats: [:xml] do call_failure('formats' => Mime::XML) assert_equal 302, @response.first end end test 'redirects the correct format if it is a non-html format request' do - swap Devise, :navigational_formats => [:js] do + swap Devise, navigational_formats: [:js] do call_failure('formats' => Mime::JS) assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"] end @@ -140,28 +140,28 @@ class FailureTest < ActiveSupport::TestCase end test 'does not return WWW-authenticate headers if model does not allow' do - swap Devise, :http_authenticatable => false do + swap Devise, http_authenticatable: false do call_failure('formats' => Mime::XML) assert_nil @response.second["WWW-Authenticate"] end end test 'works for any non navigational format' do - swap Devise, :navigational_formats => [] do + swap Devise, navigational_formats: [] do call_failure('formats' => Mime::HTML) assert_equal 401, @response.first end end test 'uses the failure message as response body' do - call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(:message => :invalid)) + call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(message: :invalid)) assert_match 'Invalid email or password.', @response.third.body end context 'on ajax call' do context 'when http_authenticatable_on_xhr is false' do test 'dont return 401 with navigational formats' do - swap Devise, :http_authenticatable_on_xhr => false do + swap Devise, http_authenticatable_on_xhr: false do call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_equal 302, @response.first assert_equal 'http://test.host/users/sign_in', @response.second["Location"] @@ -169,7 +169,7 @@ class FailureTest < ActiveSupport::TestCase end test 'dont return 401 with non navigational formats' do - swap Devise, :http_authenticatable_on_xhr => false do + swap Devise, http_authenticatable_on_xhr: false do call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_equal 302, @response.first assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"] @@ -179,14 +179,14 @@ class FailureTest < ActiveSupport::TestCase context 'when http_authenticatable_on_xhr is true' do test 'return 401' do - swap Devise, :http_authenticatable_on_xhr => true do + swap Devise, http_authenticatable_on_xhr: true do call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_equal 401, @response.first end end test 'skip WWW-Authenticate header' do - swap Devise, :http_authenticatable_on_xhr => true do + swap Devise, http_authenticatable_on_xhr: true do call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_nil @response.second['WWW-Authenticate'] end @@ -198,7 +198,7 @@ class FailureTest < ActiveSupport::TestCase context 'With recall' do test 'calls the original controller if invalid email or password' do env = { - "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" }, + "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" }, "devise.mapping" => Devise.mappings[:user], "warden" => stub_everything } @@ -209,7 +209,7 @@ class FailureTest < ActiveSupport::TestCase test 'calls the original controller if not confirmed email' do env = { - "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed }, + "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed }, "devise.mapping" => Devise.mappings[:user], "warden" => stub_everything } @@ -220,7 +220,7 @@ class FailureTest < ActiveSupport::TestCase test 'calls the original controller if inactive account' do env = { - "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive }, + "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive }, "devise.mapping" => Devise.mappings[:user], "warden" => stub_everything } diff --git a/test/generators/active_record_generator_test.rb b/test/generators/active_record_generator_test.rb index d78c48f8..885e8ad7 100644 --- a/test/generators/active_record_generator_test.rb +++ b/test/generators/active_record_generator_test.rb @@ -30,10 +30,10 @@ if DEVISE_ORM == :active_record run_generator %w(monster) assert_migration "db/migrate/devise_create_monsters.rb" assert_migration "db/migrate/add_devise_to_monsters.rb" - run_generator %w(monster), :behavior => :revoke + run_generator %w(monster), behavior: :revoke assert_no_migration "db/migrate/add_devise_to_monsters.rb" assert_migration "db/migrate/devise_create_monsters.rb" - run_generator %w(monster), :behavior => :revoke + run_generator %w(monster), behavior: :revoke assert_no_file "app/models/monster.rb" assert_no_migration "db/migrate/devise_create_monsters.rb" end @@ -47,11 +47,11 @@ if DEVISE_ORM == :active_record def simulate_inside_engine(engine, namespace) if Rails::Generators.respond_to?(:namespace=) - swap Rails::Generators, :namespace => namespace do + swap Rails::Generators, namespace: namespace do yield end else - swap Rails, :application => engine.instance do + swap Rails, application: engine.instance do yield end end diff --git a/test/generators/devise_generator_test.rb b/test/generators/devise_generator_test.rb index 292e0ab2..b8824680 100644 --- a/test/generators/devise_generator_test.rb +++ b/test/generators/devise_generator_test.rb @@ -18,13 +18,13 @@ class DeviseGeneratorTest < Rails::Generators::TestCase test "route generation for namespaced model names" do run_generator %w(monster/goblin name:string) - match = /devise_for :goblins, :class_name => "Monster::Goblin"/ + match = /devise_for :goblins, class_name: "Monster::Goblin"/ assert_file "config/routes.rb", match end test "route generation with skip routes" do run_generator %w(monster name:string --skip-routes) - match = /devise_for :monsters, :skip => :all/ + match = /devise_for :monsters, skip: :all/ assert_file "config/routes.rb", match end diff --git a/test/generators/mongoid_generator_test.rb b/test/generators/mongoid_generator_test.rb index 1d0a1b26..51802e8e 100644 --- a/test/generators/mongoid_generator_test.rb +++ b/test/generators/mongoid_generator_test.rb @@ -15,7 +15,7 @@ if DEVISE_ORM == :mongoid test "all files are properly deleted" do run_generator %w(monster) - run_generator %w(monster), :behavior => :revoke + run_generator %w(monster), behavior: :revoke assert_no_file "app/models/monster.rb" end end diff --git a/test/generators/views_generator_test.rb b/test/generators/views_generator_test.rb index f4044514..ee9674c8 100644 --- a/test/generators/views_generator_test.rb +++ b/test/generators/views_generator_test.rb @@ -33,7 +33,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase test "Assert views with markerb" do run_generator %w(--markerb) - assert_files nil, :mail_template_engine => "markerb" + assert_files nil, mail_template_engine: "markerb" end def assert_files(scope = nil, options={}) diff --git a/test/helpers/devise_helper_test.rb b/test/helpers/devise_helper_test.rb index f37682e2..540e7a3a 100644 --- a/test/helpers/devise_helper_test.rb +++ b/test/helpers/devise_helper_test.rb @@ -2,16 +2,16 @@ require 'test_helper' class DeviseHelperTest < ActionDispatch::IntegrationTest setup do - model_labels = { :models => { :user => "utilisateur" } } + model_labels = { models: { user: "utilisateur" } } I18n.backend.store_translations :fr, { - :errors => { :messages => { :not_saved => { - :one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.", - :other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs." + errors: { messages: { not_saved: { + one: "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.", + other: "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs." } } }, - :activerecord => model_labels, - :mongoid => model_labels + activerecord: model_labels, + mongoid: model_labels } I18n.locale = 'fr' @@ -24,8 +24,8 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest test 'test errors.messages.not_saved with single error from i18n' do get new_user_registration_path - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user123' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user123' click_button 'Sign up' assert_have_selector '#error_explanation' @@ -39,9 +39,9 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest get new_user_registration_path - fill_in 'email', :with => 'invalid_email' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user321' + fill_in 'email', with: 'invalid_email' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user321' click_button 'Sign up' assert_have_selector '#error_explanation' diff --git a/test/integration/authenticatable_test.rb b/test/integration/authenticatable_test.rb index f44a686a..03940832 100644 --- a/test/integration/authenticatable_test.rb +++ b/test/integration/authenticatable_test.rb @@ -27,7 +27,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest end test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do - swap Devise, :sign_out_all_scopes => false do + swap Devise, sign_out_all_scopes: false do sign_in_as_user sign_in_as_admin get destroy_user_session_path @@ -37,7 +37,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest end test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do - swap Devise, :sign_out_all_scopes => false do + swap Devise, sign_out_all_scopes: false do sign_in_as_user sign_in_as_admin @@ -48,7 +48,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest end test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do - swap Devise, :sign_out_all_scopes => true do + swap Devise, sign_out_all_scopes: true do sign_in_as_user sign_in_as_admin @@ -59,7 +59,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest end test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do - swap Devise, :sign_out_all_scopes => true do + swap Devise, sign_out_all_scopes: true do sign_in_as_user sign_in_as_admin @@ -162,7 +162,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest end test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do - sign_in_as_admin(:active => false) + sign_in_as_admin(active: false) assert warden.authenticated?(:admin) assert_not warden.authenticated?(:user) @@ -172,7 +172,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest end test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do - sign_in_as_admin(:active => true) + sign_in_as_admin(active: true) assert warden.authenticated?(:admin) assert_not warden.authenticated?(:user) @@ -214,7 +214,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest end test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do - sign_in_as_admin(:active => false) + sign_in_as_admin(active: false) assert warden.authenticated?(:admin) assert_not warden.authenticated?(:user) @@ -224,7 +224,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest end test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do - sign_in_as_admin(:active => true) + sign_in_as_admin(active: true) assert warden.authenticated?(:admin) assert_not warden.authenticated?(:user) @@ -277,7 +277,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest assert_equal users_path, session[:"user_return_to"] follow_redirect! - sign_in_as_user :visit => false + sign_in_as_user visit: false assert_current_url '/users' assert_nil session[:"user_return_to"] @@ -293,7 +293,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest assert_equal users_path, session[:"user_return_to"] follow_redirect! - sign_in_as_user :visit => false + sign_in_as_user visit: false assert_current_url '/users' assert_nil session[:"user_return_to"] @@ -392,7 +392,7 @@ end class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest test 'renders the scoped view if turned on and view is available' do - swap Devise, :scoped_views => true do + swap Devise, scoped_views: true do assert_raise Webrat::NotFoundError do sign_in_as_user end @@ -415,7 +415,7 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest end test 'does not render the scoped view if turned off' do - swap Devise, :scoped_views => false do + swap Devise, scoped_views: false do assert_nothing_raised do sign_in_as_user end @@ -423,7 +423,7 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest end test 'does not render the scoped view if not available' do - swap Devise, :scoped_views => true do + swap Devise, scoped_views: true do assert_nothing_raised do sign_in_as_admin end @@ -433,7 +433,7 @@ end class AuthenticationOthersTest < ActionDispatch::IntegrationTest test 'handles unverified requests gets rid of caches' do - swap ApplicationController, :allow_forgery_protection => true do + swap ApplicationController, allow_forgery_protection: true do post exhibit_user_url(1) assert_not warden.authenticated?(:user) @@ -473,12 +473,12 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest test 'sign in with script name' do assert_nothing_raised do get new_user_session_path, {}, "SCRIPT_NAME" => "/omg" - fill_in "email", :with => "user@test.com" + fill_in "email", with: "user@test.com" end end test 'sign in stub in xml format' do - get new_user_session_path(:format => 'xml') + get new_user_session_path(format: 'xml') assert_match '', response.body assert_match /.*<\/user>/m, response.body assert_match '', response.body @@ -486,15 +486,15 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest end test 'sign in stub in json format' do - get new_user_session_path(:format => 'json') + get new_user_session_path(format: 'json') assert_match '{"user":{', response.body assert_match '"email":""', response.body assert_match '"password":null', response.body end test 'sign in stub in json with non attribute key' do - swap Devise, :authentication_keys => [:other_key] do - get new_user_session_path(:format => 'json') + swap Devise, authentication_keys: [:other_key] do + get new_user_session_path(format: 'json') assert_match '{"user":{', response.body assert_match '"other_key":null', response.body assert_match '"password":null', response.body @@ -502,30 +502,30 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest end test 'uses the mapping from router' do - sign_in_as_user :visit => "/as/sign_in" + sign_in_as_user visit: "/as/sign_in" assert warden.authenticated?(:user) assert_not warden.authenticated?(:admin) end test 'sign in with xml format returns xml response' do create_user - post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'} + post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} assert_response :success assert response.body.include? %(\n) end test 'sign in with xml format is idempotent' do - get new_user_session_path(:format => 'xml') + get new_user_session_path(format: 'xml') assert_response :success create_user - post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'} + post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} assert_response :success - get new_user_session_path(:format => 'xml') + get new_user_session_path(format: 'xml') assert_response :success - post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'} + post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} assert_response :success assert response.body.include? %(\n) end @@ -537,27 +537,27 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest assert_current_url '/' sign_in_as_user - get destroy_user_session_path(:format => 'html') + get destroy_user_session_path(format: 'html') assert_response :redirect assert_current_url '/' end test 'sign out with xml format returns no content' do sign_in_as_user - get destroy_user_session_path(:format => 'xml') + get destroy_user_session_path(format: 'xml') assert_response :no_content assert_not warden.authenticated?(:user) end test 'sign out with json format returns no content' do sign_in_as_user - get destroy_user_session_path(:format => 'json') + get destroy_user_session_path(format: 'json') assert_response :no_content assert_not warden.authenticated?(:user) end test 'sign out with non-navigational format via XHR does not redirect' do - swap Devise, :navigational_formats => ['*/*', :html] do + swap Devise, navigational_formats: ['*/*', :html] do sign_in_as_user xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*. assert_response :no_content @@ -567,7 +567,7 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest # Belt and braces ... Perhaps this test is not necessary? test 'sign out with navigational format via XHR does redirect' do - swap Devise, :navigational_formats => ['*/*', :html] do + swap Devise, navigational_formats: ['*/*', :html] do sign_in_as_user xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" } assert_response :redirect @@ -578,7 +578,7 @@ end class AuthenticationKeysTest < ActionDispatch::IntegrationTest test 'missing authentication keys cause authentication to abort' do - swap Devise, :authentication_keys => [:subdomain] do + swap Devise, authentication_keys: [:subdomain] do sign_in_as_user assert_contain "Invalid email or password." assert_not warden.authenticated?(:user) @@ -586,7 +586,7 @@ class AuthenticationKeysTest < ActionDispatch::IntegrationTest end test 'missing authentication keys cause authentication to abort unless marked as not required' do - swap Devise, :authentication_keys => { :email => true, :subdomain => false } do + swap Devise, authentication_keys: { email: true, subdomain: false } do sign_in_as_user assert warden.authenticated?(:user) end @@ -597,15 +597,15 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest test 'request keys are used on authentication' do host! 'foo.bar.baz' - swap Devise, :request_keys => [:subdomain] do - User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user) + swap Devise, request_keys: [:subdomain] do + User.expects(:find_for_authentication).with(subdomain: 'foo', email: 'user@test.com').returns(create_user) sign_in_as_user assert warden.authenticated?(:user) end end test 'invalid request keys raises NoMethodError' do - swap Devise, :request_keys => [:unknown_method] do + swap Devise, request_keys: [:unknown_method] do assert_raise NoMethodError do sign_in_as_user end @@ -617,7 +617,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest test 'blank request keys cause authentication to abort' do host! 'test.com' - swap Devise, :request_keys => [:subdomain] do + swap Devise, request_keys: [:subdomain] do sign_in_as_user assert_contain "Invalid email or password." assert_not warden.authenticated?(:user) @@ -627,7 +627,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest test 'blank request keys cause authentication to abort unless if marked as not required' do host! 'test.com' - swap Devise, :request_keys => { :subdomain => false } do + swap Devise, request_keys: { subdomain: false } do sign_in_as_user assert warden.authenticated?(:user) end @@ -636,7 +636,7 @@ end class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest def sign_in!(scope) - sign_in_as_admin(:visit => send("new_#{scope}_session_path")) + sign_in_as_admin(visit: send("new_#{scope}_session_path")) assert warden.authenticated?(scope) end @@ -692,22 +692,22 @@ end class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest test 'signed in as user redirects when visiting user sign in page' do sign_in_as_user - get new_user_session_path(:format => :html) + get new_user_session_path(format: :html) assert_redirected_to '/' end test 'signed in as admin redirects when visiting admin sign in page' do sign_in_as_admin - get new_admin_session_path(:format => :html) + get new_admin_session_path(format: :html) assert_redirected_to '/admin_area/home' end test 'signed in as both user and admin redirects when visiting admin sign in page' do sign_in_as_user sign_in_as_admin - get new_user_session_path(:format => :html) + get new_user_session_path(format: :html) assert_redirected_to '/' - get new_admin_session_path(:format => :html) + get new_admin_session_path(format: :html) assert_redirected_to '/admin_area/home' end end diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 3bb555d9..510bf12b 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -3,17 +3,17 @@ require 'test_helper' class ConfirmationTest < ActionDispatch::IntegrationTest def visit_user_confirmation_with_token(confirmation_token) - visit user_confirmation_path(:confirmation_token => confirmation_token) + visit user_confirmation_path(confirmation_token: confirmation_token) end def resend_confirmation - user = create_user(:confirm => false) + user = create_user(confirm: false) ActionMailer::Base.deliveries.clear visit new_user_session_path click_link "Didn't receive confirmation instructions?" - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend confirmation instructions' end @@ -39,8 +39,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do - swap Devise, :confirm_within => 3.days do - user = create_user(:confirm => false, :confirmation_sent_at => 4.days.ago) + swap Devise, confirm_within: 3.days do + user = create_user(confirm: false, confirmation_sent_at: 4.days.ago) assert_not user.confirmed? visit_user_confirmation_with_token(user.raw_confirmation_token) @@ -51,8 +51,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'user with valid confirmation token should be able to confirm an account before the token has expired' do - swap Devise, :confirm_within => 3.days do - user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago) + swap Devise, confirm_within: 3.days do + user = create_user(confirm: false, confirmation_sent_at: 2.days.ago) assert_not user.confirmed? visit_user_confirmation_with_token(user.raw_confirmation_token) @@ -65,14 +65,14 @@ class ConfirmationTest < ActionDispatch::IntegrationTest test 'user should be redirected to a custom path after confirmation' do Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1") - user = create_user(:confirm => false) + user = create_user(confirm: false) visit_user_confirmation_with_token(user.raw_confirmation_token) assert_current_url "/?custom=1" end test 'already confirmed user should not be able to confirm the account again' do - user = create_user(:confirm => false) + user = create_user(confirm: false) user.confirmed_at = Time.now user.save visit_user_confirmation_with_token(user.raw_confirmation_token) @@ -82,21 +82,21 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'already confirmed user should not be able to confirm the account again neither request confirmation' do - user = create_user(:confirm => false) + user = create_user(confirm: false) user.confirmed_at = Time.now user.save visit_user_confirmation_with_token(user.raw_confirmation_token) assert_contain 'already confirmed' - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend confirmation instructions' assert_contain 'already confirmed' end test 'not confirmed user with setup to block without confirmation should not be able to sign in' do - swap Devise, :allow_unconfirmed_access_for => 0.days do - sign_in_as_user(:confirm => false) + swap Devise, allow_unconfirmed_access_for: 0.days do + sign_in_as_user(confirm: false) assert_contain 'You have to confirm your account before continuing' assert_not warden.authenticated?(:user) @@ -104,9 +104,9 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'not confirmed user should not see confirmation message if invalid credentials are given' do - swap Devise, :allow_unconfirmed_access_for => 0.days do - sign_in_as_user(:confirm => false) do - fill_in 'password', :with => 'invalid' + swap Devise, allow_unconfirmed_access_for: 0.days do + sign_in_as_user(confirm: false) do + fill_in 'password', with: 'invalid' end assert_contain 'Invalid email or password' @@ -115,8 +115,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'not confirmed user but configured with some days to confirm should be able to sign in' do - swap Devise, :allow_unconfirmed_access_for => 1.day do - sign_in_as_user(:confirm => false) + swap Devise, allow_unconfirmed_access_for: 1.day do + sign_in_as_user(confirm: false) assert_response :success assert warden.authenticated?(:user) @@ -124,8 +124,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'unconfirmed but signed in user should be redirected to their root path' do - swap Devise, :allow_unconfirmed_access_for => 1.day do - user = sign_in_as_user(:confirm => false) + swap Devise, allow_unconfirmed_access_for: 1.day do + user = sign_in_as_user(confirm: false) visit_user_confirmation_with_token(user.raw_confirmation_token) assert_contain 'Your account was successfully confirmed.' @@ -134,57 +134,57 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test 'error message is configurable by resource name' do - store_translations :en, :devise => { - :failure => { :user => { :unconfirmed => "Not confirmed user" } } + store_translations :en, devise: { + failure: { user: { unconfirmed: "Not confirmed user" } } } do - sign_in_as_user(:confirm => false) + sign_in_as_user(confirm: false) assert_contain 'Not confirmed user' end end test 'resent confirmation token with valid E-Mail in XML format should return valid response' do - user = create_user(:confirm => false) - post user_confirmation_path(:format => 'xml'), :user => { :email => user.email } + user = create_user(confirm: false) + post user_confirmation_path(format: 'xml'), user: { email: user.email } assert_response :success assert_equal response.body, {}.to_xml end test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do - create_user(:confirm => false) - post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' } + create_user(confirm: false) + post user_confirmation_path(format: 'xml'), user: { email: 'invalid.test@test.com' } assert_response :unprocessable_entity assert response.body.include? %(\n) end test 'confirm account with valid confirmation token in XML format should return valid response' do - user = create_user(:confirm => false) - get user_confirmation_path(:confirmation_token => user.raw_confirmation_token, :format => 'xml') + user = create_user(confirm: false) + get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml') assert_response :success assert response.body.include? %(\n) end test 'confirm account with invalid confirmation token in XML format should return invalid response' do - create_user(:confirm => false) - get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml') + create_user(confirm: false) + get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml') assert_response :unprocessable_entity assert response.body.include? %(\n) end test 'request an account confirmation account with JSON, should return an empty JSON' do - user = create_user(:confirm => false) + user = create_user(confirm: false) - post user_confirmation_path, :user => { :email => user.email }, :format => :json + post user_confirmation_path, user: { email: user.email }, format: :json assert_response :success assert_equal response.body, {}.to_json end test "when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid" do - swap Devise, :paranoid => true do - user = create_user(:confirm => false) + swap Devise, paranoid: true do + user = create_user(confirm: false) visit new_user_session_path click_link "Didn't receive confirmation instructions?" - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend confirmation instructions' assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." @@ -193,11 +193,11 @@ class ConfirmationTest < ActionDispatch::IntegrationTest end test "when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid" do - swap Devise, :paranoid => true do + swap Devise, paranoid: true do visit new_user_session_path click_link "Didn't receive confirmation instructions?" - fill_in 'email', :with => "idonthavethisemail@gmail.com" + fill_in 'email', with: "idonthavethisemail@gmail.com" click_button 'Resend confirmation instructions' assert_not_contain "1 error prohibited this user from being saved:" @@ -216,17 +216,17 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest end def visit_admin_confirmation_with_token(confirmation_token) - visit admin_confirmation_path(:confirmation_token => confirmation_token) + visit admin_confirmation_path(confirmation_token: confirmation_token) end test 'admin should be able to request a new confirmation after email changed' do admin = create_admin - admin.update_attributes(:email => 'new_test@example.com') + admin.update_attributes(email: 'new_test@example.com') visit new_admin_session_path click_link "Didn't receive confirmation instructions?" - fill_in 'email', :with => admin.unconfirmed_email + fill_in 'email', with: admin.unconfirmed_email assert_difference "ActionMailer::Base.deliveries.size" do click_button 'Resend confirmation instructions' end @@ -237,7 +237,7 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest test 'admin with valid confirmation token should be able to confirm email after email changed' do admin = create_admin - admin.update_attributes(:email => 'new_test@example.com') + admin.update_attributes(email: 'new_test@example.com') assert_equal 'new_test@example.com', admin.unconfirmed_email visit_admin_confirmation_with_token(admin.raw_confirmation_token) @@ -249,13 +249,13 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do admin = create_admin - admin.update_attributes(:email => 'first_test@example.com') + admin.update_attributes(email: 'first_test@example.com') assert_equal 'first_test@example.com', admin.unconfirmed_email raw_confirmation_token = admin.raw_confirmation_token admin = Admin.find(admin.id) - admin.update_attributes(:email => 'second_test@example.com') + admin.update_attributes(email: 'second_test@example.com') assert_equal 'second_test@example.com', admin.unconfirmed_email visit_admin_confirmation_with_token(raw_confirmation_token) @@ -271,10 +271,10 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest test 'admin email should be unique also within unconfirmed_email' do admin = create_admin - admin.update_attributes(:email => 'new_admin_test@example.com') + admin.update_attributes(email: 'new_admin_test@example.com') assert_equal 'new_admin_test@example.com', admin.unconfirmed_email - create_second_admin(:email => "new_admin_test@example.com") + create_second_admin(email: "new_admin_test@example.com") visit_admin_confirmation_with_token(admin.raw_confirmation_token) assert_have_selector '#error_explanation' diff --git a/test/integration/database_authenticatable_test.rb b/test/integration/database_authenticatable_test.rb index 65b7c805..48aed2b8 100644 --- a/test/integration/database_authenticatable_test.rb +++ b/test/integration/database_authenticatable_test.rb @@ -2,21 +2,21 @@ require 'test_helper' class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do - create_user(:email => 'Foo@Bar.com') + create_user(email: 'Foo@Bar.com') sign_in_as_user do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end assert warden.authenticated?(:user) end test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do - swap Devise, :case_insensitive_keys => [] do - create_user(:email => 'Foo@Bar.com') + swap Devise, case_insensitive_keys: [] do + create_user(email: 'Foo@Bar.com') sign_in_as_user do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end assert_not warden.authenticated?(:user) @@ -24,21 +24,21 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest end test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do - create_user(:email => ' foo@bar.com ') + create_user(email: ' foo@bar.com ') sign_in_as_user do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end assert warden.authenticated?(:user) end test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do - swap Devise, :strip_whitespace_keys => [] do - create_user(:email => 'foo@bar.com') + swap Devise, strip_whitespace_keys: [] do + create_user(email: 'foo@bar.com') sign_in_as_user do - fill_in 'email', :with => ' foo@bar.com ' + fill_in 'email', with: ' foo@bar.com ' end assert_not warden.authenticated?(:user) @@ -46,16 +46,16 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest end test 'sign in should not authenticate if not using proper authentication keys' do - swap Devise, :authentication_keys => [:username] do + swap Devise, authentication_keys: [:username] do sign_in_as_user assert_not warden.authenticated?(:user) end end test 'sign in with invalid email should return to sign in form with error message' do - store_translations :en, :devise => { :failure => { :admin => { :not_found_in_database => 'Invalid email address' } } } do + store_translations :en, devise: { failure: { admin: { not_found_in_database: 'Invalid email address' } } } do sign_in_as_admin do - fill_in 'email', :with => 'wrongemail@test.com' + fill_in 'email', with: 'wrongemail@test.com' end assert_contain 'Invalid email address' @@ -65,7 +65,7 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest test 'sign in with invalid pasword should return to sign in form with error message' do sign_in_as_admin do - fill_in 'password', :with => 'abcdef' + fill_in 'password', with: 'abcdef' end assert_contain 'Invalid email or password' @@ -73,9 +73,9 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest end test 'error message is configurable by resource name' do - store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do + store_translations :en, devise: { failure: { admin: { invalid: "Invalid credentials" } } } do sign_in_as_admin do - fill_in 'password', :with => 'abcdef' + fill_in 'password', with: 'abcdef' end assert_contain 'Invalid credentials' diff --git a/test/integration/http_authenticatable_test.rb b/test/integration/http_authenticatable_test.rb index 1934f311..aad51f62 100644 --- a/test/integration/http_authenticatable_test.rb +++ b/test/integration/http_authenticatable_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class HttpAuthenticationTest < ActionDispatch::IntegrationTest test 'handles unverified requests gets rid of caches but continues signed in' do - swap ApplicationController, :allow_forgery_protection => true do + swap ApplicationController, allow_forgery_protection: true do create_user post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}" assert warden.authenticated?(:user) @@ -16,18 +16,18 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest assert_match 'user@test.com', response.body assert warden.authenticated?(:user) - get users_path(:format => :xml) + get users_path(format: :xml) assert_response 200 end test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do - swap Devise, :skip_session_storage => [:http_auth] do + swap Devise, skip_session_storage: [:http_auth] do sign_in_as_new_user_with_http assert_response 200 assert_match 'user@test.com', response.body assert warden.authenticated?(:user) - get users_path(:format => :xml) + get users_path(format: :xml) assert_response 401 end end @@ -46,7 +46,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest end test 'returns a custom response with www-authenticate and chosen realm' do - swap Devise, :http_authentication_realm => "MyApp" do + swap Devise, http_authentication_realm: "MyApp" do sign_in_as_new_user_with_http("unknown") assert_equal 401, status assert_equal 'Basic realm="MyApp"', headers["WWW-Authenticate"] @@ -54,7 +54,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest end test 'sign in should authenticate with http even with specific authentication keys' do - swap Devise, :authentication_keys => [:username] do + swap Devise, authentication_keys: [:username] do sign_in_as_new_user_with_http("usertest") assert_response :success assert_match 'user@test.com', response.body @@ -63,7 +63,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest end test 'it uses appropriate authentication_keys when configured with hash' do - swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:username, false, :email, false] do + swap Devise, authentication_keys: ActiveSupport::OrderedHash[:username, false, :email, false] do sign_in_as_new_user_with_http("usertest") assert_response :success assert_match 'user@test.com', response.body @@ -72,7 +72,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest end test 'it uses the appropriate key when configured explicitly' do - swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:email, false, :username, false], :http_authentication_key => :username do + swap Devise, authentication_keys: ActiveSupport::OrderedHash[:email, false, :username, false], http_authentication_key: :username do sign_in_as_new_user_with_http("usertest") assert_response :success assert_match 'user@test.com', response.body @@ -81,7 +81,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest end test 'test request with oauth2 header doesnt get mistaken for basic authentication' do - swap Devise, :http_authenticatable => true do + swap Devise, http_authenticatable: true do add_oauth2_header assert_equal 401, status assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"] @@ -92,14 +92,14 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest def sign_in_as_new_user_with_http(username="user@test.com", password="12345678") user = create_user - get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}" + get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}" user end # Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication def add_oauth2_header user = create_user - get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}" + get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}" end end diff --git a/test/integration/lockable_test.rb b/test/integration/lockable_test.rb index 3ab7fd60..5fad5d3d 100644 --- a/test/integration/lockable_test.rb +++ b/test/integration/lockable_test.rb @@ -3,18 +3,18 @@ require 'test_helper' class LockTest < ActionDispatch::IntegrationTest def visit_user_unlock_with_token(unlock_token) - visit user_unlock_path(:unlock_token => unlock_token) + visit user_unlock_path(unlock_token: unlock_token) end def send_unlock_request - user = create_user(:locked => true) + user = create_user(locked: true) ActionMailer::Base.deliveries.clear visit new_user_session_path click_link "Didn't receive unlock instructions?" Devise.stubs(:friendly_token).returns("abcdef") - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend unlock instructions' end @@ -39,13 +39,13 @@ class LockTest < ActionDispatch::IntegrationTest end test 'unlocked user should not be able to request a unlock token' do - user = create_user(:locked => false) + user = create_user(locked: false) ActionMailer::Base.deliveries.clear visit new_user_session_path click_link "Didn't receive unlock instructions?" - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend unlock instructions' assert_template 'unlocks/new' @@ -89,60 +89,60 @@ class LockTest < ActionDispatch::IntegrationTest end test "user should not send a new e-mail if already locked" do - user = create_user(:locked => true) + user = create_user(locked: true) user.failed_attempts = User.maximum_attempts + 1 user.save! ActionMailer::Base.deliveries.clear - sign_in_as_user(:password => "invalid") + sign_in_as_user(password: "invalid") assert_contain 'Your account is locked.' assert ActionMailer::Base.deliveries.empty? end test 'error message is configurable by resource name' do - store_translations :en, :devise => { - :failure => {:user => {:locked => "You are locked!"}} + store_translations :en, devise: { + failure: {user: {locked: "You are locked!"}} } do - user = create_user(:locked => true) + user = create_user(locked: true) user.failed_attempts = User.maximum_attempts + 1 user.save! - sign_in_as_user(:password => "invalid") + sign_in_as_user(password: "invalid") assert_contain "You are locked!" end end test "user should not be able to sign in when locked" do - store_translations :en, :devise => { - :failure => {:user => {:locked => "You are locked!"}} + store_translations :en, devise: { + failure: {user: {locked: "You are locked!"}} } do - user = create_user(:locked => true) + user = create_user(locked: true) user.failed_attempts = User.maximum_attempts + 1 user.save! - sign_in_as_user(:password => "123456") + sign_in_as_user(password: "123456") assert_contain "You are locked!" end end test 'user should be able to request a new unlock token via XML request' do - user = create_user(:locked => true) + user = create_user(locked: true) ActionMailer::Base.deliveries.clear - post user_unlock_path(:format => 'xml'), :user => {:email => user.email} + post user_unlock_path(format: 'xml'), user: {email: user.email} assert_response :success assert_equal response.body, {}.to_xml assert_equal 1, ActionMailer::Base.deliveries.size end test 'unlocked user should not be able to request a unlock token via XML request' do - user = create_user(:locked => false) + user = create_user(locked: false) ActionMailer::Base.deliveries.clear - post user_unlock_path(:format => 'xml'), :user => {:email => user.email} + post user_unlock_path(format: 'xml'), user: {email: user.email} assert_response :unprocessable_entity assert response.body.include? %(\n) assert_equal 0, ActionMailer::Base.deliveries.size @@ -152,33 +152,33 @@ class LockTest < ActionDispatch::IntegrationTest user = create_user() raw = user.lock_access! assert user.access_locked? - get user_unlock_path(:format => 'xml', :unlock_token => raw) + get user_unlock_path(format: 'xml', unlock_token: raw) assert_response :success assert response.body.include? %(\n) end test 'user with invalid unlock token should not be able to unlock the account via XML request' do - get user_unlock_path(:format => 'xml', :unlock_token => 'invalid_token') + get user_unlock_path(format: 'xml', unlock_token: 'invalid_token') assert_response :unprocessable_entity assert response.body.include? %(\n) end test "when using json to ask a unlock request, should not return the user" do - user = create_user(:locked => true) - post user_unlock_path(:format => "json", :user => {:email => user.email}) + user = create_user(locked: true) + post user_unlock_path(format: "json", user: {email: user.email}) assert_response :success assert_equal response.body, {}.to_json end test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is locked" do - swap Devise, :paranoid => true do - user = create_user(:locked => true) + swap Devise, paranoid: true do + user = create_user(locked: true) visit new_user_session_path click_link "Didn't receive unlock instructions?" - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend unlock instructions' assert_current_url "/users/sign_in" @@ -187,13 +187,13 @@ class LockTest < ActionDispatch::IntegrationTest end test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is not locked" do - swap Devise, :paranoid => true do - user = create_user(:locked => false) + swap Devise, paranoid: true do + user = create_user(locked: false) visit new_user_session_path click_link "Didn't receive unlock instructions?" - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Resend unlock instructions' assert_current_url "/users/sign_in" @@ -202,11 +202,11 @@ class LockTest < ActionDispatch::IntegrationTest end test "in paranoid mode, when trying to unlock an user that does not exists it should not say that it does not exists" do - swap Devise, :paranoid => true do + swap Devise, paranoid: true do visit new_user_session_path click_link "Didn't receive unlock instructions?" - fill_in 'email', :with => "arandomemail@hotmail.com" + fill_in 'email', with: "arandomemail@hotmail.com" click_button 'Resend unlock instructions' assert_not_contain "1 error prohibited this user from being saved:" @@ -219,16 +219,16 @@ class LockTest < ActionDispatch::IntegrationTest end test "in paranoid mode, when locking a user that exists it should not say that the user was locked" do - swap Devise, :paranoid => true, :maximum_attempts => 1 do - user = create_user(:locked => false) + swap Devise, paranoid: true, maximum_attempts: 1 do + user = create_user(locked: false) visit new_user_session_path - fill_in 'email', :with => user.email - fill_in 'password', :with => "abadpassword" + fill_in 'email', with: user.email + fill_in 'password', with: "abadpassword" click_button 'Sign in' - fill_in 'email', :with => user.email - fill_in 'password', :with => "abadpassword" + fill_in 'email', with: user.email + fill_in 'password', with: "abadpassword" click_button 'Sign in' assert_current_url "/users/sign_in" diff --git a/test/integration/omniauthable_test.rb b/test/integration/omniauthable_test.rb index f73324c2..f131d155 100644 --- a/test/integration/omniauthable_test.rb +++ b/test/integration/omniauthable_test.rb @@ -61,8 +61,8 @@ class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest assert_difference "User.count" do visit "/users/sign_up" - fill_in "Password", :with => "12345678" - fill_in "Password confirmation", :with => "12345678" + fill_in "Password", with: "12345678" + fill_in "Password confirmation", with: "12345678" click_button "Sign up" end @@ -111,7 +111,7 @@ class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest test "generates a proper link when SCRIPT_NAME is set" do header 'SCRIPT_NAME', '/q' visit "/users/sign_in" - assert_select "a", :href => "/q/users/auth/facebook" + assert_select "a", href: "/q/users/auth/facebook" end test "handles callback error parameter according to the specification" do diff --git a/test/integration/recoverable_test.rb b/test/integration/recoverable_test.rb index 92957da4..0bd5019c 100644 --- a/test/integration/recoverable_test.rb +++ b/test/integration/recoverable_test.rb @@ -12,7 +12,7 @@ class PasswordTest < ActionDispatch::IntegrationTest assert_response :success assert_not warden.authenticated?(:user) - fill_in 'email', :with => 'user@test.com' + fill_in 'email', with: 'user@test.com' yield if block_given? Devise.stubs(:friendly_token).returns("abcdef") @@ -21,21 +21,21 @@ class PasswordTest < ActionDispatch::IntegrationTest def reset_password(options={}, &block) unless options[:visit] == false - visit edit_user_password_path(:reset_password_token => options[:reset_password_token] || "abcdef") + visit edit_user_password_path(reset_password_token: options[:reset_password_token] || "abcdef") assert_response :success end - fill_in 'New password', :with => '987654321' - fill_in 'Confirm new password', :with => '987654321' + fill_in 'New password', with: '987654321' + fill_in 'Confirm new password', with: '987654321' yield if block_given? click_button 'Change my password' end test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do - create_user(:email => 'Foo@Bar.com') + create_user(email: 'Foo@Bar.com') request_forgot_password do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end assert_current_url '/users/sign_in' @@ -43,11 +43,11 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'reset password with email should send an email from a custom mailer' do - create_user(:email => 'Foo@Bar.com') + create_user(email: 'Foo@Bar.com') User.any_instance.stubs(:devise_mailer).returns(Users::Mailer) request_forgot_password do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end mail = ActionMailer::Base.deliveries.last @@ -56,11 +56,11 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do - swap Devise, :case_insensitive_keys => [] do - create_user(:email => 'Foo@Bar.com') + swap Devise, case_insensitive_keys: [] do + create_user(email: 'Foo@Bar.com') request_forgot_password do - fill_in 'email', :with => 'foo@bar.com' + fill_in 'email', with: 'foo@bar.com' end assert_response :success @@ -71,10 +71,10 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'reset password with email with extra whitespace should succeed when email is in the list of strip whitespace keys' do - create_user(:email => 'foo@bar.com') + create_user(email: 'foo@bar.com') request_forgot_password do - fill_in 'email', :with => ' foo@bar.com ' + fill_in 'email', with: ' foo@bar.com ' end assert_current_url '/users/sign_in' @@ -82,11 +82,11 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do - swap Devise, :strip_whitespace_keys => [] do - create_user(:email => 'foo@bar.com') + swap Devise, strip_whitespace_keys: [] do + create_user(email: 'foo@bar.com') request_forgot_password do - fill_in 'email', :with => ' foo@bar.com ' + fill_in 'email', with: ' foo@bar.com ' end assert_response :success @@ -116,7 +116,7 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'not authenticated user with invalid email should receive an error message' do request_forgot_password do - fill_in 'email', :with => 'invalid.test@test.com' + fill_in 'email', with: 'invalid.test@test.com' end assert_response :success @@ -141,7 +141,7 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'not authenticated user with invalid reset password token should not be able to change their password' do user = create_user - reset_password :reset_password_token => 'invalid_reset_password' + reset_password reset_password_token: 'invalid_reset_password' assert_response :success assert_current_url '/users/password' @@ -154,7 +154,7 @@ class PasswordTest < ActionDispatch::IntegrationTest user = create_user request_forgot_password reset_password do - fill_in 'Confirm new password', :with => 'other_password' + fill_in 'Confirm new password', with: 'other_password' end assert_response :success @@ -179,12 +179,12 @@ class PasswordTest < ActionDispatch::IntegrationTest user = create_user request_forgot_password - reset_password { fill_in 'Confirm new password', :with => 'other_password' } + reset_password { fill_in 'Confirm new password', with: 'other_password' } assert_response :success assert_have_selector '#error_explanation' assert_not user.reload.valid_password?('987654321') - reset_password :visit => false + reset_password visit: false assert_contain 'Your password was changed successfully.' assert user.reload.valid_password?('987654321') end @@ -199,8 +199,8 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do [:none, :time].each do |strategy| - swap Devise, :unlock_strategy => strategy do - user = create_user(:locked => true) + swap Devise, unlock_strategy: strategy do + user = create_user(locked: true) request_forgot_password reset_password @@ -213,8 +213,8 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :email' do - swap Devise, :unlock_strategy => :email do - user = create_user(:locked => true) + swap Devise, unlock_strategy: :email do + user = create_user(locked: true) request_forgot_password reset_password @@ -225,8 +225,8 @@ class PasswordTest < ActionDispatch::IntegrationTest end test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :both' do - swap Devise, :unlock_strategy => :both do - user = create_user(:locked => true) + swap Devise, unlock_strategy: :both do + user = create_user(locked: true) request_forgot_password reset_password @@ -238,22 +238,22 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'reset password request with valid E-Mail in XML format should return valid response' do create_user - post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"} + post user_password_path(format: 'xml'), user: {email: "user@test.com"} assert_response :success assert_equal response.body, { }.to_xml end test 'reset password request with invalid E-Mail in XML format should return valid response' do create_user - post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"} + post user_password_path(format: 'xml'), user: {email: "invalid.test@test.com"} assert_response :unprocessable_entity assert response.body.include? %(\n) end test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do - swap Devise, :paranoid => true do + swap Devise, paranoid: true do create_user - post user_password_path(:format => 'xml'), :user => {:email => "invalid@test.com"} + post user_password_path(format: 'xml'), user: {email: "invalid@test.com"} assert_response :success assert_equal response.body, { }.to_xml end @@ -262,8 +262,8 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'change password with valid parameters in XML format should return valid response' do create_user request_forgot_password - put user_password_path(:format => 'xml'), :user => { - :reset_password_token => 'abcdef', :password => '987654321', :password_confirmation => '987654321' + put user_password_path(format: 'xml'), user: { + reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321' } assert_response :success assert warden.authenticated?(:user) @@ -272,7 +272,7 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'change password with invalid token in XML format should return invalid response' do create_user request_forgot_password - put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'} + put user_password_path(format: 'xml'), user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} assert_response :unprocessable_entity assert response.body.include? %(\n) end @@ -280,24 +280,24 @@ class PasswordTest < ActionDispatch::IntegrationTest test 'change password with invalid new password in XML format should return invalid response' do user = create_user request_forgot_password - put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'} + put user_password_path(format: 'xml'), user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} assert_response :unprocessable_entity assert response.body.include? %(\n) end test "when using json requests to ask a confirmable request, should not return the object" do - user = create_user(:confirm => false) + user = create_user(confirm: false) - post user_password_path(:format => :json), :user => { :email => user.email } + post user_password_path(format: :json), user: { email: user.email } assert_response :success assert_equal response.body, "{}" end test "when in paranoid mode and with an invalid e-mail, asking to reset a password should display a message that does not indicates that the e-mail does not exists in the database" do - swap Devise, :paranoid => true do + swap Devise, paranoid: true do visit_new_password_path - fill_in "email", :with => "arandomemail@test.com" + fill_in "email", with: "arandomemail@test.com" click_button 'Send me reset password instructions' assert_not_contain "1 error prohibited this user from being saved:" @@ -308,10 +308,10 @@ class PasswordTest < ActionDispatch::IntegrationTest end test "when in paranoid mode and with a valid e-mail, asking to reset password should display a message that does not indicates that the email exists in the database and redirect to the failure route" do - swap Devise, :paranoid => true do + swap Devise, paranoid: true do user = create_user visit_new_password_path - fill_in 'email', :with => user.email + fill_in 'email', with: user.email click_button 'Send me reset password instructions' assert_contain "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index e5e15c3e..ff3a1728 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -8,9 +8,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest assert_template 'registrations/new' - fill_in 'email', :with => 'new_user@test.com' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user123' + fill_in 'email', with: 'new_user@test.com' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user123' click_button 'Sign up' assert_contain 'You have signed up successfully' @@ -26,9 +26,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest get new_admin_session_path click_link 'Sign up' - fill_in 'email', :with => 'new_user@test.com' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user123' + fill_in 'email', with: 'new_user@test.com' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user123' click_button 'Sign up' assert_contain 'Welcome! You have signed up successfully.' @@ -41,9 +41,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest get new_user_registration_path - fill_in 'email', :with => 'new_user@test.com' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user123' + fill_in 'email', with: 'new_user@test.com' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user123' click_button 'Sign up' end @@ -76,9 +76,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1") get new_user_registration_path - fill_in 'email', :with => 'new_user@test.com' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user123' + fill_in 'email', with: 'new_user@test.com' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user123' click_button 'Sign up' assert_current_url "/?custom=1" @@ -92,9 +92,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest get new_user_registration_path - fill_in 'email', :with => 'invalid_email' - fill_in 'password', :with => 'new_user123' - fill_in 'password confirmation', :with => 'new_user321' + fill_in 'email', with: 'invalid_email' + fill_in 'password', with: 'new_user123' + fill_in 'password confirmation', with: 'new_user321' click_button 'Sign up' assert_template 'registrations/new' @@ -116,9 +116,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest create_user get new_user_registration_path - fill_in 'email', :with => 'user@test.com' - fill_in 'password', :with => '123456' - fill_in 'password confirmation', :with => '123456' + fill_in 'email', with: 'user@test.com' + fill_in 'password', with: '123456' + fill_in 'password confirmation', with: '123456' click_button 'Sign up' assert_current_url '/users' @@ -144,8 +144,8 @@ class RegistrationTest < ActionDispatch::IntegrationTest sign_in_as_user get edit_user_registration_path - fill_in 'email', :with => 'user.new@example.com' - fill_in 'current password', :with => '12345678' + fill_in 'email', with: 'user.new@example.com' + fill_in 'current password', with: '12345678' click_button 'Update' assert_current_url '/' @@ -158,9 +158,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest sign_in_as_user get edit_user_registration_path - fill_in 'password', :with => '1234567890' - fill_in 'password confirmation', :with => '1234567890' - fill_in 'current password', :with => '12345678' + fill_in 'password', with: '1234567890' + fill_in 'password confirmation', with: '1234567890' + fill_in 'current password', with: '12345678' click_button 'Update' assert_contain 'You updated your account successfully.' @@ -172,8 +172,8 @@ class RegistrationTest < ActionDispatch::IntegrationTest sign_in_as_user get edit_user_registration_path - fill_in 'email', :with => 'user.new@example.com' - fill_in 'current password', :with => 'invalid' + fill_in 'email', with: 'user.new@example.com' + fill_in 'current password', with: 'invalid' click_button 'Update' assert_template 'registrations/edit' @@ -187,9 +187,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest sign_in_as_user get edit_user_registration_path - fill_in 'password', :with => 'pass1234' - fill_in 'password confirmation', :with => 'pass1234' - fill_in 'current password', :with => '12345678' + fill_in 'password', with: 'pass1234' + fill_in 'password confirmation', with: 'pass1234' + fill_in 'current password', with: '12345678' click_button 'Update' assert_current_url '/' @@ -202,9 +202,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest sign_in_as_user get edit_user_registration_path - fill_in 'password', :with => 'pas123' - fill_in 'password confirmation', :with => '' - fill_in 'current password', :with => '12345678' + fill_in 'password', with: 'pas123' + fill_in 'password confirmation', with: '' + fill_in 'current password', with: '12345678' click_button 'Update' assert_contain Devise.rails4? ? @@ -235,21 +235,21 @@ class RegistrationTest < ActionDispatch::IntegrationTest end test 'a user with XML sign up stub' do - get new_user_registration_path(:format => 'xml') + get new_user_registration_path(format: 'xml') assert_response :success assert_match %(\n), response.body assert_no_match(/ 'json') + get new_user_registration_path(format: 'json') assert_response :success assert_match %({"user":), response.body assert_no_match(/"confirmation_token"/, response.body) end test 'an admin sign up with valid information in XML format should return valid response' do - post admin_registration_path(:format => 'xml'), :admin => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' } + post admin_registration_path(format: 'xml'), admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } assert_response :success assert response.body.include? %(\n) @@ -258,7 +258,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest end test 'a user sign up with valid information in XML format should return valid response' do - post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' } + post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } assert_response :success assert response.body.include? %(\n) @@ -267,28 +267,28 @@ class RegistrationTest < ActionDispatch::IntegrationTest end test 'a user sign up with invalid information in XML format should return invalid response' do - post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'invalid' } + post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } assert_response :unprocessable_entity assert response.body.include? %(\n) end test 'a user update information with valid data in XML format should return valid response' do user = sign_in_as_user - put user_registration_path(:format => 'xml'), :user => { :current_password => '12345678', :email => 'user.new@test.com' } + put user_registration_path(format: 'xml'), user: { current_password: '12345678', email: 'user.new@test.com' } assert_response :success assert_equal user.reload.email, 'user.new@test.com' end test 'a user update information with invalid data in XML format should return invalid response' do user = sign_in_as_user - put user_registration_path(:format => 'xml'), :user => { :current_password => 'invalid', :email => 'user.new@test.com' } + put user_registration_path(format: 'xml'), user: { current_password: 'invalid', email: 'user.new@test.com' } assert_response :unprocessable_entity assert_equal user.reload.email, 'user@test.com' end test 'a user cancel their account in XML format should return valid response' do sign_in_as_user - delete user_registration_path(:format => 'xml') + delete user_registration_path(format: 'xml') assert_response :success assert_equal User.count, 0 end @@ -299,8 +299,8 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest sign_in_as_admin get edit_admin_registration_path - fill_in 'email', :with => 'admin.new@example.com' - fill_in 'current password', :with => '123456' + fill_in 'email', with: 'admin.new@example.com' + fill_in 'current password', with: '123456' click_button 'Update' assert_current_url '/admin_area/home' @@ -315,9 +315,9 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest sign_in_as_admin get edit_admin_registration_path - fill_in 'password', :with => 'pas123' - fill_in 'password confirmation', :with => 'pas123' - fill_in 'current password', :with => '123456' + fill_in 'password', with: 'pas123' + fill_in 'password confirmation', with: 'pas123' + fill_in 'current password', with: '123456' click_button 'Update' assert_current_url '/admin_area/home' @@ -330,14 +330,14 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest sign_in_as_admin get edit_admin_registration_path - fill_in 'email', :with => 'admin.new@example.com' - fill_in 'current password', :with => '123456' + fill_in 'email', with: 'admin.new@example.com' + fill_in 'current password', with: '123456' click_button 'Update' get edit_admin_registration_path - fill_in 'password', :with => 'pas123' - fill_in 'password confirmation', :with => 'pas123' - fill_in 'current password', :with => '123456' + fill_in 'password', with: 'pas123' + fill_in 'password confirmation', with: 'pas123' + fill_in 'current password', with: '123456' click_button 'Update' assert_current_url '/admin_area/home' diff --git a/test/integration/rememberable_test.rb b/test/integration/rememberable_test.rb index 8f04986d..718a7146 100644 --- a/test/integration/rememberable_test.rb +++ b/test/integration/rememberable_test.rb @@ -31,7 +31,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest end test 'handle unverified requests gets rid of caches' do - swap ApplicationController, :allow_forgery_protection => true do + swap ApplicationController, allow_forgery_protection: true do post exhibit_user_url(1) assert_not warden.authenticated?(:user) @@ -43,19 +43,19 @@ class RememberMeTest < ActionDispatch::IntegrationTest end test 'handle unverified requests does not create cookies on sign in' do - swap ApplicationController, :allow_forgery_protection => true do + swap ApplicationController, allow_forgery_protection: true do get new_user_session_path assert request.session[:_csrf_token] - post user_session_path, :authenticity_token => "oops", :user => - { email: "jose.valim@gmail.com", password: "123456", :remember_me => "1" } + post user_session_path, authenticity_token: "oops", user: + { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" } assert_not warden.authenticated?(:user) assert_not request.cookies['remember_user_token'] end end test 'generate remember token after sign in' do - sign_in_as_user :remember_me => true + sign_in_as_user remember_me: true assert request.cookies['remember_user_token'] end @@ -63,15 +63,15 @@ class RememberMeTest < ActionDispatch::IntegrationTest # We test this by asserting the cookie is not sent after the redirect # since we changed the domain. This is the only difference with the # previous test. - swap Devise, :rememberable_options => { :domain => "omg.somewhere.com" } do - sign_in_as_user :remember_me => true + swap Devise, rememberable_options: { domain: "omg.somewhere.com" } do + sign_in_as_user remember_me: true assert_nil request.cookies["remember_user_token"] end end test 'generate remember token with a custom key' do - swap Devise, :rememberable_options => { :key => "v1lat_token" } do - sign_in_as_user :remember_me => true + swap Devise, rememberable_options: { key: "v1lat_token" } do + sign_in_as_user remember_me: true assert request.cookies["v1lat_token"] end end @@ -79,7 +79,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest test 'generate remember token after sign in setting session options' do begin Rails.configuration.session_options[:domain] = "omg.somewhere.com" - sign_in_as_user :remember_me => true + sign_in_as_user remember_me: true assert_nil request.cookies["remember_user_token"] ensure Rails.configuration.session_options.delete(:domain) @@ -103,14 +103,14 @@ class RememberMeTest < ActionDispatch::IntegrationTest end test 'does not extend remember period through sign in' do - swap Devise, :extend_remember_period => true, :remember_for => 1.year do + swap Devise, extend_remember_period: true, remember_for: 1.year do user = create_user user.remember_me! user.remember_created_at = old = 10.days.ago user.save - sign_in_as_user :remember_me => true + sign_in_as_user remember_me: true user.reload assert warden.user(:user) == user @@ -135,7 +135,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest test 'do not remember with expired token' do create_user_and_remember - swap Devise, :remember_for => 0 do + swap Devise, remember_for: 0 do get users_path assert_not warden.authenticated?(:user) assert_redirected_to new_user_session_path diff --git a/test/integration/timeoutable_test.rb b/test/integration/timeoutable_test.rb index 47aea6bf..79f64313 100644 --- a/test/integration/timeoutable_test.rb +++ b/test/integration/timeoutable_test.rb @@ -104,7 +104,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest user = sign_in_as_user get expire_user_path(user) - post "/users/sign_in", :email => user.email, :password => "123456" + post "/users/sign_in", email: user.email, password: "123456" assert_response :redirect follow_redirect! @@ -129,7 +129,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest end test 'user configured timeout limit' do - swap Devise, :timeout_in => 8.minutes do + swap Devise, timeout_in: 8.minutes do user = sign_in_as_user get users_path @@ -145,8 +145,8 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest end test 'error message with i18n' do - store_translations :en, :devise => { - :failure => { :user => { :timeout => 'Session expired!' } } + store_translations :en, devise: { + failure: { user: { timeout: 'Session expired!' } } } do user = sign_in_as_user @@ -158,8 +158,8 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest end test 'error message with i18n with double redirect' do - store_translations :en, :devise => { - :failure => { :user => { :timeout => 'Session expired!' } } + store_translations :en, devise: { + failure: { user: { timeout: 'Session expired!' } } } do user = sign_in_as_user @@ -172,7 +172,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest end test 'time out not triggered if remembered' do - user = sign_in_as_user :remember_me => true + user = sign_in_as_user remember_me: true get expire_user_path(user) assert_not_nil last_request_at diff --git a/test/integration/trackable_test.rb b/test/integration/trackable_test.rb index 44156bfd..f3d73c2e 100644 --- a/test/integration/trackable_test.rb +++ b/test/integration/trackable_test.rb @@ -63,8 +63,8 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest end test "does not update anything if user has signed out along the way" do - swap Devise, :allow_unconfirmed_access_for => 0.days do - user = create_user(:confirm => false) + swap Devise, allow_unconfirmed_access_for: 0.days do + user = create_user(confirm: false) sign_in_as_user user.reload diff --git a/test/mailers/confirmation_instructions_test.rb b/test/mailers/confirmation_instructions_test.rb index 204ab2d2..2d858192 100644 --- a/test/mailers/confirmation_instructions_test.rb +++ b/test/mailers/confirmation_instructions_test.rb @@ -67,13 +67,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase end test 'setup subject from I18n' do - store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do + store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do assert_equal 'Account Confirmation', mail.subject end end test 'subject namespaced by model' do - store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :user_subject => 'User Account Confirmation' } } } do + store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do assert_equal 'User Account Confirmation', mail.subject end end @@ -93,7 +93,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase end test 'renders a scoped if scoped_views is set to true' do - swap Devise, :scoped_views => true do + swap Devise, scoped_views: true do assert_equal user.email, mail.body.decoded end end @@ -108,7 +108,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase end test 'mailer sender accepts a proc' do - swap Devise, :mailer_sender => proc { "another@example.com" } do + swap Devise, mailer_sender: proc { "another@example.com" } do assert_equal ['another@example.com'], mail.from end end diff --git a/test/mailers/reset_password_instructions_test.rb b/test/mailers/reset_password_instructions_test.rb index 4741568a..83f03ec9 100644 --- a/test/mailers/reset_password_instructions_test.rb +++ b/test/mailers/reset_password_instructions_test.rb @@ -63,13 +63,13 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase end test 'setup subject from I18n' do - store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do + store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do assert_equal 'Reset instructions', mail.subject end end test 'subject namespaced by model' do - store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :user_subject => 'User Reset Instructions' } } } do + store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do assert_equal 'User Reset Instructions', mail.subject end end @@ -89,7 +89,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase end test 'mailer sender accepts a proc' do - swap Devise, :mailer_sender => proc { "another@example.com" } do + swap Devise, mailer_sender: proc { "another@example.com" } do assert_equal ['another@example.com'], mail.from end end diff --git a/test/mailers/unlock_instructions_test.rb b/test/mailers/unlock_instructions_test.rb index 324529b0..35be87ef 100644 --- a/test/mailers/unlock_instructions_test.rb +++ b/test/mailers/unlock_instructions_test.rb @@ -64,13 +64,13 @@ class UnlockInstructionsTest < ActionMailer::TestCase end test 'setup subject from I18n' do - store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do + store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do assert_equal 'Yo unlock instructions', mail.subject end end test 'subject namespaced by model' do - store_translations :en, :devise => { :mailer => { :unlock_instructions => { :user_subject => 'User Unlock Instructions' } } } do + store_translations :en, devise: { mailer: { unlock_instructions: { user_subject: 'User Unlock Instructions' } } } do assert_equal 'User Unlock Instructions', mail.subject end end diff --git a/test/models/authenticatable_test.rb b/test/models/authenticatable_test.rb index 9232f910..f57d1bdf 100644 --- a/test/models/authenticatable_test.rb +++ b/test/models/authenticatable_test.rb @@ -6,8 +6,8 @@ class AuthenticatableTest < ActiveSupport::TestCase end test 'find_first_by_auth_conditions allows custom filtering parameters' do - user = User.create!(:email => "example@example.com", :password => "123456") - assert_equal User.find_first_by_auth_conditions({ :email => "example@example.com" }), user - assert_nil User.find_first_by_auth_conditions({ :email => "example@example.com" }, :id => user.id.to_s.next) + user = User.create!(email: "example@example.com", password: "123456") + assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user + assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next) end end diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 8d0b30a5..5de56536 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -82,7 +82,7 @@ class ConfirmableTest < ActiveSupport::TestCase test 'should send confirmation instructions by email' do assert_email_sent "mynewuser@example.com" do - create_user :email => "mynewuser@example.com" + create_user email: "mynewuser@example.com" end end @@ -119,23 +119,23 @@ class ConfirmableTest < ActiveSupport::TestCase assert_email_not_sent do user = new_user user.email = '' - user.save(:validate => false) + user.save(validate: false) end end test 'should find a user to send confirmation instructions' do user = create_user - confirmation_user = User.send_confirmation_instructions(:email => user.email) + confirmation_user = User.send_confirmation_instructions(email: user.email) assert_equal confirmation_user, user end test 'should return a new user if no email was found' do - confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com") + confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com") assert_not confirmation_user.persisted? end test 'should add error to new user email if no email was found' do - confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com") + confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com") assert confirmation_user.errors[:email] assert_equal "not found", confirmation_user.errors[:email].join end @@ -143,7 +143,7 @@ class ConfirmableTest < ActiveSupport::TestCase test 'should send email instructions for the user confirm its email' do user = create_user assert_email_sent user.email do - User.send_confirmation_instructions(:email => user.email) + User.send_confirmation_instructions(email: user.email) end end @@ -183,7 +183,7 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'confirm time should fallback to devise confirm in default configuration' do - swap Devise, :allow_unconfirmed_access_for => 1.day do + swap Devise, allow_unconfirmed_access_for: 1.day do user = new_user user.confirmation_sent_at = 2.days.ago assert_not user.active_for_authentication? @@ -194,7 +194,7 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'should be active when confirmation sent at is not overpast' do - swap Devise, :allow_unconfirmed_access_for => 5.days do + swap Devise, allow_unconfirmed_access_for: 5.days do Devise.allow_unconfirmed_access_for = 5.days user = create_user @@ -246,17 +246,17 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do - swap Devise, :authentication_keys => [:username, :email] do + swap Devise, authentication_keys: [:username, :email] do user = create_user - confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username) + confirm_user = User.send_confirmation_instructions(email: user.email, username: user.username) assert_equal confirm_user, user end end test 'should require all confirmation_keys' do - swap Devise, :confirmation_keys => [:username, :email] do + swap Devise, confirmation_keys: [:username, :email] do user = create_user - confirm_user = User.send_confirmation_instructions(:email => user.email) + confirm_user = User.send_confirmation_instructions(email: user.email) assert_not confirm_user.persisted? assert_equal "can't be blank", confirm_user.errors[:username].join end @@ -275,13 +275,13 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do - swap Devise, :confirm_within => 3.days do + swap Devise, confirm_within: 3.days do assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago) end end test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do - swap Devise, :confirm_within => 3.days do + swap Devise, confirm_within: 3.days do assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago) end end @@ -327,7 +327,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin = create_admin assert admin.confirm! assert_nil admin.confirmation_token - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_not_nil admin.confirmation_token end @@ -335,7 +335,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin = create_admin assert admin.confirm! admin.skip_reconfirmation! - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_nil admin.confirmation_token end @@ -344,16 +344,16 @@ class ReconfirmableTest < ActiveSupport::TestCase admin.skip_confirmation_notification! assert_email_not_sent do - admin.update_attributes(:email => 'new_test@example.com') + admin.update_attributes(email: 'new_test@example.com') end end test 'should regenerate confirmation token after changing email' do admin = create_admin assert admin.confirm! - assert admin.update_attributes(:email => 'old_test@example.com') + assert admin.update_attributes(email: 'old_test@example.com') token = admin.confirmation_token - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_not_equal token, admin.confirmation_token end @@ -361,7 +361,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin = create_admin assert admin.confirm! assert_email_sent "new_test@example.com" do - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') end assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded end @@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin = create_admin assert admin.confirm! assert_email_not_sent do - assert admin.update_attributes(:password => 'newpass', :password_confirmation => 'newpass') + assert admin.update_attributes(password: 'newpass', password_confirmation: 'newpass') end end @@ -379,21 +379,21 @@ class ReconfirmableTest < ActiveSupport::TestCase assert admin.confirm! assert_email_not_sent do admin.email = '' - admin.save(:validate => false) + admin.save(validate: false) end end test 'should stay confirmed when email is changed' do admin = create_admin assert admin.confirm! - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert admin.confirmed? end test 'should update email only when it is confirmed' do admin = create_admin assert admin.confirm! - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_not_equal 'new_test@example.com', admin.email assert admin.confirm! assert_equal 'new_test@example.com', admin.email @@ -402,27 +402,27 @@ class ReconfirmableTest < ActiveSupport::TestCase test 'should not allow admin to get past confirmation email by resubmitting their new address' do admin = create_admin assert admin.confirm! - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_not_equal 'new_test@example.com', admin.email - assert admin.update_attributes(:email => 'new_test@example.com') + assert admin.update_attributes(email: 'new_test@example.com') assert_not_equal 'new_test@example.com', admin.email end test 'should find a admin by send confirmation instructions with unconfirmed_email' do admin = create_admin assert admin.confirm! - assert admin.update_attributes(:email => 'new_test@example.com') - confirmation_admin = Admin.send_confirmation_instructions(:email => admin.unconfirmed_email) + assert admin.update_attributes(email: 'new_test@example.com') + confirmation_admin = Admin.send_confirmation_instructions(email: admin.unconfirmed_email) assert_equal confirmation_admin, admin end test 'should return a new admin if no email or unconfirmed_email was found' do - confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com") + confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com") assert_not confirmation_admin.persisted? end test 'should add error to new admin email if no email or unconfirmed_email was found' do - confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com") + confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com") assert confirmation_admin.errors[:email] assert_equal "not found", confirmation_admin.errors[:email].join end @@ -431,7 +431,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin = create_admin admin.unconfirmed_email = "new_test@email.com" assert admin.save - admin = Admin.find_by_unconfirmed_email_with_errors(:email => "new_test@email.com") + admin = Admin.find_by_unconfirmed_email_with_errors(email: "new_test@email.com") assert admin.persisted? end diff --git a/test/models/database_authenticatable_test.rb b/test/models/database_authenticatable_test.rb index 8ab320c9..fc3f7292 100644 --- a/test/models/database_authenticatable_test.rb +++ b/test/models/database_authenticatable_test.rb @@ -6,7 +6,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should downcase case insensitive keys when saving' do # case_insensitive_keys is set to :email by default. email = 'Foo@Bar.com' - user = new_user(:email => email) + user = new_user(email: email) assert_equal email, user.email user.save! @@ -16,7 +16,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should downcase case insensitive keys that refer to virtual attributes when saving' do email = 'Foo@Bar1.com' confirmation = 'Foo@Bar1.com' - attributes = valid_attributes(:email => email, :email_confirmation => confirmation) + attributes = valid_attributes(email: email, email_confirmation: confirmation) user = UserWithVirtualAttributes.new(attributes) assert_equal confirmation, user.email_confirmation @@ -27,7 +27,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should not mutate value assigned to case insensitive key' do email = 'Foo@Bar.com' original_email = email.dup - user = new_user(:email => email) + user = new_user(email: email) user.save! assert_equal original_email, email @@ -36,7 +36,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should remove whitespace from strip whitespace keys when saving' do # strip_whitespace_keys is set to :email by default. email = ' foo@bar.com ' - user = new_user(:email => email) + user = new_user(email: email) assert_equal email, user.email user.save! @@ -46,20 +46,20 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should not mutate value assigned to string whitespace key' do email = ' foo@bar.com ' original_email = email.dup - user = new_user(:email => email) + user = new_user(email: email) user.save! assert_equal original_email, email end test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do - swap Devise, :strip_whitespace_keys => [:fake_key] do + swap Devise, strip_whitespace_keys: [:fake_key] do assert_nothing_raised { create_user } end end test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do - swap Devise, :case_insensitive_keys => [:fake_key] do + swap Devise, case_insensitive_keys: [:fake_key] do assert_nothing_raised { create_user } end end @@ -94,7 +94,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase end test 'should support custom encryption methods' do - user = UserWithCustomEncryption.new(:password => '654321') + user = UserWithCustomEncryption.new(password: '654321') assert_equal user.encrypted_password, '123456' end @@ -105,8 +105,8 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase end test 'should not generate encrypted password if password is blank' do - assert_blank new_user(:password => nil).encrypted_password - assert_blank new_user(:password => '').encrypted_password + assert_blank new_user(password: nil).encrypted_password + assert_blank new_user(password: '').encrypted_password end test 'should encrypt password again if password has changed' do @@ -141,23 +141,23 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase test 'should update password with valid current password' do user = create_user - assert user.update_with_password(:current_password => '12345678', - :password => 'pass4321', :password_confirmation => 'pass4321') + assert user.update_with_password(current_password: '12345678', + password: 'pass4321', password_confirmation: 'pass4321') assert user.reload.valid_password?('pass4321') end test 'should add an error to current password when it is invalid' do user = create_user - assert_not user.update_with_password(:current_password => 'other', - :password => 'pass4321', :password_confirmation => 'pass4321') + assert_not user.update_with_password(current_password: 'other', + password: 'pass4321', password_confirmation: 'pass4321') assert user.reload.valid_password?('12345678') assert_match "is invalid", user.errors[:current_password].join end test 'should add an error to current password when it is blank' do user = create_user - assert_not user.update_with_password(:password => 'pass4321', - :password_confirmation => 'pass4321') + assert_not user.update_with_password(password: 'pass4321', + password_confirmation: 'pass4321') assert user.reload.valid_password?('12345678') assert_match "can't be blank", user.errors[:current_password].join end @@ -166,41 +166,41 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase user = UserWithValidation.create!(valid_attributes) user.save assert user.persisted? - assert_not user.update_with_password(:username => "") + assert_not user.update_with_password(username: "") assert_match "usertest", user.reload.username assert_match "can't be blank", user.errors[:username].join end test 'should ignore password and its confirmation if they are blank' do user = create_user - assert user.update_with_password(:current_password => '12345678', :email => "new@example.com") + assert user.update_with_password(current_password: '12345678', email: "new@example.com") assert_equal "new@example.com", user.email end test 'should not update password with invalid confirmation' do user = create_user - assert_not user.update_with_password(:current_password => '12345678', - :password => 'pass4321', :password_confirmation => 'other') + assert_not user.update_with_password(current_password: '12345678', + password: 'pass4321', password_confirmation: 'other') assert user.reload.valid_password?('12345678') end test 'should clean up password fields on failure' do user = create_user - assert_not user.update_with_password(:current_password => '12345678', - :password => 'pass4321', :password_confirmation => 'other') + assert_not user.update_with_password(current_password: '12345678', + password: 'pass4321', password_confirmation: 'other') assert user.password.blank? assert user.password_confirmation.blank? end test 'should update the user without password' do user = create_user - user.update_without_password(:email => 'new@example.com') + user.update_without_password(email: 'new@example.com') assert_equal 'new@example.com', user.email end test 'should not update password without password' do user = create_user - user.update_without_password(:password => 'pass4321', :password_confirmation => 'pass4321') + user.update_without_password(password: 'pass4321', password_confirmation: 'pass4321') assert !user.reload.valid_password?('pass4321') assert user.valid_password?('12345678') end @@ -226,8 +226,8 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase end test 'downcase_keys with validation' do - User.create(:email => "HEllO@example.com", :password => "123456") - user = User.create(:email => "HEllO@example.com", :password => "123456") + User.create(email: "HEllO@example.com", password: "123456") + user = User.create(email: "HEllO@example.com", password: "123456") assert !user.valid? end @@ -239,7 +239,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase end test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do - swap Devise, :authentication_keys => [:login] do + swap Devise, authentication_keys: [:login] do assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [ :encrypted_password, :login diff --git a/test/models/lockable_test.rb b/test/models/lockable_test.rb index c371f9c8..7bfb25c6 100644 --- a/test/models/lockable_test.rb +++ b/test/models/lockable_test.rb @@ -8,7 +8,7 @@ class LockableTest < ActiveSupport::TestCase test "should respect maximum attempts configuration" do user = create_user user.confirm! - swap Devise, :maximum_attempts => 2 do + swap Devise, maximum_attempts: 2 do 2.times { user.valid_for_authentication?{ false } } assert user.reload.access_locked? end @@ -18,7 +18,7 @@ class LockableTest < ActiveSupport::TestCase user = create_user user.confirm! - swap Devise, :maximum_attempts => 2 do + swap Devise, maximum_attempts: 2 do 2.times { user.valid_for_authentication?{ false } } assert user.reload.access_locked? end @@ -30,7 +30,7 @@ class LockableTest < ActiveSupport::TestCase test "should not touch failed_attempts if lock_strategy is none" do user = create_user user.confirm! - swap Devise, :lock_strategy => :none, :maximum_attempts => 2 do + swap Devise, lock_strategy: :none, maximum_attempts: 2 do 3.times { user.valid_for_authentication?{ false } } assert !user.access_locked? assert_equal 0, user.failed_attempts @@ -77,7 +77,7 @@ class LockableTest < ActiveSupport::TestCase end test "should unlock user after unlock_in period" do - swap Devise, :unlock_in => 3.hours do + swap Devise, unlock_in: 3.hours do user = new_user user.locked_at = 2.hours.ago assert user.access_locked? @@ -88,7 +88,7 @@ class LockableTest < ActiveSupport::TestCase end test "should not unlock in 'unlock_in' if :time unlock strategy is not set" do - swap Devise, :unlock_strategy => :email do + swap Devise, unlock_strategy: :email do user = new_user user.locked_at = 2.hours.ago assert user.access_locked? @@ -114,7 +114,7 @@ class LockableTest < ActiveSupport::TestCase end test "should not generate unlock_token when :email is not an unlock strategy" do - swap Devise, :unlock_strategy => :time do + swap Devise, unlock_strategy: :time do user = create_user user.lock_access! assert_nil user.unlock_token @@ -122,7 +122,7 @@ class LockableTest < ActiveSupport::TestCase end test "should send email with unlock instructions when :email is an unlock strategy" do - swap Devise, :unlock_strategy => :email do + swap Devise, unlock_strategy: :email do user = create_user assert_email_sent do user.lock_access! @@ -131,7 +131,7 @@ class LockableTest < ActiveSupport::TestCase end test "doesn't send email when you pass option send_instructions to false" do - swap Devise, :unlock_strategy => :email do + swap Devise, unlock_strategy: :email do user = create_user assert_email_not_sent do user.lock_access! send_instructions: false @@ -140,7 +140,7 @@ class LockableTest < ActiveSupport::TestCase end test "sends email when you pass options other than send_instructions" do - swap Devise, :unlock_strategy => :email do + swap Devise, unlock_strategy: :email do user = create_user assert_email_sent do user.lock_access! foo: :bar, bar: :foo @@ -149,7 +149,7 @@ class LockableTest < ActiveSupport::TestCase end test "should not send email with unlock instructions when :email is not an unlock strategy" do - swap Devise, :unlock_strategy => :time do + swap Devise, unlock_strategy: :time do user = create_user assert_email_not_sent do user.lock_access! @@ -180,32 +180,32 @@ class LockableTest < ActiveSupport::TestCase test 'should find a user to send unlock instructions' do user = create_user user.lock_access! - unlock_user = User.send_unlock_instructions(:email => user.email) + unlock_user = User.send_unlock_instructions(email: user.email) assert_equal unlock_user, user end test 'should return a new user if no email was found' do - unlock_user = User.send_unlock_instructions(:email => "invalid@example.com") + unlock_user = User.send_unlock_instructions(email: "invalid@example.com") assert_not unlock_user.persisted? end test 'should add error to new user email if no email was found' do - unlock_user = User.send_unlock_instructions(:email => "invalid@example.com") + unlock_user = User.send_unlock_instructions(email: "invalid@example.com") assert_equal 'not found', unlock_user.errors[:email].join end test 'should find a user to send unlock instructions by authentication_keys' do - swap Devise, :authentication_keys => [:username, :email] do + swap Devise, authentication_keys: [:username, :email] do user = create_user - unlock_user = User.send_unlock_instructions(:email => user.email, :username => user.username) + unlock_user = User.send_unlock_instructions(email: user.email, username: user.username) assert_equal unlock_user, user end end test 'should require all unlock_keys' do - swap Devise, :unlock_keys => [:username, :email] do + swap Devise, unlock_keys: [:username, :email] do user = create_user - unlock_user = User.send_unlock_instructions(:email => user.email) + unlock_user = User.send_unlock_instructions(email: user.email) assert_not unlock_user.persisted? assert_equal "can't be blank", unlock_user.errors[:username].join end @@ -219,7 +219,7 @@ class LockableTest < ActiveSupport::TestCase end test 'should not be able to send instructions if the user if not locked and have username as unlock key' do - swap Devise, :unlock_keys => [:username] do + swap Devise, unlock_keys: [:username] do user = create_user assert_not user.resend_unlock_instructions assert_not user.access_locked? @@ -228,7 +228,7 @@ class LockableTest < ActiveSupport::TestCase end test 'should unlock account if lock has expired and increase attempts on failure' do - swap Devise, :unlock_in => 1.minute do + swap Devise, unlock_in: 1.minute do user = create_user user.confirm! @@ -241,7 +241,7 @@ class LockableTest < ActiveSupport::TestCase end test 'should unlock account if lock has expired on success' do - swap Devise, :unlock_in => 1.minute do + swap Devise, unlock_in: 1.minute do user = create_user user.confirm! @@ -255,8 +255,8 @@ class LockableTest < ActiveSupport::TestCase end test 'required_fields should contain the all the fields when all the strategies are enabled' do - swap Devise, :unlock_strategy => :both do - swap Devise, :lock_strategy => :failed_attempts do + swap Devise, unlock_strategy: :both do + swap Devise, lock_strategy: :failed_attempts do assert_same_content Devise::Models::Lockable.required_fields(User), [ :failed_attempts, :locked_at, @@ -267,8 +267,8 @@ class LockableTest < ActiveSupport::TestCase end test 'required_fields should contain only failed_attempts and locked_at when the strategies are time and failed_attempts are enabled' do - swap Devise, :unlock_strategy => :time do - swap Devise, :lock_strategy => :failed_attempts do + swap Devise, unlock_strategy: :time do + swap Devise, lock_strategy: :failed_attempts do assert_same_content Devise::Models::Lockable.required_fields(User), [ :failed_attempts, :locked_at @@ -278,8 +278,8 @@ class LockableTest < ActiveSupport::TestCase end test 'required_fields should contain only failed_attempts and unlock_token when the strategies are token and failed_attempts are enabled' do - swap Devise, :unlock_strategy => :email do - swap Devise, :lock_strategy => :failed_attempts do + swap Devise, unlock_strategy: :email do + swap Devise, lock_strategy: :failed_attempts do assert_same_content Devise::Models::Lockable.required_fields(User), [ :failed_attempts, :unlock_token @@ -289,7 +289,7 @@ class LockableTest < ActiveSupport::TestCase end test 'should not return a locked unauthenticated message if in paranoid mode' do - swap Devise, :paranoid => :true do + swap Devise, paranoid: :true do user = create_user user.failed_attempts = Devise.maximum_attempts + 1 user.lock_access! @@ -299,8 +299,8 @@ class LockableTest < ActiveSupport::TestCase end test 'should return last attempt message if user made next-to-last attempt of password entering' do - swap Devise, :last_attempt_warning => :true do - swap Devise, :lock_strategy => :failed_attempts do + swap Devise, last_attempt_warning: :true do + swap Devise, lock_strategy: :failed_attempts do user = create_user user.failed_attempts = Devise.maximum_attempts - 2 assert_equal :invalid, user.unauthenticated_message diff --git a/test/models/recoverable_test.rb b/test/models/recoverable_test.rb index f6afc20c..a59f06a7 100644 --- a/test/models/recoverable_test.rb +++ b/test/models/recoverable_test.rb @@ -67,28 +67,28 @@ class RecoverableTest < ActiveSupport::TestCase test 'should find a user to send instructions by email' do user = create_user - reset_password_user = User.send_reset_password_instructions(:email => user.email) + reset_password_user = User.send_reset_password_instructions(email: user.email) assert_equal reset_password_user, user end test 'should return a new record with errors if user was not found by e-mail' do - reset_password_user = User.send_reset_password_instructions(:email => "invalid@example.com") + reset_password_user = User.send_reset_password_instructions(email: "invalid@example.com") assert_not reset_password_user.persisted? assert_equal "not found", reset_password_user.errors[:email].join end test 'should find a user to send instructions by authentication_keys' do - swap Devise, :authentication_keys => [:username, :email] do + swap Devise, authentication_keys: [:username, :email] do user = create_user - reset_password_user = User.send_reset_password_instructions(:email => user.email, :username => user.username) + reset_password_user = User.send_reset_password_instructions(email: user.email, username: user.username) assert_equal reset_password_user, user end end test 'should require all reset_password_keys' do - swap Devise, :reset_password_keys => [:username, :email] do + swap Devise, reset_password_keys: [:username, :email] do user = create_user - reset_password_user = User.send_reset_password_instructions(:email => user.email) + reset_password_user = User.send_reset_password_instructions(email: user.email) assert_not reset_password_user.persisted? assert_equal "can't be blank", reset_password_user.errors[:username].join end @@ -97,14 +97,14 @@ class RecoverableTest < ActiveSupport::TestCase test 'should reset reset_password_token before send the reset instructions email' do user = create_user token = user.reset_password_token - User.send_reset_password_instructions(:email => user.email) + User.send_reset_password_instructions(email: user.email) assert_not_equal token, user.reload.reset_password_token end test 'should send email instructions to the user reset their password' do user = create_user assert_email_sent do - User.send_reset_password_instructions(:email => user.email) + User.send_reset_password_instructions(email: user.email) end end @@ -112,18 +112,18 @@ class RecoverableTest < ActiveSupport::TestCase user = create_user raw = user.send_reset_password_instructions - reset_password_user = User.reset_password_by_token(:reset_password_token => raw) + reset_password_user = User.reset_password_by_token(reset_password_token: raw) assert_equal reset_password_user, user end test 'should return a new record with errors if no reset_password_token is found' do - reset_password_user = User.reset_password_by_token(:reset_password_token => 'invalid_token') + reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token') assert_not reset_password_user.persisted? assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join end test 'should return a new record with errors if reset_password_token is blank' do - reset_password_user = User.reset_password_by_token(:reset_password_token => '') + reset_password_user = User.reset_password_by_token(reset_password_token: '') assert_not reset_password_user.persisted? assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join end @@ -132,7 +132,7 @@ class RecoverableTest < ActiveSupport::TestCase user = create_user raw = user.send_reset_password_instructions - reset_password_user = User.reset_password_by_token(:reset_password_token => raw, :password => '') + reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '') assert_not reset_password_user.errors.empty? assert_match "can't be blank", reset_password_user.errors[:password].join end @@ -143,9 +143,9 @@ class RecoverableTest < ActiveSupport::TestCase raw = user.send_reset_password_instructions User.reset_password_by_token( - :reset_password_token => raw, - :password => 'new_password', - :password_confirmation => 'new_password' + reset_password_token: raw, + password: 'new_password', + password_confirmation: 'new_password' ) user.reload @@ -154,7 +154,7 @@ class RecoverableTest < ActiveSupport::TestCase end test 'should not reset password after reset_password_within time' do - swap Devise, :reset_password_within => 1.hour do + swap Devise, reset_password_within: 1.hour do user = create_user raw = user.send_reset_password_instructions @@ -163,9 +163,9 @@ class RecoverableTest < ActiveSupport::TestCase user.save! reset_password_user = User.reset_password_by_token( - :reset_password_token => raw, - :password => 'new_password', - :password_confirmation => 'new_password' + reset_password_token: raw, + password: 'new_password', + password_confirmation: 'new_password' ) user.reload diff --git a/test/models/rememberable_test.rb b/test/models/rememberable_test.rb index 4607e6d5..74e37f2a 100644 --- a/test/models/rememberable_test.rb +++ b/test/models/rememberable_test.rb @@ -86,7 +86,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'remember for should fallback to devise remember for default configuration' do - swap Devise, :remember_for => 1.day do + swap Devise, remember_for: 1.day do resource = create_resource resource.remember_me! assert_not resource.remember_expired? @@ -94,7 +94,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'remember expires at should sum date of creation with remember for configuration' do - swap Devise, :remember_for => 3.days do + swap Devise, remember_for: 3.days do resource = create_resource resource.remember_me! assert_equal 3.days.from_now.to_date, resource.remember_expires_at.to_date @@ -105,7 +105,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'remember should be expired if remember_for is zero' do - swap Devise, :remember_for => 0.days do + swap Devise, remember_for: 0.days do Devise.remember_for = 0.days resource = create_resource resource.remember_me! @@ -114,7 +114,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'remember should be expired if it was created before limit time' do - swap Devise, :remember_for => 1.day do + swap Devise, remember_for: 1.day do resource = create_resource resource.remember_me! resource.remember_created_at = 2.days.ago @@ -124,7 +124,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'remember should not be expired if it was created within the limit time' do - swap Devise, :remember_for => 30.days do + swap Devise, remember_for: 30.days do resource = create_resource resource.remember_me! resource.remember_created_at = (30.days.ago + 2.minutes) @@ -134,7 +134,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'if extend_remember_period is false, remember_me! should generate a new timestamp if expired' do - swap Devise, :remember_for => 5.minutes do + swap Devise, remember_for: 5.minutes do resource = create_resource resource.remember_me!(false) assert resource.remember_created_at @@ -148,7 +148,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'if extend_remember_period is false, remember_me! should not generate a new timestamp' do - swap Devise, :remember_for => 1.year do + swap Devise, remember_for: 1.year do resource = create_resource resource.remember_me!(false) assert resource.remember_created_at @@ -162,7 +162,7 @@ class RememberableTest < ActiveSupport::TestCase end test 'if extend_remember_period is true, remember_me! should always generate a new timestamp' do - swap Devise, :remember_for => 1.year do + swap Devise, remember_for: 1.year do resource = create_resource resource.remember_me!(true) assert resource.remember_created_at diff --git a/test/models/serializable_test.rb b/test/models/serializable_test.rb index 565b71fe..7e16f74f 100644 --- a/test/models/serializable_test.rb +++ b/test/models/serializable_test.rb @@ -11,13 +11,13 @@ class SerializableTest < ActiveSupport::TestCase end test 'should not include unsafe keys on XML even if a new except is provided' do - assert_no_match(/email/, @user.to_xml(:except => :email)) - assert_no_match(/confirmation-token/, @user.to_xml(:except => :email)) + assert_no_match(/email/, @user.to_xml(except: :email)) + assert_no_match(/confirmation-token/, @user.to_xml(except: :email)) end test 'should include unsafe keys on XML if a force_except is provided' do - assert_no_match(/ :email)) - assert_match(/confirmation-token/, @user.to_xml(:force_except => :email)) + assert_no_match(/ :email) - assert_no_key "confirmation_token", from_json(:except => :email) + assert_no_key "email", from_json(except: :email) + assert_no_key "confirmation_token", from_json(except: :email) end test 'should include unsafe keys on JSON if a force_except is provided' do - assert_no_key "email", from_json(:force_except => :email) - assert_key "confirmation_token", from_json(:force_except => :email) + assert_no_key "email", from_json(force_except: :email) + assert_key "confirmation_token", from_json(force_except: :email) end def assert_key(key, subject) diff --git a/test/models/timeoutable_test.rb b/test/models/timeoutable_test.rb index b25cb2ed..be682467 100644 --- a/test/models/timeoutable_test.rb +++ b/test/models/timeoutable_test.rb @@ -29,7 +29,7 @@ class TimeoutableTest < ActiveSupport::TestCase end test 'fallback to Devise config option' do - swap Devise, :timeout_in => 1.minute do + swap Devise, timeout_in: 1.minute do user = new_user assert user.timedout?(2.minutes.ago) assert_not user.timedout?(30.seconds.ago) diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index 983628f6..c73b4389 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class ValidatableTest < ActiveSupport::TestCase test 'should require email to be set' do - user = new_user(:email => nil) + user = new_user(email: nil) assert user.invalid? assert user.errors[:email] assert_equal 'can\'t be blank', user.errors[:email].join @@ -12,7 +12,7 @@ class ValidatableTest < ActiveSupport::TestCase test 'should require uniqueness of email if email has changed, allowing blank' do existing_user = create_user - user = new_user(:email => '') + user = new_user(email: '') assert user.invalid? assert_no_match(/taken/, user.errors[:email].join) @@ -20,12 +20,12 @@ class ValidatableTest < ActiveSupport::TestCase assert user.invalid? assert_match(/taken/, user.errors[:email].join) - user.save(:validate => false) + user.save(validate: false) assert user.valid? end test 'should require correct email format if email has changed, allowing blank' do - user = new_user(:email => '') + user = new_user(email: '') assert user.invalid? assert_not_equal 'is invalid', user.errors[:email].join @@ -35,26 +35,26 @@ class ValidatableTest < ActiveSupport::TestCase assert_equal 'is invalid', user.errors[:email].join end - user.save(:validate => false) + user.save(validate: false) assert user.valid? end test 'should accept valid emails' do %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email| - user = new_user(:email => email) + user = new_user(email: email) assert user.valid?, 'should be valid with email ' << email assert_blank user.errors[:email] end end test 'should require password to be set when creating a new record' do - user = new_user(:password => '', :password_confirmation => '') + user = new_user(password: '', password_confirmation: '') assert user.invalid? assert_equal 'can\'t be blank', user.errors[:password].join end test 'should require confirmation to be set when creating a new record' do - user = new_user(:password => 'new_password', :password_confirmation => 'blabla') + user = new_user(password: 'new_password', password_confirmation: 'blabla') assert user.invalid? if Devise.rails4? @@ -87,13 +87,13 @@ class ValidatableTest < ActiveSupport::TestCase end test 'should require a password with minimum of 6 characters' do - user = new_user(:password => '12345', :password_confirmation => '12345') + user = new_user(password: '12345', password_confirmation: '12345') assert user.invalid? assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join end test 'should require a password with maximum of 128 characters long' do - user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129) + user = new_user(password: 'x'*129, password_confirmation: 'x'*129) assert user.invalid? assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join end @@ -109,7 +109,7 @@ class ValidatableTest < ActiveSupport::TestCase end test 'should complain about length even if password is not required' do - user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129) + user = new_user(password: 'x'*129, password_confirmation: 'x'*129) user.stubs(:password_required?).returns(false) assert user.invalid? assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join diff --git a/test/omniauth/config_test.rb b/test/omniauth/config_test.rb index f53a5d73..86e96634 100644 --- a/test/omniauth/config_test.rb +++ b/test/omniauth/config_test.rb @@ -11,12 +11,12 @@ class OmniAuthConfigTest < ActiveSupport::TestCase end test 'strategy_name returns provider if no name option are given' do - config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }] + config = Devise::OmniAuth::Config.new :facebook, [{ other: :option }] assert_equal :facebook, config.strategy_name end test 'returns name option when have a name' do - config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }] + config = Devise::OmniAuth::Config.new :facebook, [{ name: :github }] assert_equal :github, config.strategy_name end @@ -50,7 +50,7 @@ class OmniAuthConfigTest < ActiveSupport::TestCase end test 'allows the user to define a custom require path' do - config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}] + config = Devise::OmniAuth::Config.new :my_strategy, [{strategy_class: MyStrategy}] config_class = config.strategy_class assert_equal MyStrategy, config_class end diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index 9a8b4653..6f9c80e9 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -17,8 +17,8 @@ class OmniAuthRoutesTest < ActionController::TestCase if with_param # Default url params - assert_equal @controller.send(action, :user, provider, :param => 123), - @controller.send("user_#{action}", provider, :param => 123) + assert_equal @controller.send(action, :user, provider, param: 123), + @controller.send("user_#{action}", provider, param: 123) end end @@ -44,7 +44,7 @@ class OmniAuthRoutesTest < ActionController::TestCase test 'should generate authorization path with params' do assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com", - @controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com") + @controller.omniauth_authorize_path(:user, :openid, openid_url: "http://yahoo.com") end test 'should not add a "?" if no param was sent' do diff --git a/test/parameter_sanitizer_test.rb b/test/parameter_sanitizer_test.rb index cd48b382..f086cf9b 100644 --- a/test/parameter_sanitizer_test.rb +++ b/test/parameter_sanitizer_test.rb @@ -27,7 +27,7 @@ if defined?(ActionController::StrongParameters) end test 'handles auth keys as a hash' do - swap Devise, :authentication_keys => {:email => true} do + swap Devise, authentication_keys: {email: true} do sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid" }) assert_equal({ "email" => "jose", "password" => "invalid" }, sanitizer.sanitize(:sign_in)) end diff --git a/test/rails_app/app/controllers/admins_controller.rb b/test/rails_app/app/controllers/admins_controller.rb index 538eb41c..2b4837cf 100644 --- a/test/rails_app/app/controllers/admins_controller.rb +++ b/test/rails_app/app/controllers/admins_controller.rb @@ -6,6 +6,6 @@ class AdminsController < ApplicationController def expire admin_session['last_request_at'] = 31.minutes.ago.utc - render :text => 'Admin will be expired on next request' + render text: 'Admin will be expired on next request' end end diff --git a/test/rails_app/app/controllers/application_controller.rb b/test/rails_app/app/controllers/application_controller.rb index 30b1677a..a3153ffa 100644 --- a/test/rails_app/app/controllers/application_controller.rb +++ b/test/rails_app/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery - before_filter :current_user, :unless => :devise_controller? - before_filter :authenticate_user!, :if => :devise_controller? + before_filter :current_user, unless: :devise_controller? + before_filter :authenticate_user!, if: :devise_controller? respond_to *Mime::SET.map(&:to_sym) end diff --git a/test/rails_app/app/controllers/home_controller.rb b/test/rails_app/app/controllers/home_controller.rb index 19a787bd..c6471953 100644 --- a/test/rails_app/app/controllers/home_controller.rb +++ b/test/rails_app/app/controllers/home_controller.rb @@ -20,6 +20,6 @@ class HomeController < ApplicationController end def unauthenticated - render :text => "unauthenticated", :status => :unauthorized + render text: "unauthenticated", status: :unauthorized end end diff --git a/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb b/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb index 0ee486e7..a3b1e1e5 100644 --- a/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +++ b/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb @@ -2,13 +2,13 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook data = env["omniauth.auth"] session["devise.facebook_data"] = data["extra"]["user_hash"] - render :json => data + render json: data end def sign_in_facebook user = User.find_by_email('user@test.com') user.remember_me = true sign_in user - render :text => "" + render text: "" end end diff --git a/test/rails_app/app/controllers/users_controller.rb b/test/rails_app/app/controllers/users_controller.rb index d889de69..839e194e 100644 --- a/test/rails_app/app/controllers/users_controller.rb +++ b/test/rails_app/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController - prepend_before_filter :current_user, :only => :exhibit - before_filter :authenticate_user!, :except => [:accept, :exhibit] + prepend_before_filter :current_user, only: :exhibit + before_filter :authenticate_user!, except: [:accept, :exhibit] respond_to :html, :xml def index @@ -13,7 +13,7 @@ class UsersController < ApplicationController end def update_form - render :text => 'Update' + render text: 'Update' end def accept @@ -21,11 +21,11 @@ class UsersController < ApplicationController end def exhibit - render :text => current_user ? "User is authenticated" : "User is not authenticated" + render text: current_user ? "User is authenticated" : "User is not authenticated" end def expire user_session['last_request_at'] = 31.minutes.ago.utc - render :text => 'User will be expired on next request' + render text: 'User will be expired on next request' end end diff --git a/test/rails_app/app/mailers/users/mailer.rb b/test/rails_app/app/mailers/users/mailer.rb index f81d49ca..8359d6a5 100644 --- a/test/rails_app/app/mailers/users/mailer.rb +++ b/test/rails_app/app/mailers/users/mailer.rb @@ -1,12 +1,12 @@ class Users::Mailer < Devise::Mailer - default :from => 'custom@example.com' + default from: 'custom@example.com' end class Users::ReplyToMailer < Devise::Mailer - default :from => 'custom@example.com' - default :reply_to => 'custom_reply_to@example.com' + default from: 'custom@example.com' + default reply_to: 'custom_reply_to@example.com' end class Users::FromProcMailer < Devise::Mailer - default :from => proc { 'custom@example.com' } + default from: proc { 'custom@example.com' } end diff --git a/test/rails_app/app/mongoid/admin.rb b/test/rails_app/app/mongoid/admin.rb index dea2cc90..d5884cb6 100644 --- a/test/rails_app/app/mongoid/admin.rb +++ b/test/rails_app/app/mongoid/admin.rb @@ -6,24 +6,24 @@ class Admin include SharedAdmin ## Database authenticatable - field :email, :type => String - field :encrypted_password, :type => String + field :email, type: String + field :encrypted_password, type: String ## Recoverable - field :reset_password_token, :type => String - field :reset_password_sent_at, :type => Time + field :reset_password_token, type: String + field :reset_password_sent_at, type: Time ## Rememberable - field :remember_created_at, :type => Time + field :remember_created_at, type: Time ## Confirmable - field :confirmation_token, :type => String - field :confirmed_at, :type => Time - field :confirmation_sent_at, :type => Time - field :unconfirmed_email, :type => String # Only if using reconfirmable + field :confirmation_token, type: String + field :confirmed_at, type: Time + field :confirmation_sent_at, type: Time + field :unconfirmed_email, type: String # Only if using reconfirmable ## Lockable - field :locked_at, :type => Time + field :locked_at, type: Time - field :active, :type => Boolean, :default => false + field :active, type: Boolean, default: false end diff --git a/test/rails_app/app/mongoid/shim.rb b/test/rails_app/app/mongoid/shim.rb index f74e8711..cd48fd40 100644 --- a/test/rails_app/app/mongoid/shim.rb +++ b/test/rails_app/app/mongoid/shim.rb @@ -3,7 +3,7 @@ module Shim included do include ::Mongoid::Timestamps - field :created_at, :type => DateTime + field :created_at, type: DateTime end module ClassMethods @@ -12,7 +12,7 @@ module Shim end def find_by_email(email) - find_by(:email => email) + find_by(email: email) end end diff --git a/test/rails_app/app/mongoid/user.rb b/test/rails_app/app/mongoid/user.rb index 867758ea..0a2e5ea1 100644 --- a/test/rails_app/app/mongoid/user.rb +++ b/test/rails_app/app/mongoid/user.rb @@ -5,35 +5,35 @@ class User include Shim include SharedUser - field :username, :type => String - field :facebook_token, :type => String + field :username, type: String + field :facebook_token, type: String ## Database authenticatable - field :email, :type => String, :default => "" - field :encrypted_password, :type => String, :default => "" + field :email, type: String, default: "" + field :encrypted_password, type: String, default: "" ## Recoverable - field :reset_password_token, :type => String - field :reset_password_sent_at, :type => Time + field :reset_password_token, type: String + field :reset_password_sent_at, type: Time ## Rememberable - field :remember_created_at, :type => Time + field :remember_created_at, type: Time ## Trackable - field :sign_in_count, :type => Integer, :default => 0 - field :current_sign_in_at, :type => Time - field :last_sign_in_at, :type => Time - field :current_sign_in_ip, :type => String - field :last_sign_in_ip, :type => String + field :sign_in_count, type: Integer, default: 0 + field :current_sign_in_at, type: Time + field :last_sign_in_at, type: Time + field :current_sign_in_ip, type: String + field :last_sign_in_ip, type: String ## Confirmable - field :confirmation_token, :type => String - field :confirmed_at, :type => Time - field :confirmation_sent_at, :type => Time - # field :unconfirmed_email, :type => String # Only if using reconfirmable + field :confirmation_token, type: String + field :confirmed_at, type: Time + field :confirmation_sent_at, type: Time + # field :unconfirmed_email, type: String # Only if using reconfirmable ## Lockable - field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts - field :unlock_token, :type => String # Only if unlock strategy is :email or :both - field :locked_at, :type => Time + field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts + field :unlock_token, type: String # Only if unlock strategy is :email or :both + field :locked_at, type: Time end diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index 5744dae7..46140549 100644 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -23,14 +23,14 @@ module RailsApp # config.generators do |g| # g.orm :active_record # g.template_engine :erb - # g.test_framework :test_unit, :fixture => true + # g.test_framework :test_unit, fixture: true # end # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters << :password config.assets.enabled = false - config.action_mailer.default_url_options = { :host => "localhost:3000" } + config.action_mailer.default_url_options = { host: "localhost:3000" } # This was used to break devise in some situations config.to_prepare do diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 3e2506d2..81d7a248 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -166,9 +166,9 @@ Devise.setup do |config| # config.sign_out_via = :get # ==> OmniAuth - config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access' + config.omniauth :facebook, 'APP_ID', 'APP_SECRET', scope: 'email,offline_access' config.omniauth :openid - config.omniauth :openid, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id' + config.omniauth :openid, name: 'google', identifier: 'https://www.google.com/accounts/o8/id' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or @@ -176,6 +176,6 @@ Devise.setup do |config| # # config.warden do |manager| # manager.failure_app = AnotherApp - # manager.default_strategies(:scope => :user).unshift :some_external_strategy + # manager.default_strategies(scope: :user).unshift :some_external_strategy # end end diff --git a/test/rails_app/config/initializers/secret_token.rb b/test/rails_app/config/initializers/secret_token.rb index 93864c62..24698914 100644 --- a/test/rails_app/config/initializers/secret_token.rb +++ b/test/rails_app/config/initializers/secret_token.rb @@ -4,5 +4,5 @@ if Devise.rails4? config.secret_key_base = 'd588e99efff13a86461fd6ab82327823ad2f8feb5dc217ce652cdd9f0dfc5eb4b5a62a92d24d2574d7d51dfb1ea8dd453ea54e00cf672159a13104a135422a10' else config.secret_token = 'ea942c41850d502f2c8283e26bdc57829f471bb18224ddff0a192c4f32cdf6cb5aa0d82b3a7a7adbeb640c4b06f3aa1cd5f098162d8240f669b39d6b49680571' - config.session_store :cookie_store, :key => "_my_app" + config.session_store :cookie_store, key: "_my_app" end diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index ce789037..16f60751 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do # Resources for testing - resources :users, :only => [:index] do + resources :users, only: [:index] do member do get :expire get :accept @@ -9,97 +9,97 @@ Rails.application.routes.draw do end authenticate do - post :exhibit, :on => :member + post :exhibit, on: :member end end - resources :admins, :only => [:index] do - get :expire, :on => :member + resources :admins, only: [:index] do + get :expire, on: :member end # Users scope - devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } + devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" } as :user do - get "/as/sign_in", :to => "devise/sessions#new" + get "/as/sign_in", to: "devise/sessions#new" end - get "/sign_in", :to => "devise/sessions#new" + get "/sign_in", to: "devise/sessions#new" # Admin scope - devise_for :admin, :path => "admin_area", :controllers => { :sessions => :"admins/sessions" }, :skip => :passwords + devise_for :admin, path: "admin_area", controllers: { sessions: :"admins/sessions" }, skip: :passwords - get "/admin_area/home", :to => "admins#index", :as => :admin_root - get "/anywhere", :to => "foo#bar", :as => :new_admin_password + get "/admin_area/home", to: "admins#index", as: :admin_root + get "/anywhere", to: "foo#bar", as: :new_admin_password authenticate(:admin) do - get "/private", :to => "home#private", :as => :private + get "/private", to: "home#private", as: :private end authenticate(:admin, lambda { |admin| admin.active? }) do - get "/private/active", :to => "home#private", :as => :private_active + get "/private/active", to: "home#private", as: :private_active end authenticated :admin do - get "/dashboard", :to => "home#admin_dashboard" + get "/dashboard", to: "home#admin_dashboard" end authenticated :admin, lambda { |admin| admin.active? } do - get "/dashboard/active", :to => "home#admin_dashboard" + get "/dashboard/active", to: "home#admin_dashboard" end authenticated do - get "/dashboard", :to => "home#user_dashboard" + get "/dashboard", to: "home#user_dashboard" end unauthenticated do - get "/join", :to => "home#join" + get "/join", to: "home#join" end # Routes for constraints testing - devise_for :headquarters_admin, :class_name => "Admin", :path => "headquarters", :constraints => {:host => /192\.168\.1\.\d\d\d/} + devise_for :headquarters_admin, class_name: "Admin", path: "headquarters", constraints: {host: /192\.168\.1\.\d\d\d/} - constraints(:host => /192\.168\.1\.\d\d\d/) do - devise_for :homebase_admin, :class_name => "Admin", :path => "homebase" + constraints(host: /192\.168\.1\.\d\d\d/) do + devise_for :homebase_admin, class_name: "Admin", path: "homebase" end - devise_for :skip_admin, :class_name => "Admin", :skip => :all + devise_for :skip_admin, class_name: "Admin", skip: :all # Routes for format=false testing - devise_for :htmlonly_admin, :class_name => "Admin", :skip => [:confirmations, :unlocks], :path => "htmlonly_admin", :format => false, :skip_helpers => [:confirmations, :unlocks] - devise_for :htmlonly_users, :class_name => "User", :only => [:confirmations, :unlocks], :path => "htmlonly_users", :format => false, :skip_helpers => true + devise_for :htmlonly_admin, class_name: "Admin", skip: [:confirmations, :unlocks], path: "htmlonly_admin", format: false, skip_helpers: [:confirmations, :unlocks] + devise_for :htmlonly_users, class_name: "User", only: [:confirmations, :unlocks], path: "htmlonly_users", format: false, skip_helpers: true # Other routes for routing_test.rb - devise_for :reader, :class_name => "User", :only => :passwords + devise_for :reader, class_name: "User", only: :passwords - scope :host => "sub.example.com" do - devise_for :sub_admin, :class_name => "Admin" + scope host: "sub.example.com" do + devise_for :sub_admin, class_name: "Admin" end - namespace :publisher, :path_names => { :sign_in => "i_dont_care", :sign_out => "get_out" } do - devise_for :accounts, :class_name => "Admin", :path_names => { :sign_in => "get_in" } + namespace :publisher, path_names: { sign_in: "i_dont_care", sign_out: "get_out" } do + devise_for :accounts, class_name: "Admin", path_names: { sign_in: "get_in" } end - scope ":locale", :module => :invalid do - devise_for :accounts, :singular => "manager", :class_name => "Admin", - :path_names => { - :sign_in => "login", :sign_out => "logout", - :password => "secret", :confirmation => "verification", - :unlock => "unblock", :sign_up => "register", - :registration => "management", - :cancel => "giveup", :edit => "edit/profile" - }, :failure_app => lambda { |env| [404, {"Content-Type" => "text/plain"}, ["Oops, not found"]] }, :module => :devise + scope ":locale", module: :invalid do + devise_for :accounts, singular: "manager", class_name: "Admin", + path_names: { + sign_in: "login", sign_out: "logout", + password: "secret", confirmation: "verification", + unlock: "unblock", sign_up: "register", + registration: "management", + cancel: "giveup", edit: "edit/profile" + }, failure_app: lambda { |env| [404, {"Content-Type" => "text/plain"}, ["Oops, not found"]] }, module: :devise end - namespace :sign_out_via, :module => "devise" do - devise_for :deletes, :sign_out_via => :delete, :class_name => "Admin" - devise_for :posts, :sign_out_via => :post, :class_name => "Admin" - devise_for :delete_or_posts, :sign_out_via => [:delete, :post], :class_name => "Admin" + namespace :sign_out_via, module: "devise" do + devise_for :deletes, sign_out_via: :delete, class_name: "Admin" + devise_for :posts, sign_out_via: :post, class_name: "Admin" + devise_for :delete_or_posts, sign_out_via: [:delete, :post], class_name: "Admin" end - get "/set", :to => "home#set" - get "/unauthenticated", :to => "home#unauthenticated" + get "/set", to: "home#set" + get "/unauthenticated", to: "home#unauthenticated" get "/custom_strategy/new" - root :to => "home#index", :via => [:get, :post] + root to: "home#index", via: [:get, :post] end diff --git a/test/rails_app/db/migrate/20100401102949_create_tables.rb b/test/rails_app/db/migrate/20100401102949_create_tables.rb index 43bf8564..5aaf7364 100644 --- a/test/rails_app/db/migrate/20100401102949_create_tables.rb +++ b/test/rails_app/db/migrate/20100401102949_create_tables.rb @@ -5,8 +5,8 @@ class CreateTables < ActiveRecord::Migration t.string :facebook_token ## Database authenticatable - t.string :email, :null => false, :default => "" - t.string :encrypted_password, :null => false, :default => "" + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" ## Recoverable t.string :reset_password_token @@ -16,7 +16,7 @@ class CreateTables < ActiveRecord::Migration t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0 + t.integer :sign_in_count, default: 0 t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -29,7 +29,7 @@ class CreateTables < ActiveRecord::Migration # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable - t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + t.integer :failed_attempts, default: 0 # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both t.datetime :locked_at @@ -38,8 +38,8 @@ class CreateTables < ActiveRecord::Migration create_table :admins do |t| ## Database authenticatable - t.string :email, :null => true - t.string :encrypted_password, :null => true + t.string :email, null: true + t.string :encrypted_password, null: true ## Recoverable t.string :reset_password_token @@ -58,7 +58,7 @@ class CreateTables < ActiveRecord::Migration t.datetime :locked_at ## Attribute for testing route blocks - t.boolean :active, :default => false + t.boolean :active, default: false t.timestamps end diff --git a/test/rails_app/lib/shared_admin.rb b/test/rails_app/lib/shared_admin.rb index 0bb40a4b..e8c293e5 100644 --- a/test/rails_app/lib/shared_admin.rb +++ b/test/rails_app/lib/shared_admin.rb @@ -4,11 +4,11 @@ module SharedAdmin included do devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable, - :unlock_strategy => :time, :lock_strategy => :none, - :allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true + unlock_strategy: :time, lock_strategy: :none, + allow_unconfirmed_access_for: 2.weeks, reconfirmable: true - validates_length_of :reset_password_token, :minimum => 3, :allow_blank => true - validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed? + validates_length_of :reset_password_token, minimum: 3, allow_blank: true + validates_uniqueness_of :email, allow_blank: true, if: :email_changed? end def raw_confirmation_token diff --git a/test/routes_test.rb b/test/routes_test.rb index 3376e914..33cd63c7 100644 --- a/test/routes_test.rb +++ b/test/routes_test.rb @@ -4,107 +4,107 @@ ExpectedRoutingError = Devise.rails4? ? MiniTest::Assertion : ActionController:: class DefaultRoutingTest < ActionController::TestCase test 'map new user session' do - assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => 'users/sign_in', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'new'}, {path: 'users/sign_in', method: :get}) assert_named_route "/users/sign_in", :new_user_session_path end test 'map create user session' do - assert_recognizes({:controller => 'devise/sessions', :action => 'create'}, {:path => 'users/sign_in', :method => :post}) + assert_recognizes({controller: 'devise/sessions', action: 'create'}, {path: 'users/sign_in', method: :post}) assert_named_route "/users/sign_in", :user_session_path end test 'map destroy user session' do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => 'users/sign_out', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: 'users/sign_out', method: :get}) assert_named_route "/users/sign_out", :destroy_user_session_path end test 'map new user confirmation' do - assert_recognizes({:controller => 'devise/confirmations', :action => 'new'}, 'users/confirmation/new') + assert_recognizes({controller: 'devise/confirmations', action: 'new'}, 'users/confirmation/new') assert_named_route "/users/confirmation/new", :new_user_confirmation_path end test 'map create user confirmation' do - assert_recognizes({:controller => 'devise/confirmations', :action => 'create'}, {:path => 'users/confirmation', :method => :post}) + assert_recognizes({controller: 'devise/confirmations', action: 'create'}, {path: 'users/confirmation', method: :post}) assert_named_route "/users/confirmation", :user_confirmation_path end test 'map show user confirmation' do - assert_recognizes({:controller => 'devise/confirmations', :action => 'show'}, {:path => 'users/confirmation', :method => :get}) + assert_recognizes({controller: 'devise/confirmations', action: 'show'}, {path: 'users/confirmation', method: :get}) end test 'map new user password' do - assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'users/password/new') + assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'users/password/new') assert_named_route "/users/password/new", :new_user_password_path end test 'map create user password' do - assert_recognizes({:controller => 'devise/passwords', :action => 'create'}, {:path => 'users/password', :method => :post}) + assert_recognizes({controller: 'devise/passwords', action: 'create'}, {path: 'users/password', method: :post}) assert_named_route "/users/password", :user_password_path end test 'map edit user password' do - assert_recognizes({:controller => 'devise/passwords', :action => 'edit'}, 'users/password/edit') + assert_recognizes({controller: 'devise/passwords', action: 'edit'}, 'users/password/edit') assert_named_route "/users/password/edit", :edit_user_password_path end test 'map update user password' do - assert_recognizes({:controller => 'devise/passwords', :action => 'update'}, {:path => 'users/password', :method => :put}) + assert_recognizes({controller: 'devise/passwords', action: 'update'}, {path: 'users/password', method: :put}) end test 'map new user unlock' do - assert_recognizes({:controller => 'devise/unlocks', :action => 'new'}, 'users/unlock/new') + assert_recognizes({controller: 'devise/unlocks', action: 'new'}, 'users/unlock/new') assert_named_route "/users/unlock/new", :new_user_unlock_path end test 'map create user unlock' do - assert_recognizes({:controller => 'devise/unlocks', :action => 'create'}, {:path => 'users/unlock', :method => :post}) + assert_recognizes({controller: 'devise/unlocks', action: 'create'}, {path: 'users/unlock', method: :post}) assert_named_route "/users/unlock", :user_unlock_path end test 'map show user unlock' do - assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => 'users/unlock', :method => :get}) + assert_recognizes({controller: 'devise/unlocks', action: 'show'}, {path: 'users/unlock', method: :get}) end test 'map new user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, 'users/sign_up') + assert_recognizes({controller: 'devise/registrations', action: 'new'}, 'users/sign_up') assert_named_route "/users/sign_up", :new_user_registration_path end test 'map create user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'create'}, {:path => 'users', :method => :post}) + assert_recognizes({controller: 'devise/registrations', action: 'create'}, {path: 'users', method: :post}) assert_named_route "/users", :user_registration_path end test 'map edit user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'edit'}, {:path => 'users/edit', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'edit'}, {path: 'users/edit', method: :get}) assert_named_route "/users/edit", :edit_user_registration_path end test 'map update user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'update'}, {:path => 'users', :method => :put}) + assert_recognizes({controller: 'devise/registrations', action: 'update'}, {path: 'users', method: :put}) end test 'map destroy user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete}) + assert_recognizes({controller: 'devise/registrations', action: 'destroy'}, {path: 'users', method: :delete}) end test 'map cancel user registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'cancel'}, {:path => 'users/cancel', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'cancel'}, {path: 'users/cancel', method: :get}) assert_named_route "/users/cancel", :cancel_user_registration_path end test 'map omniauth callbacks' do - assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'facebook'}, {:path => 'users/auth/facebook/callback', :method => :get}) - assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'facebook'}, {:path => 'users/auth/facebook/callback', :method => :post}) + assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :get}) + assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :post}) assert_named_route "/users/auth/facebook/callback", :user_omniauth_callback_path, :facebook # named open_id - assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'google'}, {:path => 'users/auth/google/callback', :method => :get}) - assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'google'}, {:path => 'users/auth/google/callback', :method => :post}) + assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :get}) + assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :post}) assert_named_route "/users/auth/google/callback", :user_omniauth_callback_path, :google assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'ysers/omniauth_callbacks', :action => 'twitter'}, {:path => 'users/auth/twitter/callback', :method => :get}) + assert_recognizes({controller: 'ysers/omniauth_callbacks', action: 'twitter'}, {path: 'users/auth/twitter/callback', method: :get}) end end @@ -117,122 +117,122 @@ end class CustomizedRoutingTest < ActionController::TestCase test 'map admin with :path option' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'admin_area/sign_up', method: :get}) end test 'map admin with :controllers option' do - assert_recognizes({:controller => 'admins/sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get}) + assert_recognizes({controller: 'admins/sessions', action: 'new'}, {path: 'admin_area/sign_in', method: :get}) end test 'does not map admin password' do assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'admin_area/password/new') + assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'admin_area/password/new') end end test 'subdomain admin' do - assert_recognizes({"host"=>"sub.example.com", :controller => 'devise/sessions', :action => 'new'}, {:host => "sub.example.com", :path => '/sub_admin/sign_in', :method => :get}) + assert_recognizes({"host"=>"sub.example.com", controller: 'devise/sessions', action: 'new'}, {host: "sub.example.com", path: '/sub_admin/sign_in', method: :get}) end test 'does only map reader password' do assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, 'reader/sessions/new') + assert_recognizes({controller: 'devise/sessions', action: 'new'}, 'reader/sessions/new') end - assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'reader/password/new') + assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'reader/password/new') end test 'map account with custom path name for session sign in' do - assert_recognizes({:controller => 'devise/sessions', :action => 'new', :locale => 'en'}, '/en/accounts/login') + assert_recognizes({controller: 'devise/sessions', action: 'new', locale: 'en'}, '/en/accounts/login') end test 'map account with custom path name for session sign out' do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy', :locale => 'en'}, '/en/accounts/logout') + assert_recognizes({controller: 'devise/sessions', action: 'destroy', locale: 'en'}, '/en/accounts/logout') end test 'map account with custom path name for password' do - assert_recognizes({:controller => 'devise/passwords', :action => 'new', :locale => 'en'}, '/en/accounts/secret/new') + assert_recognizes({controller: 'devise/passwords', action: 'new', locale: 'en'}, '/en/accounts/secret/new') end test 'map account with custom path name for registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register') + assert_recognizes({controller: 'devise/registrations', action: 'new', locale: 'en'}, '/en/accounts/management/register') end test 'map account with custom path name for edit registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'edit', :locale => 'en'}, '/en/accounts/management/edit/profile') + assert_recognizes({controller: 'devise/registrations', action: 'edit', locale: 'en'}, '/en/accounts/management/edit/profile') end test 'map account with custom path name for cancel registration' do - assert_recognizes({:controller => 'devise/registrations', :action => 'cancel', :locale => 'en'}, '/en/accounts/management/giveup') + assert_recognizes({controller: 'devise/registrations', action: 'cancel', locale: 'en'}, '/en/accounts/management/giveup') end test 'map deletes with :sign_out_via option' do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/deletes/sign_out', :method => :delete}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/deletes/sign_out', method: :delete}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/deletes/sign_out', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/deletes/sign_out', method: :get}) end end test 'map posts with :sign_out_via option' do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/posts/sign_out', :method => :post}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/posts/sign_out', method: :post}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/posts/sign_out', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/posts/sign_out', method: :get}) end end test 'map delete_or_posts with :sign_out_via option' do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :post}) - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :delete}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :post}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :delete}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :get}) end end test 'map with constraints defined in hash' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'http://192.168.1.100/headquarters/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://192.168.1.100/headquarters/sign_up', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'http://10.0.0.100/headquarters/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://10.0.0.100/headquarters/sign_up', method: :get}) end end test 'map with constraints defined in block' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'http://192.168.1.100/homebase/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://192.168.1.100/homebase/sign_up', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'http://10.0.0.100//homebase/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://10.0.0.100//homebase/sign_up', method: :get}) end end test 'map with format false for sessions' do - assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => '/htmlonly_admin/sign_in', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'new'}, {path: '/htmlonly_admin/sign_in', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => '/htmlonly_admin/sign_in.xml', :method => :get}) + assert_recognizes({controller: 'devise/sessions', action: 'new'}, {path: '/htmlonly_admin/sign_in.xml', method: :get}) end end test 'map with format false for passwords' do - assert_recognizes({:controller => 'devise/passwords', :action => 'create'}, {:path => '/htmlonly_admin/password', :method => :post}) + assert_recognizes({controller: 'devise/passwords', action: 'create'}, {path: '/htmlonly_admin/password', method: :post}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/passwords', :action => 'create'}, {:path => '/htmlonly_admin/password.xml', :method => :post}) + assert_recognizes({controller: 'devise/passwords', action: 'create'}, {path: '/htmlonly_admin/password.xml', method: :post}) end end test 'map with format false for registrations' do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => '/htmlonly_admin/sign_up', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: '/htmlonly_admin/sign_up', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => '/htmlonly_admin/sign_up.xml', :method => :get}) + assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: '/htmlonly_admin/sign_up.xml', method: :get}) end end test 'map with format false for confirmations' do - assert_recognizes({:controller => 'devise/confirmations', :action => 'show'}, {:path => '/htmlonly_users/confirmation', :method => :get}) + assert_recognizes({controller: 'devise/confirmations', action: 'show'}, {path: '/htmlonly_users/confirmation', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/confirmations', :action => 'show'}, {:path => '/htmlonly_users/confirmation.xml', :method => :get}) + assert_recognizes({controller: 'devise/confirmations', action: 'show'}, {path: '/htmlonly_users/confirmation.xml', method: :get}) end end test 'map with format false for unlocks' do - assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => '/htmlonly_users/unlock', :method => :get}) + assert_recognizes({controller: 'devise/unlocks', action: 'show'}, {path: '/htmlonly_users/unlock', method: :get}) assert_raise ExpectedRoutingError do - assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => '/htmlonly_users/unlock.xml', :method => :get}) + assert_recognizes({controller: 'devise/unlocks', action: 'show'}, {path: '/htmlonly_users/unlock.xml', method: :get}) end end @@ -251,12 +251,12 @@ end class ScopedRoutingTest < ActionController::TestCase test 'map publisher account' do - assert_recognizes({:controller => 'publisher/registrations', :action => 'new'}, {:path => '/publisher/accounts/sign_up', :method => :get}) + assert_recognizes({controller: 'publisher/registrations', action: 'new'}, {path: '/publisher/accounts/sign_up', method: :get}) assert_equal '/publisher/accounts/sign_up', @routes.url_helpers.new_publisher_account_registration_path end test 'map publisher account merges path names' do - assert_recognizes({:controller => 'publisher/sessions', :action => 'new'}, {:path => '/publisher/accounts/get_in', :method => :get}) + assert_recognizes({controller: 'publisher/sessions', action: 'new'}, {path: '/publisher/accounts/get_in', method: :get}) assert_equal '/publisher/accounts/get_in', @routes.url_helpers.new_publisher_account_session_path end end diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 375d3c3f..4eb0db86 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -23,10 +23,10 @@ class ActiveSupport::TestCase end def valid_attributes(attributes={}) - { :username => "usertest", - :email => generate_unique_email, - :password => '12345678', - :password_confirmation => '12345678' }.update(attributes) + { username: "usertest", + email: generate_unique_email, + password: '12345678', + password_confirmation: '12345678' }.update(attributes) end def new_user(attributes={}) diff --git a/test/support/integration.rb b/test/support/integration.rb index 9a451c53..245b0e42 100644 --- a/test/support/integration.rb +++ b/test/support/integration.rb @@ -8,11 +8,11 @@ class ActionDispatch::IntegrationTest def create_user(options={}) @user ||= begin user = User.create!( - :username => 'usertest', - :email => options[:email] || 'user@test.com', - :password => options[:password] || '12345678', - :password_confirmation => options[:password] || '12345678', - :created_at => Time.now.utc + username: 'usertest', + email: options[:email] || 'user@test.com', + password: options[:password] || '12345678', + password_confirmation: options[:password] || '12345678', + created_at: Time.now.utc ) user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at] user.confirm! unless options[:confirm] == false @@ -24,9 +24,9 @@ class ActionDispatch::IntegrationTest def create_admin(options={}) @admin ||= begin admin = Admin.create!( - :email => options[:email] || 'admin@test.com', - :password => '123456', :password_confirmation => '123456', - :active => options[:active] + email: options[:email] || 'admin@test.com', + password: '123456', password_confirmation: '123456', + active: options[:active] ) admin.confirm! unless options[:confirm] == false admin @@ -36,8 +36,8 @@ class ActionDispatch::IntegrationTest 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' - fill_in 'password', :with => options[:password] || '12345678' + fill_in 'email', with: options[:email] || 'user@test.com' + fill_in 'password', with: options[:password] || '12345678' check 'remember me' if options[:remember_me] == true yield if block_given? click_button 'Sign In' @@ -47,8 +47,8 @@ class ActionDispatch::IntegrationTest 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' - fill_in 'password', :with => '123456' + fill_in 'email', with: 'admin@test.com' + fill_in 'password', with: '123456' yield if block_given? click_button 'Sign In' admin diff --git a/test/test_helpers_test.rb b/test/test_helpers_test.rb index 7db2c6f8..b0d523da 100644 --- a/test/test_helpers_test.rb +++ b/test/test_helpers_test.rb @@ -17,7 +17,7 @@ class TestHelpersTest < ActionController::TestCase end test "redirects if attempting to access a page with an unconfirmed account" do - swap Devise, :allow_unconfirmed_access_for => 0.days do + swap Devise, allow_unconfirmed_access_for: 0.days do user = create_user assert !user.active_for_authentication? @@ -28,12 +28,12 @@ class TestHelpersTest < ActionController::TestCase end test "returns nil if accessing current_user with an unconfirmed account" do - swap Devise, :allow_unconfirmed_access_for => 0.days do + swap Devise, allow_unconfirmed_access_for: 0.days do user = create_user assert !user.active_for_authentication? sign_in user - get :accept, :id => user + get :accept, id: user assert_nil assigns(:current_user) end end diff --git a/test/test_models.rb b/test/test_models.rb index ec3710fc..ee19b84a 100644 --- a/test/test_models.rb +++ b/test/test_models.rb @@ -1,11 +1,11 @@ class Configurable < User devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable, - :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days, - :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days + stretches: 15, pepper: 'abcdef', allow_unconfirmed_access_for: 5.days, + remember_for: 7.days, timeout_in: 15.minutes, unlock_in: 10.days end class WithValidation < Admin - devise :database_authenticatable, :validatable, :password_length => 2..6 + devise :database_authenticatable, :validatable, password_length: 2..6 end class UserWithValidation < User @@ -20,8 +20,8 @@ class UserWithCustomEncryption < User end class UserWithVirtualAttributes < User - devise :case_insensitive_keys => [ :email, :email_confirmation ] - validates :email, :presence => true, :confirmation => {:on => :create} + devise case_insensitive_keys: [ :email, :email_confirmation ] + validates :email, presence: true, confirmation: {on: :create} end class Several < Admin