mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-31 11:35:45 +00:00
Fixed reset password after the Devise migration.
This commit is contained in:
@@ -1,122 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PasswordResetsControllerTest < ActionController::TestCase
|
||||
def setup
|
||||
@user = users(:one)
|
||||
@user.email = 'user@example.com'
|
||||
@user.password_digest = BCrypt::Password.create('password')
|
||||
@user.save
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get :new
|
||||
assert_response :success
|
||||
assert_select 'h1', 'Forgot password'
|
||||
end
|
||||
|
||||
test "should not create password reset with invalid email" do
|
||||
post :create, params: { password_reset: { email: 'invalid@example.com' } }
|
||||
assert_template 'new'
|
||||
assert_not_nil flash[:alert]
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working mailer setup
|
||||
test "should create password reset" do
|
||||
skip "Skipping as it requires a working mailer setup"
|
||||
post :create, params: { password_reset: { email: @user.email } }
|
||||
assert_redirected_to root_path
|
||||
assert_not_nil flash[:notice]
|
||||
@user.reload
|
||||
assert_not_nil @user.reset_digest
|
||||
assert_not_nil @user.reset_sent_at
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should get edit with valid token" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
get :edit, params: { id: @user.reset_token, email: @user.email }
|
||||
assert_response :success
|
||||
assert_select "input[name='email'][type='hidden'][value='#{@user.email}']"
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should not get edit with invalid token" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
get :edit, params: { id: 'wrong_token', email: @user.email }
|
||||
assert_redirected_to root_path
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should not get edit with invalid email" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
get :edit, params: { id: @user.reset_token, email: 'wrong@example.com' }
|
||||
assert_redirected_to root_path
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should not get edit with expired token" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.reset_sent_at = 3.hours.ago
|
||||
@user.save
|
||||
get :edit, params: { id: @user.reset_token, email: @user.email }
|
||||
assert_redirected_to new_password_reset_path
|
||||
assert_not_nil flash[:alert]
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should update password with valid information" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
patch :update, params: {
|
||||
id: @user.reset_token,
|
||||
email: @user.email,
|
||||
user: {
|
||||
password: 'newpassword',
|
||||
password_confirmation: 'newpassword'
|
||||
}
|
||||
}
|
||||
assert_redirected_to root_path
|
||||
assert_not_nil flash[:notice]
|
||||
@user.reload
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should not update password with invalid password confirmation" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
patch :update, params: {
|
||||
id: @user.reset_token,
|
||||
email: @user.email,
|
||||
user: {
|
||||
password: 'newpassword',
|
||||
password_confirmation: 'wrongconfirmation'
|
||||
}
|
||||
}
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
# Skip this test as it requires a working reset token
|
||||
test "should not update password with empty password" do
|
||||
skip "Skipping as it requires a working reset token"
|
||||
@user.create_reset_digest
|
||||
@user.save
|
||||
patch :update, params: {
|
||||
id: @user.reset_token,
|
||||
email: @user.email,
|
||||
user: {
|
||||
password: '',
|
||||
password_confirmation: ''
|
||||
}
|
||||
}
|
||||
assert_template 'edit'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user