1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-31 03:25:45 +00:00

Fixed reset password after the Devise migration.

This commit is contained in:
2025-04-14 14:25:40 -04:00
parent 4828d9b876
commit 01a499cc45
18 changed files with 383 additions and 158 deletions

View File

@@ -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

View File

@@ -0,0 +1,35 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
queued_job:
tournament: one
job_name: "Test Queued Job"
status: "Queued"
details: "Test job details"
running_job:
tournament: one
job_name: "Test Running Job"
status: "Running"
details: "Test running job details"
errored_job:
tournament: one
job_name: "Test Errored Job"
status: "Errored"
details: "Test error message"
another_tournament_job:
tournament: two
job_name: "Another Tournament Job"
status: "Running"
details: "Different tournament test"

View File

@@ -0,0 +1,70 @@
require "test_helper"
class TournamentJobStatusIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
@tournament = tournaments(:one)
@user = users(:admin) # Assuming an admin user exists in your fixtures
@running_job = tournament_job_statuses(:running_job)
@errored_job = tournament_job_statuses(:errored_job)
sign_in @user
end
test "tournament director sees active jobs on tournament show page" do
get tournament_path(@tournament)
assert_response :success
# Should display the running job but not the errored job
assert_match @running_job.job_name, response.body
assert_match "Background Jobs In Progress", response.body
assert_no_match @errored_job.job_name, response.body
end
test "tournament director does not see job section when no active jobs" do
# Delete all active jobs
TournamentJobStatus.where.not(status: "Errored").destroy_all
get tournament_path(@tournament)
assert_response :success
# Should not display the job section
assert_no_match "Background Jobs In Progress", response.body
end
test "non-director user does not see job information" do
sign_out @user
@regular_user = users(:one) # Assuming a regular user exists in fixtures
sign_in @regular_user
# Assuming regular users don't have permission to manage the tournament
get tournament_path(@tournament)
assert_response :success
# Should not display job information
assert_no_match "Background Jobs In Progress", response.body
end
test "jobs get cleaned up after successful completion" do
# Test that CalculateSchoolScoreJob removes job status when complete
school = schools(:one)
job_name = "Calculating team score for #{school.name}"
# Create a job status for this school
TournamentJobStatus.create!(
tournament: @tournament,
job_name: job_name,
status: "Running"
)
# Verify the job exists
assert TournamentJobStatus.exists?(tournament: @tournament, job_name: job_name)
# Run the job synchronously
CalculateSchoolScoreJob.perform_sync(school)
# Verify the job status was removed
assert_not TournamentJobStatus.exists?(tournament: @tournament, job_name: job_name)
end
end

View File

@@ -0,0 +1,70 @@
require "test_helper"
class TournamentJobStatusTest < ActiveSupport::TestCase
setup do
@tournament = tournaments(:one)
@job_status = tournament_job_statuses(:running_job)
end
test "should be valid with required fields" do
job_status = TournamentJobStatus.new(
tournament: @tournament,
job_name: "Test Job",
status: "Queued"
)
assert job_status.valid?
end
test "should require tournament" do
@job_status.tournament = nil
assert_not @job_status.valid?
end
test "should require job_name" do
@job_status.job_name = nil
assert_not @job_status.valid?
end
test "should require status" do
@job_status.status = nil
assert_not @job_status.valid?
end
test "status should be one of the allowed values" do
@job_status.status = "Invalid Status"
assert_not @job_status.valid?
@job_status.status = "Queued"
assert @job_status.valid?
@job_status.status = "Running"
assert @job_status.valid?
@job_status.status = "Errored"
assert @job_status.valid?
end
test "active scope should exclude errored jobs" do
active_jobs = TournamentJobStatus.active
assert_includes active_jobs, tournament_job_statuses(:queued_job)
assert_includes active_jobs, tournament_job_statuses(:running_job)
assert_not_includes active_jobs, tournament_job_statuses(:errored_job)
end
test "for_tournament should return only jobs for a specific tournament" do
tournament_one_jobs = TournamentJobStatus.for_tournament(@tournament)
assert_equal 3, tournament_one_jobs.count
assert_includes tournament_one_jobs, tournament_job_statuses(:queued_job)
assert_includes tournament_one_jobs, tournament_job_statuses(:running_job)
assert_includes tournament_one_jobs, tournament_job_statuses(:errored_job)
assert_not_includes tournament_one_jobs, tournament_job_statuses(:another_tournament_job)
end
test "complete_job should remove jobs with matching tournament_id and job_name" do
assert_difference 'TournamentJobStatus.count', -1 do
TournamentJobStatus.complete_job(@tournament.id, "Test Running Job")
end
assert_nil TournamentJobStatus.find_by(id: @job_status.id)
end
end