Update devise dependency to version 3.2.2
This commit is contained in:
parent
c02aebccce
commit
11ac7148c3
2
Gemfile
2
Gemfile
|
@ -4,7 +4,7 @@ ruby '2.0.0'
|
|||
gem 'rails', '~> 3.2'
|
||||
|
||||
gem 'arel'
|
||||
gem 'devise', '~> 2.2'
|
||||
gem 'devise'
|
||||
gem 'geokit'
|
||||
gem 'haml'
|
||||
gem 'http_accept_language'
|
||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -30,6 +30,7 @@ GEM
|
|||
multi_json (~> 1.0)
|
||||
addressable (2.3.5)
|
||||
arel (3.0.3)
|
||||
atomic (1.1.14)
|
||||
bcrypt-ruby (3.1.2)
|
||||
binding_of_caller (0.7.2)
|
||||
debug_inspector (>= 0.0.1)
|
||||
|
@ -60,11 +61,12 @@ GEM
|
|||
debugger-ruby_core_source (~> 1.2.4)
|
||||
debugger-linecache (1.2.0)
|
||||
debugger-ruby_core_source (1.2.4)
|
||||
devise (2.2.8)
|
||||
devise (3.2.2)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.2.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
docile (1.1.1)
|
||||
erubis (2.7.0)
|
||||
execjs (2.0.2)
|
||||
|
@ -194,6 +196,8 @@ GEM
|
|||
term-ansicolor (1.2.2)
|
||||
tins (~> 0.8)
|
||||
thor (0.18.1)
|
||||
thread_safe (0.1.3)
|
||||
atomic
|
||||
tilt (1.4.1)
|
||||
tins (0.13.1)
|
||||
treetop (1.4.15)
|
||||
|
@ -217,7 +221,7 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
arel
|
||||
coveralls
|
||||
devise (~> 2.2)
|
||||
devise
|
||||
fastercsv
|
||||
geokit
|
||||
haml
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
class PasswordsController < Devise::PasswordsController
|
||||
def create
|
||||
self.resource = resource_class.send_reset_password_instructions(resource_params)
|
||||
if resource.errors.empty?
|
||||
yield resource if block_given?
|
||||
if successfully_sent?(resource)
|
||||
render(json: {success: true})
|
||||
else
|
||||
render(json: {errors: resource.errors}, status: 500)
|
||||
|
@ -16,6 +17,11 @@ class PasswordsController < Devise::PasswordsController
|
|||
|
||||
def update
|
||||
self.resource = resource_class.reset_password_by_token(resource_params)
|
||||
yield resource if block_given?
|
||||
if resource.errors.empty?
|
||||
resource.unlock_access! if unlockable?(resource)
|
||||
sign_in(resource_name, resource)
|
||||
end
|
||||
redirect_to(controller: "main", action: "index")
|
||||
end
|
||||
|
||||
|
|
|
@ -4,9 +4,10 @@ class SessionsController < Devise::SessionsController
|
|||
end
|
||||
|
||||
def create
|
||||
resource = warden.authenticate(scope: resource_name)
|
||||
self.resource = warden.authenticate!(auth_options)
|
||||
if resource
|
||||
sign_in(resource_name, resource)
|
||||
yield resource if block_given?
|
||||
render(json: resource)
|
||||
else
|
||||
render(json: {errors: {password: [t("errors.password")]}}, status: 401)
|
||||
|
@ -16,6 +17,8 @@ class SessionsController < Devise::SessionsController
|
|||
def destroy
|
||||
signed_in = signed_in?(resource_name)
|
||||
sign_out(resource_name) if signed_in
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
||||
yield resource if block_given?
|
||||
render(json: {success: signed_in})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,10 @@ class UsersController < Devise::RegistrationsController
|
|||
end
|
||||
|
||||
def update
|
||||
if resource.update_with_password(resource_params)
|
||||
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
||||
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
||||
if update_resource(resource, account_update_params)
|
||||
yield resource if block_given?
|
||||
sign_in(resource_name, resource, bypass: true)
|
||||
flash[:notice] = "Profile updated!"
|
||||
redirect_to(controller: "sidebar", action: "search")
|
||||
|
@ -15,8 +18,9 @@ class UsersController < Devise::RegistrationsController
|
|||
end
|
||||
|
||||
def create
|
||||
build_resource
|
||||
build_resource(sign_up_params)
|
||||
if resource.save
|
||||
yield resource if block_given?
|
||||
sign_in(resource_name, resource)
|
||||
render(json: resource)
|
||||
else
|
||||
|
@ -27,11 +31,12 @@ class UsersController < Devise::RegistrationsController
|
|||
|
||||
private
|
||||
|
||||
def resource_params
|
||||
params.require(:user).permit(:address_1, :address_2, :city,
|
||||
:current_password, :email, :name,
|
||||
:organization, :password,
|
||||
:password_confirmation, :remember_me,
|
||||
:sms_number, :state, :voice_number, :zip)
|
||||
def sign_up_params
|
||||
params.require(:user).permit(:email, :name, :organization, :password, :password_confirmation, :sms_number, :voice_number)
|
||||
end
|
||||
|
||||
def account_update_params
|
||||
params.require(:user).permit(:address_1, :address_2, :city, :current_password, :email, :name, :organization, :password, :password_confirmation, :remember_me, :sms_number, :state, :voice_number, :zip)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
# Use this hook to configure devise mailer, warden hooks and so forth.
|
||||
# Many of these configuration options can be set straight in your model.
|
||||
Devise.setup do |config|
|
||||
# The secret key used by Devise. Devise uses this key to generate
|
||||
# random tokens. Changing this key will render invalid all existing
|
||||
# confirmation, reset password and unlock tokens in the database.
|
||||
config.secret_key = 'e642a15001ccf8126bf88426c41497c97d28084fd1de3b2f136ef897257e3e6de525fb751199e439cbefc9c93bc643c59426852c44f4c108dfcb87fdf7cfd503'
|
||||
|
||||
# ==> Mailer Configuration
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
||||
config.mailer_sender = "noreply@adoptahydrant.com"
|
||||
# note that it will be overwritten if you use your own mailer class
|
||||
# with default "from" parameter.
|
||||
config.mailer_sender = 'noreply@adoptahydrant.com'
|
||||
|
||||
# Configure the class responsible to send e-mails.
|
||||
# config.mailer = "Devise::Mailer"
|
||||
# config.mailer = 'Devise::Mailer'
|
||||
|
||||
# ==> ORM configuration
|
||||
# Load and configure the ORM. Supports :active_record (default) and
|
||||
|
@ -48,17 +54,18 @@ Devise.setup do |config|
|
|||
# enable it only for database (email + password) authentication.
|
||||
# config.params_authenticatable = true
|
||||
|
||||
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
||||
# Tell if authentication through HTTP Auth is enabled. False by default.
|
||||
# It can be set to an array that will enable http authentication only for the
|
||||
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
||||
# enable it only for token authentication.
|
||||
# given strategies, for example, `config.http_authenticatable = [:database]` will
|
||||
# enable it only for database authentication. The supported strategies are:
|
||||
# :database = Support basic authentication with authentication key + password
|
||||
# config.http_authenticatable = false
|
||||
|
||||
# If http headers should be returned for AJAX requests. True by default.
|
||||
# config.http_authenticatable_on_xhr = true
|
||||
|
||||
# The realm used in Http Basic Authentication. "Application" by default.
|
||||
# config.http_authentication_realm = "Application"
|
||||
# The realm used in Http Basic Authentication. 'Application' by default.
|
||||
# config.http_authentication_realm = 'Application'
|
||||
|
||||
# It will change confirmation, password recovery and other workflows
|
||||
# to behave the same regardless if the e-mail provided was right or wrong.
|
||||
|
@ -66,12 +73,18 @@ Devise.setup do |config|
|
|||
# config.paranoid = true
|
||||
|
||||
# By default Devise will store the user in session. You can skip storage for
|
||||
# :http_auth and :token_auth by adding those symbols to the array below.
|
||||
# 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
|
||||
config.skip_session_storage = [:http_auth]
|
||||
|
||||
# By default, Devise cleans up the CSRF token on authentication to
|
||||
# avoid CSRF token fixation attacks. This means that, when using AJAX
|
||||
# requests for sign in and sign up, you need to get a new CSRF token
|
||||
# from the server. You can disable this option at your own risk.
|
||||
# config.clean_up_csrf_token_on_authentication = true
|
||||
|
||||
# ==> Configuration for :database_authenticatable
|
||||
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
||||
# using other encryptors, it sets how many times you want the password re-encrypted.
|
||||
|
@ -92,6 +105,14 @@ Devise.setup do |config|
|
|||
# the user cannot access the website without confirming his account.
|
||||
# config.allow_unconfirmed_access_for = 2.days
|
||||
|
||||
# A period that the user is allowed to confirm their account before their
|
||||
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
||||
# their account within 3 days after the mail was sent, but on the fourth day
|
||||
# their account can't be confirmed with the token any more.
|
||||
# Default is nil, meaning there is no restriction on how long a user can take
|
||||
# before confirming their account.
|
||||
# config.confirm_within = 3.days
|
||||
|
||||
# If true, requires any email changes to be confirmed (exactly the same way as
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field (see migrations). Until confirmed new email is stored in
|
||||
|
@ -113,11 +134,11 @@ Devise.setup do |config|
|
|||
# config.rememberable_options = {}
|
||||
|
||||
# ==> Configuration for :validatable
|
||||
# Range for password length. Default is 6..128.
|
||||
# config.password_length = 6..128
|
||||
# Range for password length. Default is 8..128.
|
||||
# config.password_length = 8..128
|
||||
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# an one (and only one) @ exists in the given string. This is mainly
|
||||
# one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
||||
|
||||
|
@ -152,6 +173,9 @@ Devise.setup do |config|
|
|||
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
||||
# config.unlock_in = 1.hour
|
||||
|
||||
# Warn on the last attempt before the account is locked.
|
||||
# config.last_attempt_warning = false
|
||||
|
||||
# ==> Configuration for :recoverable
|
||||
#
|
||||
# Defines which key will be used when recovering the password for an account
|
||||
|
@ -167,13 +191,11 @@ Devise.setup do |config|
|
|||
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
||||
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
||||
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
||||
# REST_AUTH_SITE_KEY to pepper)
|
||||
# REST_AUTH_SITE_KEY to pepper).
|
||||
#
|
||||
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
||||
# config.encryptor = :sha512
|
||||
|
||||
# ==> Configuration for :token_authenticatable
|
||||
# Defines name of the authentication token params key
|
||||
# config.token_authentication_key = :auth_token
|
||||
|
||||
# ==> Scopes configuration
|
||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||
# "users/sessions/new". It's turned off by default because it's slower if you
|
||||
|
@ -197,7 +219,7 @@ Devise.setup do |config|
|
|||
# should add them to the navigational formats lists.
|
||||
#
|
||||
# The "*/*" below is required to match Internet Explorer requests.
|
||||
# config.navigational_formats = ["*/*", :html]
|
||||
# config.navigational_formats = ['*/*', :html]
|
||||
|
||||
# The default HTTP method used to sign out a resource. Default is :delete.
|
||||
config.sign_out_via = :delete
|
||||
|
@ -221,12 +243,12 @@ Devise.setup do |config|
|
|||
# is mountable, there are some extra configurations to be taken into account.
|
||||
# The following options are available, assuming the engine is mounted as:
|
||||
#
|
||||
# mount MyEngine, at: "/my_engine"
|
||||
# mount MyEngine, at: '/my_engine'
|
||||
#
|
||||
# The router that invoked `devise_for`, in the example above, would be:
|
||||
# config.router_name = :my_engine
|
||||
#
|
||||
# When using omniauth, Devise cannot automatically set Omniauth path,
|
||||
# so you need to do it manually. For the users scope, it would be:
|
||||
# config.omniauth_path_prefix = "/my_engine/users/auth"
|
||||
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
||||
end
|
||||
|
|
|
@ -1,58 +1,59 @@
|
|||
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
||||
|
||||
en:
|
||||
devise:
|
||||
confirmations:
|
||||
confirmed: "Your account was successfully confirmed."
|
||||
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
|
||||
send_paranoid_instructions: "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."
|
||||
failure:
|
||||
already_authenticated: "You are already signed in."
|
||||
inactive: "Your account is not activated yet."
|
||||
invalid: "Invalid email or password."
|
||||
locked: "Your account is locked."
|
||||
last_attempt: "You have one more attempt before your account will be locked."
|
||||
not_found_in_database: "Invalid email or password."
|
||||
timeout: "Your session expired. Please sign in again to continue."
|
||||
unauthenticated: "You need to sign in or sign up before continuing."
|
||||
unconfirmed: "You have to confirm your account before continuing."
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Confirmation instructions"
|
||||
reset_password_instructions:
|
||||
subject: "Reset password instructions"
|
||||
unlock_instructions:
|
||||
subject: "Unlock Instructions"
|
||||
omniauth_callbacks:
|
||||
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
|
||||
success: "Successfully authenticated from %{kind} account."
|
||||
passwords:
|
||||
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
||||
send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
|
||||
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
||||
updated: "Your password was changed successfully. You are now signed in."
|
||||
updated_not_active: "Your password was changed successfully."
|
||||
registrations:
|
||||
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
||||
signed_up: "Welcome! You have signed up successfully."
|
||||
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
|
||||
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
|
||||
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
|
||||
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
||||
updated: "You updated your account successfully."
|
||||
sessions:
|
||||
signed_in: "Signed in successfully."
|
||||
signed_out: "Signed out successfully."
|
||||
unlocks:
|
||||
send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
|
||||
send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
|
||||
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
|
||||
errors:
|
||||
messages:
|
||||
already_confirmed: "was already confirmed, please try signing in"
|
||||
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
|
||||
expired: "has expired, please request a new one"
|
||||
not_found: "not found"
|
||||
already_confirmed: "was already confirmed, please try signing in"
|
||||
not_locked: "was not locked"
|
||||
not_saved:
|
||||
one: "1 error prohibited this %{resource} from being saved:"
|
||||
other: "%{count} errors prohibited this %{resource} from being saved:"
|
||||
|
||||
devise:
|
||||
failure:
|
||||
already_authenticated: 'You are already signed in.'
|
||||
unauthenticated: 'You need to sign in or sign up before continuing.'
|
||||
unconfirmed: 'You have to confirm your account before continuing.'
|
||||
locked: 'Your account is locked.'
|
||||
invalid: 'Invalid email or password.'
|
||||
invalid_token: 'Invalid authentication token.'
|
||||
timeout: 'Your session expired, please sign in again to continue.'
|
||||
inactive: 'Your account was not activated yet.'
|
||||
sessions:
|
||||
signed_in: 'Signed in successfully.'
|
||||
signed_out: 'Signed out successfully.'
|
||||
passwords:
|
||||
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
||||
updated: 'Your password was changed successfully. You are now signed in.'
|
||||
updated_not_active: 'Your password was changed successfully.'
|
||||
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
||||
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
||||
confirmations:
|
||||
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
||||
send_paranoid_instructions: '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.'
|
||||
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
||||
registrations:
|
||||
signed_up: 'Welcome! You have signed up successfully.'
|
||||
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
||||
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
||||
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
||||
updated: 'You updated your account successfully.'
|
||||
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
||||
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
||||
unlocks:
|
||||
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
||||
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
||||
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
||||
omniauth_callbacks:
|
||||
success: 'Successfully authenticated from %{kind} account.'
|
||||
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
subject: 'Confirmation instructions'
|
||||
reset_password_instructions:
|
||||
subject: 'Reset password instructions'
|
||||
unlock_instructions:
|
||||
subject: 'Unlock Instructions'
|
||||
|
|
|
@ -13,7 +13,7 @@ class AddDeviseToUsers < ActiveRecord::Migration
|
|||
t.datetime :remember_created_at
|
||||
|
||||
## Trackable
|
||||
t.integer :sign_in_count, default: 0
|
||||
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
|
||||
|
@ -26,23 +26,19 @@ class AddDeviseToUsers < 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, 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
|
||||
|
||||
## Token authenticatable
|
||||
# t.string :authentication_token
|
||||
|
||||
|
||||
# Uncomment below if timestamps were not included in your original model.
|
||||
# t.timestamps
|
||||
end
|
||||
|
||||
# add_index :users, :email, :unique => true
|
||||
add_index :users, :reset_password_token, :unique => true
|
||||
# add_index :users, :confirmation_token, :unique => true
|
||||
# add_index :users, :unlock_token, :unique => true
|
||||
# add_index :users, :authentication_token, :unique => true
|
||||
# add_index :users, :email, unique: true
|
||||
add_index :users, :reset_password_token, unique: true
|
||||
# add_index :users, :confirmation_token, unique: true
|
||||
# add_index :users, :unlock_token, unique: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 5) do
|
|||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
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"
|
||||
|
|
|
@ -5,7 +5,7 @@ class AddressesControllerTest < ActionController::TestCase
|
|||
stub_request(:get, "http://maps.google.com/maps/geo").
|
||||
with(query: {key: "REPLACE_WITH_YOUR_GOOGLE_KEY", oe: "utf-8", output: "xml", q: "City Hall, Boston, MA"}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/city_hall.kml', __FILE__)))
|
||||
get :show, address: 'City Hall', city_state: "Boston, MA"
|
||||
get :show, address: 'City Hall', city_state: "Boston, MA", format: 'json'
|
||||
assert_not_nil assigns :address
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ class AddressesControllerTest < ActionController::TestCase
|
|||
stub_request(:get, "http://maps.google.com/maps/geo").
|
||||
with(query: {key: "REPLACE_WITH_YOUR_GOOGLE_KEY", oe: "utf-8", output: "xml", q: ", "}).
|
||||
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.kml', __FILE__)))
|
||||
get :show, address: '', city_state: ''
|
||||
get :show, address: '', city_state: '', format: 'json'
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,8 +28,8 @@ class PasswordsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
test 'should reset user password with an valid reset password token' do
|
||||
@user.send :generate_reset_password_token!
|
||||
put :update, user: {reset_password_token: @user.reset_password_token, password: 'new_password', password_confirmation: 'new_password'}
|
||||
token = @user.send_reset_password_instructions
|
||||
put :update, user: {reset_password_token: token, password: 'new_password'}
|
||||
@user.reload
|
||||
assert @user.valid_password?('new_password')
|
||||
assert_response :redirect
|
||||
|
@ -37,8 +37,8 @@ class PasswordsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
test 'should not reset user password with an invalid reset password token' do
|
||||
@user.send :generate_reset_password_token!
|
||||
put :update, user: {reset_password_token: 'invalid_token', password: 'new_password', password_confirmation: 'new_password'}
|
||||
@user.send_reset_password_instructions
|
||||
put :update, user: {reset_password_token: 'invalid_token', password: 'new_password'}
|
||||
@user.reload
|
||||
assert !@user.valid_password?('new_password')
|
||||
assert_response :redirect
|
||||
|
|
|
@ -19,19 +19,19 @@ class SessionsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
test 'should authenticate user if password is correct' do
|
||||
post :create, user: {email: @user.email, password: 'correct'}
|
||||
post :create, user: {email: @user.email, password: 'correct'}, format: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should return error if password is incorrect' do
|
||||
post :create, user: {email: @user.email, password: 'incorrect'}
|
||||
post :create, user: {email: @user.email, password: 'incorrect'}, format: :json
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
test 'should empty session on sign out' do
|
||||
sign_in @user
|
||||
get :destroy
|
||||
assert_equal Hash.new, session
|
||||
get :destroy, format: :json
|
||||
assert_equal {}, session
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue