Skip to content

System Test Overhaul spec/system/judges/new_spec.rb - #6531

Merged
compwron merged 7 commits into
rubyforgood:mainfrom
AudTheCodeWitch:acook/6321/update-judges-new-spec
Oct 8, 2025
Merged

System Test Overhaul spec/system/judges/new_spec.rb#6531
compwron merged 7 commits into
rubyforgood:mainfrom
AudTheCodeWitch:acook/6321/update-judges-new-spec

Conversation

@AudTheCodeWitch

Copy link
Copy Markdown
Contributor

What github issue is this PR for, if any?

Resolves #6321

What changed, and why?

  • Refactored spec/system/judges/new_spec.rb to ensure each test verifies database updates only after the page has finished loading post-submit, addressing race conditions and flakiness.
  • Used unique test data for each example to ensure isolation and prevent collisions.
  • Improved coverage for edge cases (long name, special characters) and validation errors (blank name, duplicate name).

How is this tested? (please write rspec and jest tests!) 💖💪

  • All changes are covered by system specs in spec/system/judges/new_spec.rb.
  • Tests include:
    • Creating active and inactive judges with valid names.
    • Creating judges with long names and special characters.
    • Validation errors for blank name and duplicate name.

Feelings gif (optional)

A baseball bounces off a brick wall. The text at the bottom of the image reads, "You were passing all your tests."

Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
@AudTheCodeWitch AudTheCodeWitch changed the title Acook/6321/update judges new spec System Test Overhaul spec/system/judges/new_spec.rb Oct 8, 2025
@compwron
compwron requested a review from Copilot October 8, 2025 16:55

@compwron compwron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the system test for creating judges to improve test reliability and coverage. The changes address race conditions by ensuring database updates are verified only after page loading completes, and enhance test isolation by using unique test data for each example.

  • Replaced single test with comprehensive test suite covering active/inactive judges, edge cases, and validation scenarios
  • Implemented helper method submit_judge_form to reduce code duplication
  • Added test coverage for long names, special characters, blank names, and duplicate name validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +9 to +10
let(:active_name) { Faker::Name.unique.name }
let(:inactive_name) { Faker::Name.unique.name }

Copilot AI Oct 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Faker::Name.unique.name in let blocks can cause issues since let is memoized but Faker.unique resets between test runs. Consider using let! or generating names directly in the tests to ensure truly unique values for each test execution.

Copilot uses AI. Check for mistakes.

# rubocop:disable RSpec/ExampleLength
it "creates a judge with special characters in the name", :aggregate_failures do
special_name = "#{Faker::Lorem.characters(number: 30, min_alpha: 10, min_numeric: 5)}!@#$%^&*()"

Copilot AI Oct 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special characters test uses a magic number (30) and hardcoded special characters. Consider extracting these to named constants or using a more descriptive approach to make the test intent clearer.

Copilot uses AI. Check for mistakes.
end

it "does not allow duplicate judge names in the same organization", :aggregate_failures do
duplicate_name = Faker::Name.unique.name

Copilot AI Oct 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Faker::Name.unique.name here may conflict with the unique names generated in the let blocks at the top of the spec, potentially causing Faker to run out of unique combinations. Consider using a simple string or resetting Faker.unique before this test.

Suggested change
duplicate_name = Faker::Name.unique.name
duplicate_name = "Duplicate Judge Name"

Copilot uses AI. Check for mistakes.
@compwron
compwron merged commit c4b64a2 into rubyforgood:main Oct 8, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Touches Ruby code 🧪 Tests Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System Test Overhaul spec/system/judges/new_spec.rb

3 participants