# Entry Request System Test Coverage ## Test Files Created ### 1. Model Tests: `test/models/entry_request_test.rb` Tests for Entry model enhancements: - ✅ Validates that at least one translation is required - ✅ Entry status defaults to "active" - ✅ Scopes (requested, approved, active_entries) work correctly - ✅ requested_by association functions properly - ✅ Status transitions (requested → approved → active) - ✅ Blank translations are properly handled **13 tests, 40 assertions** ### 2. Public Controller Tests: `test/controllers/requests_controller_test.rb` Tests for public entry request submission: - ✅ Shows new request form for anonymous users (with name/email fields) - ✅ Shows new request form for logged-in users (without name/email fields) - ✅ Creates entry request with valid data - ✅ Requires at least one translation - ✅ Redirects to login if email already exists with accepted invitation - ✅ Shows pending count for email with existing requests - ✅ Creates entry with single or multiple translations - ✅ Logged-in user can submit request without providing name/email - ✅ Does not modify existing user when they submit request - ✅ Reuses existing pending user without modifying them - ✅ Transaction rollback on validation failure **11 tests, 78 assertions** ### 3. Admin Controller Tests: `test/controllers/admin/requests_controller_test.rb` Tests for admin request management: - ✅ Requires admin authentication - ✅ Shows requests index with requested and approved sections - ✅ Lists requested and approved entries - ✅ Shows request details - ✅ Shows edit form for requested entry - ✅ Updates entry details - ✅ Validates entry data on update - ✅ Approves request and sends invitation email - ✅ Rejects request and deletes entry/user - ✅ Preserves user if they have multiple entries - ✅ Blocks access for non-admin users (contributors, reviewers) **14 tests, 85 assertions** ### 4. Integration Tests: `test/integration/entry_request_flow_test.rb` Full end-to-end flow tests: - ✅ Complete flow: request → admin approve → user accepts → entry active - ✅ Rejected request removes entry and user - ✅ Requested/approved entries not visible on public site - ✅ Multiple entries by same requester all activated on invitation acceptance - ✅ Admin can edit entry details before approval - ✅ Cannot submit request with existing user email **6 tests** ## Fixtures Added ### Updated: `test/fixtures/entries.yml` - Added `status: 2` (active) to existing entries - Added `requested_entry` fixture (status: requested) - Added `approved_entry` fixture (status: approved) ### Updated: `test/fixtures/users.yml` - Added `requester_user` fixture (user without accepted invitation) ### 5. Mailer Tests: `test/mailers/invitation_mailer_test.rb` Invitation email tests including entry approval notifications: - ✅ Sends email with correct details - ✅ Includes invitation link and expiry date - ✅ Has both HTML and text parts - ✅ **With approved entry: includes entry details in email** - ✅ **With approved entry: shows correct message and formatting** - ✅ Without approved entry: uses standard invitation message **7 tests, 38 assertions** ## Test Summary **Total: 51 tests, 316 assertions** All tests passing ✅ Full test suite: **131 tests, 566 assertions** ✅ ## Running the Tests Run all request-related tests: ```bash bin/rails test test/models/entry_request_test.rb \ test/controllers/requests_controller_test.rb \ test/controllers/admin/requests_controller_test.rb \ test/integration/entry_request_flow_test.rb ``` Run individual test files: ```bash bin/rails test test/models/entry_request_test.rb bin/rails test test/controllers/requests_controller_test.rb bin/rails test test/controllers/admin/requests_controller_test.rb bin/rails test test/integration/entry_request_flow_test.rb ``` Run specific test: ```bash bin/rails test test/integration/entry_request_flow_test.rb:3 ``` ## Test Coverage Areas ### Public Request Flow - Form display and validation (different for logged-in vs anonymous users) - User and entry creation - Email duplicate detection for active accounts - Logged-in users submit without providing name/email - Existing users are never modified during request submission - Existing pending users are reused without modification - Transaction safety ### Admin Management Flow - Authentication and authorization - Request listing and filtering - Request details display - Entry editing before approval - Approval with invitation sending - Rejection with cleanup ### Integration Flow - Complete user journey from request to active entry - Entry visibility rules (requested/approved not shown publicly) - Multi-entry approval and activation - Admin workflow with editing ### Edge Cases - Validation failures with transaction rollback - User preservation when they have multiple entries - Expired invitations - Non-admin access attempts - Blank translations handling